mirror of
https://github.com/CringeStudios/element-desktop.git
synced 2025-01-18 23:44:59 +01:00
Remove context item and replace with setting
This commit is contained in:
parent
967fa056a2
commit
2176750586
2
src/@types/global.d.ts
vendored
2
src/@types/global.d.ts
vendored
@ -31,7 +31,7 @@ declare global {
|
|||||||
autoHideMenuBar?: boolean;
|
autoHideMenuBar?: boolean;
|
||||||
locale?: string | string[];
|
locale?: string | string[];
|
||||||
disableHardwareAcceleration?: boolean;
|
disableHardwareAcceleration?: boolean;
|
||||||
monochrome?: boolean;
|
monochromeIcon?: boolean;
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
/* eslint-enable no-var */
|
/* eslint-enable no-var */
|
||||||
|
@ -67,4 +67,13 @@ export const Settings: Record<string, Setting> = {
|
|||||||
global.store.set("disableHardwareAcceleration", !value);
|
global.store.set("disableHardwareAcceleration", !value);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"Electron.monochromeIcon": {
|
||||||
|
async read(): Promise<any> {
|
||||||
|
return tray.isMonochrome();
|
||||||
|
},
|
||||||
|
async write(value: any): Promise<void> {
|
||||||
|
global.store.set("monochromeIcon", value);
|
||||||
|
tray.refreshIcon();
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
34
src/tray.ts
34
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 {
|
function toggleWin(): void {
|
||||||
if (global.mainWindow?.isVisible() && !global.mainWindow.isMinimized() && global.mainWindow.isFocused()) {
|
if (global.mainWindow?.isVisible() && !global.mainWindow.isMinimized() && global.mainWindow.isFocused()) {
|
||||||
global.mainWindow.hide();
|
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 {
|
interface IConfig {
|
||||||
color_icon_path: string; // eslint-disable-line camelcase
|
color_icon_path: string; // eslint-disable-line camelcase
|
||||||
monochrome_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";
|
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 {
|
export function create(config: IConfig): void {
|
||||||
// no trays on darwin
|
// no trays on darwin
|
||||||
if (process.platform === "darwin" || trayIcon) return;
|
if (process.platform === "darwin" || trayIcon) return;
|
||||||
@ -132,12 +130,6 @@ export function initApplicationMenu(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
{
|
|
||||||
label: _t("action|toggle_monochrome"),
|
|
||||||
click: toggleMonochrome,
|
|
||||||
type: "checkbox",
|
|
||||||
checked: isMonochrome(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: _t("action|show_hide"),
|
label: _t("action|show_hide"),
|
||||||
click: toggleWin,
|
click: toggleWin,
|
||||||
|
Loading…
Reference in New Issue
Block a user