From feea5e13f337697017f5e325c8921bc8c6452f02 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Tue, 15 Apr 2025 15:56:15 -0700 Subject: [PATCH] update service fix --- .../contrib/void/browser/voidUpdateActions.ts | 2 +- .../electron-main/voidUpdateMainService.ts | 84 ++++++++++++++----- 2 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts b/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts index 378171d1..31666fb6 100644 --- a/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts +++ b/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts @@ -99,7 +99,7 @@ const notifyUpdate = (res: VoidCheckUpdateRespose & { message: string }, notifSe secondary: [{ id: 'void.updater.close', enabled: true, - label: `Keep Void outdated`, + label: `Keep current version`, tooltip: '', class: undefined, run: () => { diff --git a/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts b/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts index df46911c..c8ef9e64 100644 --- a/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts +++ b/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts @@ -23,6 +23,7 @@ export class VoidMainUpdateService extends Disposable implements IVoidUpdateServ super() } + async check(explicit: boolean): Promise { const isDevMode = !this._envMainService.isBuilt // found in abstractUpdateService.ts @@ -37,17 +38,17 @@ export class VoidMainUpdateService extends Disposable implements IVoidUpdateServ if (this._updateService.state.type === StateType.Uninitialized) { // The update service hasn't been initialized yet - return { message: explicit ? 'Not yet checking for updates...' : null, action: explicit ? 'reinstall' : undefined } as const + return { message: explicit ? 'Checking for updates soon...' : null, action: explicit ? 'reinstall' : undefined } as const } if (this._updateService.state.type === StateType.Idle) { // No updates currently available - return { message: explicit ? 'No update found!' : null, action: explicit ? 'reinstall' : undefined } as const + return { message: explicit ? 'No updates found!' : null, action: explicit ? 'reinstall' : undefined } as const } if (this._updateService.state.type === StateType.CheckingForUpdates) { // Currently checking for updates - return { message: explicit ? 'No updates found!' : null } as const + return { message: explicit ? 'Checking for updates...' : null } as const } if (this._updateService.state.type === StateType.AvailableForDownload) { @@ -62,7 +63,7 @@ export class VoidMainUpdateService extends Disposable implements IVoidUpdateServ if (this._updateService.state.type === StateType.Downloaded) { // Update has been downloaded but not yet ready - return { message: explicit ? 'Got download, need to apply...' : null, action: 'apply' } as const + return { message: explicit ? 'An update is ready to be applied!' : null, action: 'apply' } as const } if (this._updateService.state.type === StateType.Updating) { @@ -76,28 +77,69 @@ export class VoidMainUpdateService extends Disposable implements IVoidUpdateServ } if (this._updateService.state.type === StateType.Disabled) { - try { - const res = await fetch(`https://updates.voideditor.dev/api/v0/${this._productService.commit}`) - const resJSON = await res.json() + return await this._manualCheckGHTagIfDisabled(explicit) + } + return null + } - if (!resJSON) return null // null means error - const { hasUpdate, downloadMessage } = resJSON ?? {} - if (hasUpdate === undefined) - return null - const after = (downloadMessage || '') + '' - if (hasUpdate) - return { message: after, action: 'reinstall' } as const - return { message: 'Void is up-to-date!' } as const + + + + private async _manualCheckGHTagIfDisabled(explicit: boolean): Promise { + try { + const response = await fetch('https://api.github.com/repos/voideditor/binaries/releases/latest'); + + const data = await response.json(); + const version = data.tag_name; + + const myVersion = `${this._productService.voidVersion}.${this._productService.release}` + const latestVersion = version + + const isUpToDate = myVersion === latestVersion // only makes sense if response.ok + + let message: string | null + let action: 'reinstall' | undefined + + // explicit + if (explicit) { + if (response.ok) { + if (!isUpToDate) { + message = 'A new version of Void is available! Please reinstall (auto-updates are disabled on this OS) - it only takes a second!' + action = 'reinstall' + } + else { + message = 'Void is up-to-date!' + } + } + else { + message = `An error occurred when fetching the latest GitHub release tag. Please try again in ~5 minutes, or reinstall.` + action = 'reinstall' + } } - catch (e) { - return null + // not explicit + else { + if (response.ok && !isUpToDate) { + message = 'A new version of Void is available! Please reinstall (auto-updates are disabled on this OS) - it only takes a second!' + action = 'reinstall' + } + else { + message = null + } + } + return { message, action } as const + } + catch (e) { + if (explicit) { + return { + message: `An error occurred when fetching the latest GitHub release tag: ${e}. Please try again in ~5 minutes.`, + action: 'reinstall', + } + } + else { + return { message: null } as const } } - - return null - } } -