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 <tukon479@gmail.com>
This commit is contained in:
@@ -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<UpdateCheckResult> {
|
||||
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<void> {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user