Files
xk-admin/apps/desktop/src/main/menu.ts

90 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { app, dialog, Menu } from 'electron';
import { checkForUpdates } from './updater';
import { getMainWindow, markQuitting } from './window';
/**
* 应用菜单
* - macOS:系统菜单栏(不占窗口客户区),保留编辑/窗口角色以保证快捷键
* - Windows/Linux:不挂原生菜单栏,检查更新/刷新等走托盘 + Ctrl+R
*/
/** 刷新当前主窗口页面 */
export function reloadMainWindow(): void {
getMainWindow()?.webContents.reload();
}
/** 「关于」弹窗 */
export function showAboutDialog(): void {
dialog.showMessageBox({
type: 'info',
title: '关于',
message: '萧康云医',
detail: `版本:v${app.getVersion()}\n平台:${process.platform}`,
});
}
/**
* 注册应用菜单
* Win/Linux 设 null,避免占客户区;刷新快捷键在 window.ts 拦截
*/
export function createAppMenu(): void {
if (process.platform === 'darwin') {
Menu.setApplicationMenu(
Menu.buildFromTemplate([
{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{
label: '检查更新',
click: () => checkForUpdates(true),
},
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
},
{ role: 'editMenu' },
{
label: '查看',
submenu: [
{
label: '刷新',
accelerator: 'CmdOrCtrl+R',
click: () => reloadMainWindow(),
},
{ type: 'separator' },
{ role: 'togglefullscreen' },
],
},
{ role: 'windowMenu' },
{
label: '帮助',
submenu: [
{
label: '关于萧康云医',
click: () => showAboutDialog(),
},
],
},
]),
);
return;
}
Menu.setApplicationMenu(null);
}
/** 供托盘等复用:退出 */
export function quitApp(): void {
markQuitting();
app.quit();
}