mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
update state
This commit is contained in:
parent
c2fc2577e0
commit
7519f05238
3 changed files with 33 additions and 11 deletions
|
|
@ -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>;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue