fix load app, download, upgrade

This commit is contained in:
2026-03-16 15:53:59 +08:00
parent b34720fccf
commit 970d6d9538
16 changed files with 487 additions and 107 deletions

View File

@@ -4,7 +4,8 @@
* Based on REQUIREMENTS.md:228-268
*/
import { ipcMain, dialog } from "electron";
import { ipcMain, dialog, app } from "electron";
import { autoUpdater } from "electron-updater";
import { v4 as uuidv4 } from "uuid";
import {
saveDomain,
@@ -34,6 +35,7 @@ import type {
GetVersionsParams,
RollbackParams,
SetLocaleParams,
CheckUpdateResult,
} from "@shared/types/ipc";
import type { LocaleCode } from "@shared/types/locale";
import type {
@@ -539,6 +541,69 @@ function registerSetLocale(): void {
});
}
// ==================== App Version & Update IPC Handlers ====================
/**
* Get the current app version
*/
function registerGetAppVersion(): void {
handle<void, string>("getAppVersion", async () => {
return app.getVersion();
});
}
/**
* Check for app updates
*/
function registerCheckForUpdates(): void {
handle<void, CheckUpdateResult>("checkForUpdates", async () => {
try {
// In development, autoUpdater.checkForUpdates will throw an error
// because there's no update server configured
if (process.env.NODE_ENV === "development" || !app.isPackaged) {
// Return mock result for development
return {
hasUpdate: false,
updateInfo: undefined,
};
}
const result = await autoUpdater.checkForUpdates();
if (result && result.updateInfo) {
const currentVersion = app.getVersion();
const latestVersion = result.updateInfo.version;
// Compare versions
const hasUpdate = latestVersion !== currentVersion;
return {
hasUpdate,
updateInfo: hasUpdate
? {
version: result.updateInfo.version,
releaseDate: result.updateInfo.releaseDate,
releaseNotes: result.releaseNotes as string | undefined,
}
: undefined,
};
}
return {
hasUpdate: false,
updateInfo: undefined,
};
} catch (error) {
// If update check fails, return no update available
console.error("Update check failed:", error);
return {
hasUpdate: false,
updateInfo: undefined,
};
}
});
}
// ==================== Register All Handlers ====================
/**
@@ -573,6 +638,10 @@ export function registerIpcHandlers(): void {
registerGetLocale();
registerSetLocale();
// App Version & Update
registerGetAppVersion();
registerCheckForUpdates();
// Dialog
registerShowSaveDialog();
registerSaveFileContent();