fix(AppUpdater): simplify error logging and update version check logic (#8656)

* fix(AppUpdater): simplify error logging and update version check logic

- Updated error logging to use a more concise format.
- Changed logging messages for update events to be more consistent.
- Modified the update check logic to return null when no update is available.
- Enhanced the app initialization hook to include update availability in the state dispatch.

* fix(useAppInit): simplify update state dispatch logic by removing update availability check
This commit is contained in:
beyondkmp 2025-07-30 11:59:41 +08:00 committed by GitHub
parent 73b010af00
commit bee933dd72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 13 deletions

View File

@ -31,17 +31,12 @@ export default class AppUpdater {
} }
autoUpdater.on('error', (error) => { autoUpdater.on('error', (error) => {
// 简单记录错误信息和时间戳 logger.error('update error', error as Error)
logger.error('更新异常', {
message: error.message,
stack: error.stack,
time: new Date().toISOString()
})
mainWindow.webContents.send(IpcChannel.UpdateError, error) mainWindow.webContents.send(IpcChannel.UpdateError, error)
}) })
autoUpdater.on('update-available', (releaseInfo: UpdateInfo) => { autoUpdater.on('update-available', (releaseInfo: UpdateInfo) => {
logger.info('检测到新版本', releaseInfo) logger.info('update available', releaseInfo)
mainWindow.webContents.send(IpcChannel.UpdateAvailable, releaseInfo) mainWindow.webContents.send(IpcChannel.UpdateAvailable, releaseInfo)
}) })
@ -65,7 +60,7 @@ export default class AppUpdater {
autoUpdater.on('update-downloaded', (releaseInfo: UpdateInfo) => { autoUpdater.on('update-downloaded', (releaseInfo: UpdateInfo) => {
mainWindow.webContents.send(IpcChannel.UpdateDownloaded, releaseInfo) mainWindow.webContents.send(IpcChannel.UpdateDownloaded, releaseInfo)
this.releaseInfo = releaseInfo this.releaseInfo = releaseInfo
logger.info('下载完成', releaseInfo) logger.info('update downloaded', releaseInfo)
}) })
if (isWin) { if (isWin) {
@ -242,7 +237,7 @@ export default class AppUpdater {
return { return {
currentVersion: this.autoUpdater.currentVersion, currentVersion: this.autoUpdater.currentVersion,
updateInfo: this.updateCheckResult?.updateInfo updateInfo: this.updateCheckResult?.isUpdateAvailable ? this.updateCheckResult?.updateInfo : null
} }
} catch (error) { } catch (error) {
logger.error('Failed to check for update:', error as Error) logger.error('Failed to check for update:', error as Error)

View File

@ -96,9 +96,6 @@ const AboutSettings: FC = () => {
}) })
} }
// don't support downgrade, so we only check if the version is different
const hasNewVersion = update?.info?.version && version ? update.info.version !== version : false
const currentChannelByVersion = const currentChannelByVersion =
[ [
{ pattern: `-${UpgradeChannel.BETA}.`, channel: UpgradeChannel.BETA }, { pattern: `-${UpgradeChannel.BETA}.`, channel: UpgradeChannel.BETA },
@ -267,7 +264,7 @@ const AboutSettings: FC = () => {
</> </>
)} )}
</SettingGroup> </SettingGroup>
{hasNewVersion && update.info && ( {update.info && update.available && (
<SettingGroup theme={theme}> <SettingGroup theme={theme}>
<SettingRow> <SettingRow>
<SettingRowTitle> <SettingRowTitle>