mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-09-20 13:40:11 +08:00
fix: 修复 before-quit 中 mainWindow 未定义报错,并优化排行榜加载
- electron/main/index.ts: flushSaveBounds 改用模块级 win 变量, 修复关闭应用时 mainWindow is not defined 的 ReferenceError - src/App.vue: loadRanking 并发数降至 15;loadHome 多来源请求并行化 - src/modules/ranking.ts: parseContributors 增强异常格式边界处理
This commit is contained in:
@@ -361,6 +361,16 @@ function saveWindowState(state: WindowState): void {
|
||||
}
|
||||
|
||||
let saveBoundsTimer: NodeJS.Timeout | null = null;
|
||||
function flushSaveBounds(): void {
|
||||
if (saveBoundsTimer) {
|
||||
clearTimeout(saveBoundsTimer);
|
||||
saveBoundsTimer = null;
|
||||
}
|
||||
if (win && !win.isDestroyed()) {
|
||||
const { width, height, x, y } = win.getBounds();
|
||||
saveWindowState({ width, height, x, y, maximized: win.isMaximized() });
|
||||
}
|
||||
}
|
||||
function scheduleSaveBounds(winInstance: BrowserWindow): void {
|
||||
if (saveBoundsTimer) clearTimeout(saveBoundsTimer);
|
||||
saveBoundsTimer = setTimeout(() => {
|
||||
@@ -376,6 +386,11 @@ function scheduleSaveBounds(winInstance: BrowserWindow): void {
|
||||
}, 400);
|
||||
}
|
||||
|
||||
// 应用退出前立即持久化(防抖 400ms 可能在快速关闭时丢失最后一次状态)
|
||||
app.on("before-quit", () => {
|
||||
flushSaveBounds();
|
||||
});
|
||||
|
||||
async function createWindow() {
|
||||
const saved = loadWindowState();
|
||||
// 恢复时:若上次窗口过大(>1600x900,通常为全屏/最大化),回退到默认尺寸并居中,
|
||||
|
||||
Reference in New Issue
Block a user