2022-02-24 20:50:19 +01:00
|
|
|
import { MenuItemConstructorOptions } from "electron";
|
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
|
|
|
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
2022-01-28 17:27:30 +01:00
|
|
|
import { isMac } from "jslib-electron/utils";
|
2021-12-15 23:32:00 +01:00
|
|
|
import { WindowMain } from "jslib-electron/window.main";
|
|
|
|
|
|
|
|
import { IMenubarMenu } from "./menubar";
|
|
|
|
|
|
|
|
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[] {
|
2022-01-28 17:27:30 +01:00
|
|
|
const items = [this.minimize, this.hideToMenu, this.alwaysOnTop];
|
|
|
|
|
|
|
|
if (isMac()) {
|
2022-02-23 15:58:59 +01:00
|
|
|
items.push(this.zoom, this.separator, this.bringAllToFront);
|
2022-01-07 15:54:35 +01:00
|
|
|
}
|
|
|
|
|
2022-02-23 15:58:59 +01:00
|
|
|
items.push(this.separator, this.close);
|
2022-01-28 17:27:30 +01:00
|
|
|
return items;
|
2021-12-15 23:32:00 +01:00
|
|
|
}
|
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",
|
|
|
|
};
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
private get hideToMenu(): MenuItemConstructorOptions {
|
|
|
|
return {
|
|
|
|
id: "hideToMenu",
|
2022-01-28 17:27:30 +01:00
|
|
|
label: this.localize(isMac() ? "hideToMenuBar" : "hideToTray"),
|
2021-12-15 23:32:00 +01:00
|
|
|
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",
|
|
|
|
};
|
|
|
|
}
|
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",
|
|
|
|
};
|
|
|
|
}
|
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",
|
|
|
|
};
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|