Files
ZenEcho b48e639490 feat: 引入共享类型与工具层,重构代码结构并优化用户体验
- 新增 `shared/` 目录,统一管理前后端共享的类型定义与工具函数,消除重复代码
- 重构 IPC 数据传输,使用 `toIpcSafeSnapshot` 确保序列化安全
- 新增系统托盘独立窗口 (`/tray` 路由) 与主窗口关闭行为设置,提升用户体验
- 优化 Sing-box 配置校验错误提示,增强可读性
- 修复订阅更新无新节点时的提示逻辑
- 更新项目依赖与构建配置,支持共享层路径别名 (`@shared`)
- 补充单元测试,完善国际化词条
2026-03-01 16:50:40 +08:00

30 lines
699 B
TypeScript

import { ipcMain } from 'electron'
import { DatabaseService } from './database'
import type { Game } from '@shared/types'
/**
* 游戏管理服务
*
* DatabaseService 的 IPC 薄封装层,负责通过 IPC 暴露游戏相关的 CRUD 操作。
*/
export class GameService {
private db: DatabaseService
constructor(db: DatabaseService) {
this.db = db
this.registerIPC()
}
private registerIPC() {
ipcMain.handle('games:get-all', () => this.db.getAllGames())
ipcMain.handle('games:save', async (_, game: Game) => {
return this.db.saveGame(game)
})
ipcMain.handle('games:delete', async (_, id: string) => {
return this.db.deleteGame(id)
})
}
}