mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 18:19:03 +08:00
f57597ca57
- 新增 TrayService 实现系统托盘功能 - 主窗口关闭时默认隐藏而非退出 - 添加 window_zoom 配置项支持窗口缩放 - 引入 TrayServiceToken 作为依赖注入标识 - 通过 isQuitting 状态控制应用退出行为
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { Service } from '../../shared/kernel'
|
|
import { MainContext } from '../context'
|
|
import { Tray, Menu, app, nativeImage } from 'electron'
|
|
import type { windowManagerOptions } from './WindowManager'
|
|
|
|
export class TrayService extends Service {
|
|
private tray: Tray | null = null
|
|
|
|
constructor(
|
|
ctx: MainContext,
|
|
private readonly opts: windowManagerOptions
|
|
) {
|
|
super(ctx, 'tray')
|
|
}
|
|
|
|
private get mainCtx() {
|
|
return this.ctx as MainContext
|
|
}
|
|
|
|
public initialize() {
|
|
const icon = nativeImage.createFromPath(this.opts.icon)
|
|
this.tray = new Tray(icon)
|
|
|
|
const contextMenu = Menu.buildFromTemplate([
|
|
{
|
|
label: '显示主窗口',
|
|
click: () => {
|
|
this.showMainWindow()
|
|
}
|
|
},
|
|
{ type: 'separator' },
|
|
{
|
|
label: '退出 SecScore',
|
|
click: () => {
|
|
app.quit()
|
|
}
|
|
}
|
|
])
|
|
|
|
this.tray.setToolTip('SecScore 积分管理')
|
|
this.tray.setContextMenu(contextMenu)
|
|
|
|
this.tray.on('double-click', () => {
|
|
this.showMainWindow()
|
|
})
|
|
}
|
|
|
|
private showMainWindow() {
|
|
const mainWin = this.mainCtx.windows.get('main')
|
|
if (mainWin) {
|
|
if (mainWin.isMinimized()) mainWin.restore()
|
|
mainWin.show()
|
|
mainWin.focus()
|
|
} else {
|
|
this.mainCtx.windows.open({ key: 'main', title: 'SecScore', route: '/' })
|
|
}
|
|
}
|
|
}
|