2021-12-15 23:32:00 +01:00
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
|
|
|
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
|
|
|
|
|
|
|
import { isMacAppStore } from "jslib-electron/utils";
|
|
|
|
import { WindowMain } from "jslib-electron/window.main";
|
|
|
|
|
|
|
|
import { IMenubarMenu } from "./menubar";
|
|
|
|
|
|
|
|
import { MenuItemConstructorOptions } from "electron";
|
|
|
|
|
|
|
|
export class WindowMenu implements IMenubarMenu {
|
|
|
|
readonly id: string;
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
get label(): string {
|
|
|
|
return this.localize("window");
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
get items(): MenuItemConstructorOptions[] {
|
|
|
|
return [
|
|
|
|
this.minimize,
|
|
|
|
this.hideToMenu,
|
|
|
|
this.alwaysOnTop,
|
|
|
|
this.zoom,
|
|
|
|
this.separator,
|
|
|
|
this.bringAllToFront,
|
|
|
|
this.close,
|
|
|
|
];
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private readonly _i18nService: I18nService;
|
|
|
|
private readonly _messagingService: MessagingService;
|
|
|
|
private readonly _window: WindowMain;
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
constructor(
|
|
|
|
i18nService: I18nService,
|
|
|
|
messagingService: MessagingService,
|
|
|
|
windowMain: WindowMain
|
|
|
|
) {
|
|
|
|
this._i18nService = i18nService;
|
|
|
|
this._messagingService = messagingService;
|
|
|
|
this._window = windowMain;
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get minimize(): MenuItemConstructorOptions {
|
|
|
|
return {
|
|
|
|
id: "minimize",
|
|
|
|
label: this.localize("minimize"),
|
|
|
|
role: "minimize",
|
|
|
|
visible: isMacAppStore(),
|
|
|
|
};
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get hideToMenu(): MenuItemConstructorOptions {
|
|
|
|
return {
|
|
|
|
id: "hideToMenu",
|
|
|
|
label: this.localize(isMacAppStore() ? "hideToMenuBar" : "hideToTray"),
|
|
|
|
click: () => this.sendMessage("hideToTray"),
|
|
|
|
accelerator: "CmdOrCtrl+Shift+M",
|
|
|
|
};
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get alwaysOnTop(): MenuItemConstructorOptions {
|
|
|
|
return {
|
|
|
|
id: "alwaysOnTop",
|
|
|
|
label: this.localize("alwaysOnTop"),
|
|
|
|
type: "checkbox",
|
|
|
|
checked: this._window.win.isAlwaysOnTop(),
|
|
|
|
click: () => this._window.toggleAlwaysOnTop(),
|
|
|
|
accelerator: "CmdOrCtrl+Shift+T",
|
|
|
|
};
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get zoom(): MenuItemConstructorOptions {
|
|
|
|
return {
|
|
|
|
id: "zoom",
|
|
|
|
label: this.localize("zoom"),
|
|
|
|
role: "zoom",
|
|
|
|
visible: isMacAppStore(),
|
|
|
|
};
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get separator(): MenuItemConstructorOptions {
|
|
|
|
return { type: "separator" };
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get bringAllToFront(): MenuItemConstructorOptions {
|
|
|
|
return {
|
|
|
|
id: "bringAllToFront",
|
|
|
|
label: this.localize("bringAllToFront"),
|
|
|
|
role: "front",
|
|
|
|
visible: isMacAppStore(),
|
|
|
|
};
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get close(): MenuItemConstructorOptions {
|
|
|
|
return {
|
|
|
|
id: "close",
|
|
|
|
label: this.localize("close"),
|
|
|
|
role: "close",
|
|
|
|
visible: isMacAppStore(),
|
|
|
|
};
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private localize(s: string) {
|
|
|
|
return this._i18nService.t(s);
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private sendMessage(message: string, args?: any) {
|
|
|
|
this._messagingService.send(message, args);
|
|
|
|
}
|
|
|
|
}
|