[Desktop] Add toasts for update check (#3723)

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
This commit is contained in:
Benjamin Lu
2025-05-02 11:06:51 -04:00
committed by GitHub
parent 869f500d4e
commit b61640c51b
8 changed files with 62 additions and 8 deletions

View File

@@ -1,7 +1,10 @@
import log from 'loglevel'
import { PYTHON_MIRROR } from '@/constants/uvMirrors'
import { t } from '@/i18n'
import { app } from '@/scripts/app'
import { useDialogService } from '@/services/dialogService'
import { useToastStore } from '@/stores/toastStore'
import { useWorkflowStore } from '@/stores/workflowStore'
import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
import { checkMirrorReachable } from '@/utils/networkUtil'
@@ -12,6 +15,7 @@ import { checkMirrorReachable } from '@/utils/networkUtil'
const electronAPI = getElectronAPI()
const desktopAppVersion = await electronAPI.getElectronVersion()
const workflowStore = useWorkflowStore()
const toastStore = useToastStore()
const onChangeRestartApp = (newValue: string, oldValue: string) => {
// Add a delay to allow changes to take effect before restarting.
@@ -163,19 +167,48 @@ import { checkMirrorReachable } from '@/utils/networkUtil'
label: 'Check for Updates',
icon: 'pi pi-sync',
async function() {
const updateAvailable = await electronAPI.checkForUpdates({
disableUpdateReadyAction: true
})
if (updateAvailable.isUpdateAvailable) {
const version = updateAvailable.version
try {
const updateInfo = await electronAPI.checkForUpdates({
disableUpdateReadyAction: true
})
if (!updateInfo.isUpdateAvailable) {
toastStore.add({
severity: 'info',
summary: t('desktopUpdate.noUpdateFound'),
life: 5_000
})
return
}
const proceed = await useDialogService().confirm({
title: t('desktopUpdate.updateFoundTitle', { version }),
title: t('desktopUpdate.updateFoundTitle', {
version: updateInfo.version
}),
message: t('desktopUpdate.updateAvailableMessage'),
type: 'default'
})
if (proceed) {
electronAPI.restartAndInstall()
try {
electronAPI.restartAndInstall()
} catch (error) {
log.error('Error installing update:', error)
toastStore.add({
severity: 'error',
summary: t('g.error'),
detail: t('desktopUpdate.errorInstallingUpdate'),
life: 10_000
})
}
}
} catch (error) {
log.error('Error checking for updates:', error)
toastStore.add({
severity: 'error',
summary: t('g.error'),
detail: t('desktopUpdate.errorCheckingUpdate'),
life: 10_000
})
}
}
},