update service fix

This commit is contained in:
Andrew Pareles 2025-04-15 15:56:15 -07:00
parent 119db73f69
commit feea5e13f3
2 changed files with 64 additions and 22 deletions

View file

@ -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: () => {

View file

@ -23,6 +23,7 @@ export class VoidMainUpdateService extends Disposable implements IVoidUpdateServ
super()
}
async check(explicit: boolean): Promise<VoidCheckUpdateRespose> {
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<VoidCheckUpdateRespose> {
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
}
}