diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 7868f33..6a7a394 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -31,7 +31,7 @@ declare global { autoHideMenuBar?: boolean; locale?: string | string[]; disableHardwareAcceleration?: boolean; - monochrome?: boolean; + monochromeIcon?: boolean; }>; } /* eslint-enable no-var */ diff --git a/src/settings.ts b/src/settings.ts index 50e3a08..b4a13ad 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -67,4 +67,13 @@ export const Settings: Record = { global.store.set("disableHardwareAcceleration", !value); }, }, + "Electron.monochromeIcon": { + async read(): Promise { + return tray.isMonochrome(); + }, + async write(value: any): Promise { + global.store.set("monochromeIcon", value); + tray.refreshIcon(); + }, + }, }; diff --git a/src/tray.ts b/src/tray.ts index f633380..b863238 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -28,6 +28,19 @@ export function destroy(): void { } } +export function isMonochrome(): boolean { + return global.store.get("monochromeIcon", process.platform === "linux"); +} + +export function refreshIcon(): void { + const monochrome = isMonochrome(); + if (monochrome) { + trayIcon?.setImage(nativeImage.createFromPath(global.trayConfig.monochrome_icon_path)); + } else { + trayIcon?.setImage(nativeImage.createFromPath(global.trayConfig.color_icon_path)); + } +} + function toggleWin(): void { if (global.mainWindow?.isVisible() && !global.mainWindow.isMinimized() && global.mainWindow.isFocused()) { global.mainWindow.hide(); @@ -38,17 +51,6 @@ function toggleWin(): void { } } -function toggleMonochrome(): void { - const monochrome = !isMonochrome(); - if (monochrome) { - trayIcon?.setImage(nativeImage.createFromPath(global.trayConfig.monochrome_icon_path)); - } else { - trayIcon?.setImage(nativeImage.createFromPath(global.trayConfig.color_icon_path)); - } - global.store.set("monochrome", monochrome); - initApplicationMenu(); -} - interface IConfig { color_icon_path: string; // eslint-disable-line camelcase monochrome_icon_path: string; // eslint-disable-line camelcase @@ -61,10 +63,6 @@ function getUuid(): string { return global.vectorConfig["uuid"] || "eba84003-e499-4563-8e9d-166e34b5cc25"; } -function isMonochrome(): boolean { - return global.store.get("monochrome", process.platform === "linux"); -} - export function create(config: IConfig): void { // no trays on darwin if (process.platform === "darwin" || trayIcon) return; @@ -132,12 +130,6 @@ export function initApplicationMenu(): void { } const contextMenu = Menu.buildFromTemplate([ - { - label: _t("action|toggle_monochrome"), - click: toggleMonochrome, - type: "checkbox", - checked: isMonochrome(), - }, { label: _t("action|show_hide"), click: toggleWin,