From 7519f052386a2d891c488bd2521ff8be9db61d5a Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Mon, 20 Jan 2025 00:51:27 -0800 Subject: [PATCH] update state --- .../platform/void/common/voidUpdateService.ts | 2 +- .../electron-main/voidUpdateMainService.ts | 11 ++++--- .../contrib/void/browser/voidUpdateActions.ts | 31 ++++++++++++++++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/vs/platform/void/common/voidUpdateService.ts b/src/vs/platform/void/common/voidUpdateService.ts index 2f4a6264..0304073f 100644 --- a/src/vs/platform/void/common/voidUpdateService.ts +++ b/src/vs/platform/void/common/voidUpdateService.ts @@ -12,7 +12,7 @@ import { InstantiationType, registerSingleton } from '../../instantiation/common export interface IVoidUpdateService { readonly _serviceBrand: undefined; - check: () => Promise<{ message: string } | null>; + check: () => Promise<{ hasUpdate: true, message: string } | { hasUpdate: false } | null>; } diff --git a/src/vs/platform/void/electron-main/voidUpdateMainService.ts b/src/vs/platform/void/electron-main/voidUpdateMainService.ts index b8ca462e..97328b62 100644 --- a/src/vs/platform/void/electron-main/voidUpdateMainService.ts +++ b/src/vs/platform/void/electron-main/voidUpdateMainService.ts @@ -30,15 +30,16 @@ export class VoidMainUpdateService extends Disposable implements IVoidUpdateServ } try { - const res = await fetch(`https://updates.voideditor.dev/api/v0/${this._productService.commit}`) + const res = await fetch(`https://updates.voideditor.dev/api/v0/${this._productService.commit ?? '6e1f8a08b39b9fcc2810356a7e69e65d6e61d13f'}`) const resJSON = await res.json() if (!resJSON) return null - const { downloadMessage } = resJSON ?? {} - if (!downloadMessage) return null + const { hasUpdate, downloadMessage } = resJSON ?? {} + if (hasUpdate === undefined) + return null - const after = downloadMessage - return { message: after } + const after = (downloadMessage || '') + '' + return { hasUpdate: !!hasUpdate, message: after } } catch (e) { return null diff --git a/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts b/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts index d45e4e55..ae3e9849 100644 --- a/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts +++ b/src/vs/workbench/contrib/void/browser/voidUpdateActions.ts @@ -13,16 +13,29 @@ import { IVoidUpdateService } from '../../../../platform/void/common/voidUpdateS import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js'; -const afterGetRes = (res: null | { message: string }, notifService: INotificationService) => { - if (res === null) return - const message = res?.message ?? 'This is a very old version of void, please download the latest version! [Void Editor](https://voideditor.com/download-beta)! ' +const notifyYesUpdate = (notifService: INotificationService, msg?: string) => { + const message = msg || 'This is a very old version of void, please download the latest version! [Void Editor](https://voideditor.com/download-beta)!' notifService.notify({ severity: Severity.Info, message: message, }) } +const notifyNoUpdate = (notifService: INotificationService) => { + notifService.notify({ + severity: Severity.Info, + message: 'Void is up-to-date!', + }) +} +const notifyErrChecking = (notifService: INotificationService) => { + const message = `Void Error: There was an error checking for updates. If this persists for a few days, please get in touch or re-download Void [here](https://voideditor.com/download-beta)!` + notifService.notify({ + severity: Severity.Info, + message: message, + }) +} + // Action @@ -39,7 +52,9 @@ registerAction2(class extends Action2 { const notifService = accessor.get(INotificationService) const res = await voidUpdateService.check() - afterGetRes(res, notifService) + if (!res) notifyErrChecking(notifService) + else if (res.hasUpdate) notifyYesUpdate(notifService, res.message) + else if (!res.hasUpdate) notifyNoUpdate(notifService) } }) @@ -51,9 +66,15 @@ class VoidUpdateWorkbenchContribution extends Disposable implements IWorkbenchCo @INotificationService private readonly notifService: INotificationService ) { super() + + // on mount setTimeout(async () => { const res = await this.voidUpdateService.check() - afterGetRes(res, this.notifService) + + if (!res) notifyErrChecking(this.notifService) + else if (res.hasUpdate) notifyYesUpdate(this.notifService, res.message) + else if (!res.hasUpdate) { } // display nothing if up to date + }, 5 * 1000) } }