refactor: 移除WebSocket同步功能及相关代码

feat(theme): 增强侧边栏选中项样式配置
style: 优化主题变量和样式覆盖逻辑
chore: 清理未使用的依赖和配置文件
This commit is contained in:
Fox_block
2026-01-18 11:44:50 +08:00
parent b41139b941
commit e83f17af56
70 changed files with 4199 additions and 2173 deletions
+146
View File
@@ -0,0 +1,146 @@
import { Service } from '../../shared/kernel'
import { MainContext } from '../context'
import { BrowserWindow, shell } from 'electron'
import type { BrowserWindowConstructorOptions } from 'electron'
export type windowOpenInput = {
key: string
title?: string
route?: string
options?: BrowserWindowConstructorOptions
}
export type windowManagerOptions = {
icon: any
preloadPath: string
rendererHtmlPath: string
getRendererUrl: () => string | undefined
}
declare module '../../shared/kernel' {
interface Context {
windows: WindowManager
}
}
export class WindowManager extends Service {
private readonly windows = new Map<string, BrowserWindow>()
constructor(
ctx: MainContext,
private readonly opts: windowManagerOptions
) {
super(ctx, 'windows')
this.registerIpc()
}
private get mainCtx() {
return this.ctx as MainContext
}
public get(key: string) {
const existing = this.windows.get(key)
if (!existing) return null
if (existing.isDestroyed()) {
this.windows.delete(key)
return null
}
return existing
}
public open(input: windowOpenInput) {
const existing = this.get(input.key)
if (existing) {
if (input.route) void this.loadRoute(existing, input.route)
existing.show()
existing.focus()
return existing
}
const win = new BrowserWindow({
width: 900,
height: 670,
show: false,
autoHideMenuBar: true,
icon: this.opts.icon,
title: input.title,
webPreferences: {
preload: this.opts.preloadPath,
sandbox: false
},
...input.options
})
this.windows.set(input.key, win)
win.on('closed', () => {
this.windows.delete(input.key)
})
win.on('ready-to-show', () => {
win.show()
})
win.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url)
return { action: 'deny' }
})
void this.loadRoute(win, input.route ?? '/')
return win
}
public navigate(key: string, route: string) {
const win = this.get(key)
if (!win) return false
void this.loadRoute(win, route)
return true
}
public navigateWindow(win: BrowserWindow, route: string) {
if (win.isDestroyed()) return false
void this.loadRoute(win, route)
return true
}
private async loadRoute(win: BrowserWindow, route: string) {
const normalizedRoute = route.startsWith('/') ? route : `/${route}`
const rendererUrl = this.opts.getRendererUrl()
if (rendererUrl) {
await win.loadURL(`${rendererUrl}#${normalizedRoute}`)
return
}
await win.loadFile(this.opts.rendererHtmlPath, { hash: normalizedRoute })
}
private registerIpc() {
this.mainCtx.handle('window:open', async (_event, input: any) => {
const key = String(input?.key ?? '').trim()
if (!key) return { success: false, message: 'Missing key' }
this.open({
key,
title: input?.title ? String(input.title) : undefined,
route: input?.route ? String(input.route) : undefined,
options: input?.options
})
return { success: true }
})
this.mainCtx.handle('window:navigate', async (event, input: any) => {
const route = String(input?.route ?? '').trim()
if (!route) return { success: false, message: 'Missing route' }
const key = input?.key ? String(input.key).trim() : ''
if (key) {
const ok = this.navigate(key, route)
return ok ? { success: true } : { success: false, message: 'Window not found' }
}
const win = BrowserWindow.fromWebContents(event.sender)
if (!win) return { success: false, message: 'Window not found' }
const ok = this.navigateWindow(win, route)
return ok ? { success: true } : { success: false, message: 'Window not found' }
})
}
}