diff --git a/src/main/index.ts b/src/main/index.ts index ae50c11..00c2380 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -364,12 +364,6 @@ function initAutoUpdater(): void { autoUpdater.on('update-downloaded', (info) => { log.info('Update downloaded:', info.version) mainWindow?.webContents.send('update:downloaded', info) - - if (mainWindow) { - mainWindow.webContents.send('update:show-notification', { - version: info.version - }) - } }) log.info('Auto-updater initialized successfully') diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 8d4bc36..9bb5718 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -55,7 +55,7 @@ function AppContent() { const loadSettings = useSetAtom(loadSettingsAtom) const setUpdateReady = useSetAtom(updateReadyAtom) const setUpdateAvailable = useSetAtom(updateAvailableAtom) - const { t } = useTranslation() + const { i18n } = useTranslation() const updateDownloadInProgressRef = useRef(false) const analyticsScriptRef = useRef(null) const navigate = useNavigate() @@ -197,14 +197,27 @@ function AppContent() { available: true, version: info.version }) + + const versionLabel = info?.version ?? '' + const downloadedMessage = versionLabel + ? i18n.t('about.notifications.updateDownloadedVersion', { version: versionLabel }) + : i18n.t('about.notifications.updateDownloaded') + toast.info(downloadedMessage, { + action: { + label: i18n.t('about.notifications.restartNowAction'), + onClick: () => { + void ipcServices.update.quitAndInstall() + } + } + }) } const handleUpdateError = (rawMessage: unknown) => { const message = typeof rawMessage === 'string' ? rawMessage : '' resetDownloadState() - const errorMessage = message || t('about.notifications.unknownErrorFallback') - toast.error(t('about.notifications.updateError', { error: errorMessage })) + const errorMessage = message || i18n.t('about.notifications.unknownErrorFallback') + toast.error(i18n.t('about.notifications.updateError', { error: errorMessage })) } const handleDownloadProgress = (rawProgress: unknown) => { @@ -214,39 +227,20 @@ function AppContent() { } } - const handleUpdateNotification = (rawPayload: unknown) => { - const payload = (rawPayload ?? {}) as { version?: string } - const versionLabel = payload?.version ?? '' - const downloadedMessage = versionLabel - ? t('about.notifications.updateDownloadedVersion', { version: versionLabel }) - : t('about.notifications.updateDownloaded') - - toast.info(downloadedMessage, { - action: { - label: t('about.notifications.restartNowAction'), - onClick: () => { - void ipcServices.update.quitAndInstall() - } - } - }) - } - // Only listen to update events that should be shown globally // update:available shows a visual indicator in the sidebar ipcEvents.on('update:available', handleUpdateAvailable) ipcEvents.on('update:downloaded', handleUpdateDownloaded) ipcEvents.on('update:error', handleUpdateError) ipcEvents.on('update:download-progress', handleDownloadProgress) - ipcEvents.on('update:show-notification', handleUpdateNotification) return () => { ipcEvents.removeListener('update:available', handleUpdateAvailable) ipcEvents.removeListener('update:downloaded', handleUpdateDownloaded) ipcEvents.removeListener('update:error', handleUpdateError) ipcEvents.removeListener('update:download-progress', handleDownloadProgress) - ipcEvents.removeListener('update:show-notification', handleUpdateNotification) } - }, [setUpdateAvailable, setUpdateReady, t]) + }, [i18n, setUpdateAvailable, setUpdateReady]) return (
diff --git a/src/renderer/src/pages/About.tsx b/src/renderer/src/pages/About.tsx index 0593a20..b3d8d2a 100644 --- a/src/renderer/src/pages/About.tsx +++ b/src/renderer/src/pages/About.tsx @@ -39,7 +39,7 @@ type LatestVersionState = | null export function About() { - const { t } = useTranslation() + const { t, i18n } = useTranslation() const [settings, _setSettings] = useAtom(settingsAtom) const [updateReady] = useAtom(updateReadyAtom) const [updateAvailableState] = useAtom(updateAvailableAtom) @@ -93,7 +93,7 @@ export function About() { const versionLabel = info.version ?? '' // Update will be downloaded automatically because autoDownload is enabled in main process - toast.success(t('about.notifications.updateAvailable', { version: versionLabel })) + toast.success(i18n.t('about.notifications.updateAvailable', { version: versionLabel })) setLatestVersionState({ status: 'available', version: versionLabel @@ -127,7 +127,7 @@ export function About() { ipcEvents.removeListener('update:download-progress', handleUpdateDownloadProgress) ipcEvents.removeListener('update:downloaded', handleUpdateDownloaded) } - }, [setUpdateAvailable, t]) + }, [i18n, setUpdateAvailable]) const handleSettingChange = async ( key: keyof typeof settings,