mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-10 15:39:01 +00:00
feat(titlebar): handle window button clicks
This commit is contained in:
parent
f085362774
commit
6e9f0a420f
@ -15,20 +15,24 @@ const minimizeLabel = "Minimize window",
|
|||||||
closeLabel = "Close window";
|
closeLabel = "Close window";
|
||||||
|
|
||||||
const createWindowButtons = () => {
|
const createWindowButtons = () => {
|
||||||
const { html } = globalThis.__enhancerApi,
|
const { html, sendMessage, invokeInWorker } = globalThis.__enhancerApi,
|
||||||
$minimize = html`<${TopbarButton}
|
$minimize = html`<${TopbarButton}
|
||||||
|
onclick=${() => sendMessage("notion-enhancer:titlebar", "minimize")}
|
||||||
aria-label="${minimizeLabel}"
|
aria-label="${minimizeLabel}"
|
||||||
icon="minus"
|
icon="minus"
|
||||||
/>`,
|
/>`,
|
||||||
$maximize = html`<${TopbarButton}
|
$maximize = html`<${TopbarButton}
|
||||||
|
onclick=${() => sendMessage("notion-enhancer:titlebar", "maximize")}
|
||||||
aria-label="${maximizeLabel}"
|
aria-label="${maximizeLabel}"
|
||||||
icon="maximize"
|
icon="maximize"
|
||||||
/>`,
|
/>`,
|
||||||
$unmaximize = html`<${TopbarButton}
|
$unmaximize = html`<${TopbarButton}
|
||||||
|
onclick=${() => sendMessage("notion-enhancer:titlebar", "unmaximize")}
|
||||||
aria-label="${unmaximizeLabel}"
|
aria-label="${unmaximizeLabel}"
|
||||||
icon="minimize"
|
icon="minimize"
|
||||||
/>`,
|
/>`,
|
||||||
$close = html`<${TopbarButton}
|
$close = html`<${TopbarButton}
|
||||||
|
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}"
|
||||||
icon="x"
|
icon="x"
|
||||||
@ -37,6 +41,17 @@ const createWindowButtons = () => {
|
|||||||
html`<${Tooltip}><b>${maximizeLabel}</b><//>`.attach($maximize, "bottom");
|
html`<${Tooltip}><b>${maximizeLabel}</b><//>`.attach($maximize, "bottom");
|
||||||
html`<${Tooltip}><b>${unmaximizeLabel}</b><//>`.attach($unmaximize, "bottom");
|
html`<${Tooltip}><b>${unmaximizeLabel}</b><//>`.attach($unmaximize, "bottom");
|
||||||
html`<${Tooltip}><b>${closeLabel}</b><//>`.attach($close, "bottom");
|
html`<${Tooltip}><b>${closeLabel}</b><//>`.attach($close, "bottom");
|
||||||
|
|
||||||
|
const resizeWindow = async () => {
|
||||||
|
const isMaximized = await invokeInWorker("notion-enhancer:titlebar", {
|
||||||
|
query: "is-maximized",
|
||||||
|
});
|
||||||
|
$maximize.style.display = isMaximized ? "none" : "";
|
||||||
|
$unmaximize.style.display = isMaximized ? "" : "none";
|
||||||
|
};
|
||||||
|
window.addEventListener("resize", resizeWindow);
|
||||||
|
resizeWindow();
|
||||||
|
|
||||||
return html`<div>${$minimize}${$maximize}${$unmaximize}${$close}</div>`;
|
return html`<div>${$minimize}${$maximize}${$unmaximize}${$close}</div>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,4 +10,19 @@ module.exports = async ({}, db) => {
|
|||||||
Object.assign((globalThis.__notionConfig ??= {}), {
|
Object.assign((globalThis.__notionConfig ??= {}), {
|
||||||
titlebarStyle: "hidden",
|
titlebarStyle: "hidden",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { ipcMain, BrowserWindow } = require("electron");
|
||||||
|
ipcMain.on("notion-enhancer:titlebar", ({ sender }, message) => {
|
||||||
|
const window = BrowserWindow.fromWebContents(sender);
|
||||||
|
if (message === "minimize") window.minimize();
|
||||||
|
if (message === "maximize") window.maximize();
|
||||||
|
if (message === "unmaximize") window.unmaximize();
|
||||||
|
if (message === "close") window.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle("notion-enhancer:titlebar", ({ sender }, message) => {
|
||||||
|
if (message?.query !== "is-maximized") return;
|
||||||
|
const window = BrowserWindow.fromWebContents(sender);
|
||||||
|
return window.isMaximized();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user