feat(titlebar): customisable window control button icons

This commit is contained in:
dragonwocky 2024-01-24 15:08:56 +11:00
parent 6e9f0a420f
commit 4df00ca870
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
4 changed files with 23 additions and 8 deletions

View File

@ -20,7 +20,7 @@ function TopbarButton({ icon, ...props }, ...children) {
}); });
return html`<button ...${props}> return html`<button ...${props}>
${children.length ${props.innerHTML || children.length
? children ? children
: html`<i class="i-${icon} w-[20px] h-[20px]" />`} : html`<i class="i-${icon} w-[20px] h-[20px]" />`}
</button>`; </button>`;

View File

@ -92,7 +92,7 @@ function Input({
$clear = html`<button $clear = html`<button
style="display: none" style="display: none"
class="h-[14px] transition duration-[20ms] class="h-[14px] transition duration-[20ms]
text-[color:var(--theme--fg-secondary)] flex text-[color:var(--theme--fg-secondary)]
hover:text-[color:var(--theme--fg-primary)]" hover:text-[color:var(--theme--fg-primary)]"
onclick=${() => _set?.({ filename: "", content: "" })} onclick=${() => _set?.({ filename: "", content: "" })}
> >

View File

@ -14,27 +14,38 @@ const minimizeLabel = "Minimize window",
unmaximizeLabel = "Unmaximize window", unmaximizeLabel = "Unmaximize window",
closeLabel = "Close window"; closeLabel = "Close window";
const createWindowButtons = () => { const createWindowButtons = async () => {
const { modDatabase } = globalThis.__enhancerApi,
db = await modDatabase("a5658d03-21c6-4088-bade-fa4780459133"),
minimizeIcon = await db.get("minimizeIcon"),
maximizeIcon = await db.get("maximizeIcon"),
unmaximizeIcon = await db.get("unmaximizeIcon"),
closeIcon = await db.get("closeIcon");
const { html, sendMessage, invokeInWorker } = globalThis.__enhancerApi, const { html, sendMessage, invokeInWorker } = globalThis.__enhancerApi,
$minimize = html`<${TopbarButton} $minimize = html`<${TopbarButton}
onclick=${() => sendMessage("notion-enhancer:titlebar", "minimize")} onclick=${() => sendMessage("notion-enhancer:titlebar", "minimize")}
aria-label="${minimizeLabel}" aria-label="${minimizeLabel}"
innerHTML="${minimizeIcon?.content}"
icon="minus" icon="minus"
/>`, />`,
$maximize = html`<${TopbarButton} $maximize = html`<${TopbarButton}
onclick=${() => sendMessage("notion-enhancer:titlebar", "maximize")} onclick=${() => sendMessage("notion-enhancer:titlebar", "maximize")}
aria-label="${maximizeLabel}" aria-label="${maximizeLabel}"
innerHTML="${maximizeIcon?.content}"
icon="maximize" icon="maximize"
/>`, />`,
$unmaximize = html`<${TopbarButton} $unmaximize = html`<${TopbarButton}
onclick=${() => sendMessage("notion-enhancer:titlebar", "unmaximize")} onclick=${() => sendMessage("notion-enhancer:titlebar", "unmaximize")}
aria-label="${unmaximizeLabel}" aria-label="${unmaximizeLabel}"
innerHTML="${unmaximizeIcon?.content}"
icon="minimize" icon="minimize"
/>`, />`,
$close = html`<${TopbarButton} $close = html`<${TopbarButton}
onclick=${() => sendMessage("notion-enhancer:titlebar", "close")} onclick=${() => sendMessage("notion-enhancer:titlebar", "close")}
class="!hover:(bg-red-600 text-white)" class="!hover:(bg-red-600 text-white)"
aria-label="${closeLabel}" aria-label="${closeLabel}"
innerHTML="${closeIcon?.content}"
icon="x" icon="x"
/>`; />`;
html`<${Tooltip}><b>${minimizeLabel}</b><//>`.attach($minimize, "bottom"); html`<${Tooltip}><b>${minimizeLabel}</b><//>`.attach($minimize, "bottom");
@ -56,9 +67,10 @@ const createWindowButtons = () => {
}; };
if (globalThis.IS_TABS) { if (globalThis.IS_TABS) {
const appendAfter = ".hide-scrollbar", const appendAfter = ".hide-scrollbar";
$buttons = createWindowButtons(); createWindowButtons().then(($buttons) => {
document.querySelector(appendAfter)?.after($buttons); document.querySelector(appendAfter)?.after($buttons);
});
} }
export { createWindowButtons }; export { createWindowButtons };

View File

@ -8,9 +8,12 @@
import { createWindowButtons } from "./buttons.mjs"; import { createWindowButtons } from "./buttons.mjs";
export default (api, db) => { export default async (api, db) => {
const titlebarStyle = await db.get("titlebarStyle");
if (titlebarStyle === "Disabled") return;
const { onMessage, addMutationListener } = api, const { onMessage, addMutationListener } = api,
$buttons = createWindowButtons(), $buttons = await createWindowButtons(),
topbarMore = ".notion-topbar-more-button", topbarMore = ".notion-topbar-more-button",
addToTopbar = () => document.querySelector(topbarMore)?.after($buttons), addToTopbar = () => document.querySelector(topbarMore)?.after($buttons),
showIfNoTabBar = async () => { showIfNoTabBar = async () => {