feat(全局侧边栏): 添加全局侧边栏功能及窗口导航优化

- 新增全局侧边栏组件,支持展开/收起和快速导航功能
- 添加窗口大小调整和导航事件通信接口
- 优化窗口导航逻辑,使用软导航避免页面重载
- 调整主窗口启动逻辑,默认打开全局侧边栏
This commit is contained in:
Linkon
2026-01-18 22:51:37 +08:00
parent 3c267c0c04
commit df742a6077
7 changed files with 232 additions and 98 deletions
+40 -3
View File
@@ -51,7 +51,10 @@ export class WindowManager extends Service {
public open(input: windowOpenInput) {
const existing = this.get(input.key)
if (existing) {
if (input.route) void this.loadRoute(existing, input.route)
if (input.route) {
// Use soft navigation if window exists to prevent reload
existing.webContents.send('app:navigate', input.route)
}
existing.show()
existing.focus()
return existing
@@ -72,6 +75,25 @@ export class WindowManager extends Service {
...input.options
})
// Special positioning for global sidebar
if (input.key === 'global-sidebar') {
const { screen } = require('electron')
const primaryDisplay = screen.getPrimaryDisplay()
const { width, height } = primaryDisplay.workAreaSize
const winWidth = 84
const winHeight = 300
win.setBounds({
x: width - winWidth,
y: Math.floor(height / 2 - winHeight / 2),
width: winWidth,
height: winHeight
})
win.setAlwaysOnTop(true, 'screen-saver')
win.setVisibleOnAllWorkspaces(true)
win.setSkipTaskbar(true)
win.setResizable(false)
}
const zoom = Number(this.mainCtx.settings.getValue('window_zoom')) || 1.0
win.webContents.setZoomFactor(zoom)
@@ -112,13 +134,13 @@ export class WindowManager extends Service {
public navigate(key: string, route: string) {
const win = this.get(key)
if (!win) return false
void this.loadRoute(win, route)
win.webContents.send('app:navigate', route)
return true
}
public navigateWindow(win: BrowserWindow, route: string) {
if (win.isDestroyed()) return false
void this.loadRoute(win, route)
win.webContents.send('app:navigate', route)
return true
}
@@ -210,5 +232,20 @@ export class WindowManager extends Service {
}
}
})
this.mainCtx.handle('window:resize', (event, width: number, height: number) => {
const win = BrowserWindow.fromWebContents(event.sender)
if (win) {
const bounds = win.getBounds()
// Keep right side pinned
const newX = bounds.x + (bounds.width - width)
win.setBounds({
x: newX,
y: bounds.y,
width,
height
})
}
})
}
}