优化更新失败时的提示语

修复检查更新按钮点击后有重影
This commit is contained in:
xintaofei
2026-03-08 08:35:50 +08:00
parent a16a230c44
commit ab31d3063e
5 changed files with 141 additions and 25 deletions

View File

@@ -7,6 +7,18 @@ export interface AppUpdateCheckResult {
update: Update | null
}
export type AppUpdateErrorKind =
| "source_unreachable"
| "network"
| "download_failed"
| "install_failed"
| "unknown"
export interface AppUpdateErrorInfo {
kind: AppUpdateErrorKind
rawMessage: string
}
export async function getCurrentAppVersion(): Promise<string> {
return getVersion()
}
@@ -27,3 +39,49 @@ export async function relaunchApp(): Promise<void> {
export async function closeAppUpdate(update: Update): Promise<void> {
await update.close()
}
function toErrorMessage(error: unknown): string {
if (error instanceof Error) return error.message
return String(error)
}
export function normalizeAppUpdateError(error: unknown): AppUpdateErrorInfo {
const rawMessage = toErrorMessage(error)
const normalized = rawMessage.toLowerCase()
if (
normalized.includes("latest.json") ||
normalized.includes("/releases/latest/download/")
) {
return { kind: "source_unreachable", rawMessage }
}
if (
normalized.includes("error sending request for url") ||
normalized.includes("failed to send request") ||
normalized.includes("network") ||
normalized.includes("timed out") ||
normalized.includes("dns") ||
normalized.includes("connection refused")
) {
return { kind: "network", rawMessage }
}
if (
normalized.includes("download") ||
normalized.includes("checksum") ||
normalized.includes("content-length")
) {
return { kind: "download_failed", rawMessage }
}
if (
normalized.includes("install") ||
normalized.includes("installer") ||
normalized.includes("permission denied")
) {
return { kind: "install_failed", rawMessage }
}
return { kind: "unknown", rawMessage }
}