From 7d446b23a484f8f253357ea93c873dd7a28e07c7 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 11 Nov 2025 14:19:53 +0800 Subject: [PATCH] refactor(updater): streamline update decision handling by introducing handleDirectAppDecision method - Consolidated update decision logic into a new method for better readability and maintainability. - Updated fallback logic to utilize the new method when distribution update info is unavailable. Signed-off-by: Innei --- apps/desktop/layer/main/src/updater/index.ts | 48 ++++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/apps/desktop/layer/main/src/updater/index.ts b/apps/desktop/layer/main/src/updater/index.ts index d21b03b68..37a771b3c 100644 --- a/apps/desktop/layer/main/src/updater/index.ts +++ b/apps/desktop/layer/main/src/updater/index.ts @@ -116,25 +116,8 @@ class FollowUpdater { } const payload = await getUpdateInfo(options.refresh ? { refresh: true } : {}) - const { decision } = payload - if (!decision || decision.type === "none") { - logger.info("Update decision: none") - return { hasUpdate: false } - } - - if (decision.type === "renderer") { - logger.info("Update decision: renderer") - return await this.handleRendererDecision(payload) - } - - if (decision.type === "app") { - logger.info("Update decision: app") - return await this.handleAppDecision(payload) - } - - logger.warn("Unknown update decision type", { type: decision.type }) - return { hasUpdate: false } + return this.handleDirectAppDecision(payload) } catch (error) { logger.error("Failed to check for updates", error) return { hasUpdate: false, error: error instanceof Error ? error.message : "Unknown error" } @@ -143,6 +126,28 @@ class FollowUpdater { } } + async handleDirectAppDecision(payload: LatestReleasePayload): Promise { + const { decision } = payload + + if (!decision || decision.type === "none") { + logger.info("Update decision: none") + return { hasUpdate: false } + } + + if (decision.type === "renderer") { + logger.info("Update decision: renderer") + return await this.handleRendererDecision(payload) + } + + if (decision.type === "app") { + logger.info("Update decision: app") + return await this.handleAppDecision(payload) + } + + logger.warn("Unknown update decision type", { type: decision.type }) + return { hasUpdate: false } + } + async downloadAppUpdate(): Promise { if (this.disabled || this.downloadingUpdate) { return @@ -266,8 +271,11 @@ class FollowUpdater { const info = await getDistributionUpdateInfo() if (!info) { - logger.info("Distribution update info unavailable for current build") - return { hasUpdate: false } + logger.info( + "Distribution update info unavailable for current build, falling back to direct app decision", + ) + const payload = await getUpdateInfo() + return this.handleDirectAppDecision(payload) } const rendererResult = await this.tryDistributionRendererUpdate(info.rendererUpdate)