diff --git a/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts b/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts index da0e5fc7..905b9b80 100644 --- a/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts +++ b/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts @@ -46,13 +46,23 @@ const notifyYesUpdate = (notifService: INotificationService, res: { message?: st const { window } = dom.getActiveWindow() window.open('https://voideditor.com/') } + }], + secondary: [{ + id: 'void.updater.close', + enabled: true, + label: `Keep Void outdated`, + tooltip: '', + class: undefined, + run: () => { + notifController.close() + } }] }, }) - const d = notifController.onDidClose(() => { - notifyYesUpdate(notifService, res) - d.dispose() - }) + // const d = notifController.onDidClose(() => { + // notifyYesUpdate(notifService, res) + // d.dispose() + // }) } const notifyNoUpdate = (notifService: INotificationService) => { notifService.notify({ @@ -86,7 +96,7 @@ registerAction2(class extends Action2 { const metricsService = accessor.get(IMetricsService) metricsService.capture('Void Update Manual: Checking...', {}) - const res = await voidUpdateService.check() + const res = await voidUpdateService.check(true) if (!res) { notifyErrChecking(notifService); metricsService.capture('Void Update Manual: Error', { res }) } else if (res.hasUpdate) { notifyYesUpdate(notifService, res); metricsService.capture('Void Update Manual: Yes', { res }) } else if (!res.hasUpdate) { notifyNoUpdate(notifService); metricsService.capture('Void Update Manual: No', { res }) } @@ -104,7 +114,7 @@ class VoidUpdateWorkbenchContribution extends Disposable implements IWorkbenchCo super() const autoCheck = async () => { this.metricsService.capture('Void Update Startup: Checking...', {}) - const res = await this.voidUpdateService.check() + const res = await this.voidUpdateService.check(false) if (!res) { notifyErrChecking(this.notifService); this.metricsService.capture('Void Update Startup: Error', { res }) } else if (res.hasUpdate) { notifyYesUpdate(this.notifService, res); this.metricsService.capture('Void Update Startup: Yes', { res }) } else if (!res.hasUpdate) { this.metricsService.capture('Void Update Startup: No', { res }) } // display nothing if up to date diff --git a/src/vs/workbench/contrib/void/common/voidUpdateService.ts b/src/vs/workbench/contrib/void/common/voidUpdateService.ts index f552594f..d6fe4140 100644 --- a/src/vs/workbench/contrib/void/common/voidUpdateService.ts +++ b/src/vs/workbench/contrib/void/common/voidUpdateService.ts @@ -12,7 +12,7 @@ import { IMainProcessService } from '../../../../platform/ipc/common/mainProcess export interface IVoidUpdateService { readonly _serviceBrand: undefined; - check: () => Promise<{ hasUpdate: true, message: string } | { hasUpdate: false } | null>; + check: (explicit: boolean) => Promise<{ hasUpdate: true, message: string } | { hasUpdate: false } | null>; } @@ -34,8 +34,8 @@ export class VoidUpdateService implements IVoidUpdateService { // anything transmitted over a channel must be async even if it looks like it doesn't have to be - check: IVoidUpdateService['check'] = async () => { - const res = await this.voidUpdateService.check() + check: IVoidUpdateService['check'] = async (explicit) => { + const res = await this.voidUpdateService.check(explicit) return res } } diff --git a/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts b/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts index c691ff56..7570d965 100644 --- a/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts +++ b/src/vs/workbench/contrib/void/electron-main/voidUpdateMainService.ts @@ -6,7 +6,7 @@ import { Disposable } from '../../../../base/common/lifecycle.js'; import { IEnvironmentMainService } from '../../../../platform/environment/electron-main/environmentMainService.js'; import { IProductService } from '../../../../platform/product/common/productService.js'; - +import { IUpdateService, StateType } from '../../../../platform/update/common/update.js'; import { IVoidUpdateService } from '../common/voidUpdateService.js'; @@ -17,22 +17,37 @@ export class VoidMainUpdateService extends Disposable implements IVoidUpdateServ constructor( @IProductService private readonly _productService: IProductService, @IEnvironmentMainService private readonly _envMainService: IEnvironmentMainService, + @IUpdateService private readonly _updateService: IUpdateService ) { super() } - async check() { + nIgnores = 0 + async check(explicit: boolean) { + const isDevMode = !this._envMainService.isBuilt // found in abstractUpdateService.ts if (isDevMode) { return { hasUpdate: false } as const } + this._updateService.checkForUpdates(false) // implicity check, then handle result ourselves + + if (this._updateService.state.type === StateType.Ready) { + return { hasUpdate: true, message: 'Restart Void to update!' } + } + + const wasAutomaticCheck = !explicit // ignore the first auto check, just use it to call updateService.check() + if (wasAutomaticCheck && this.nIgnores < 1) { + this.nIgnores += 1 + return { hasUpdate: false } as const + } + try { const res = await fetch(`https://updates.voideditor.dev/api/v0/${this._productService.commit}`) const resJSON = await res.json() - if (!resJSON) return null + if (!resJSON) return null // null means error const { hasUpdate, downloadMessage } = resJSON ?? {} if (hasUpdate === undefined)