fix: should not download when autoupdate is false (#5029)

This commit is contained in:
fullex 2025-04-18 16:28:20 +08:00 committed by GitHub
parent 73f8148a94
commit fd3d9f17b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 33 additions and 9 deletions

View File

@ -13,6 +13,7 @@ export enum IpcChannel {
App_RestartTray = 'app:restart-tray',
App_SetTheme = 'app:set-theme',
App_SetCustomCss = 'app:set-custom-css',
App_SetAutoUpdate = 'app:set-auto-update',
App_IsBinaryExist = 'app:is-binary-exist',
App_GetBinaryPath = 'app:get-binary-path',

View File

@ -100,6 +100,11 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
configManager.setTrayOnClose(isActive)
})
// auto update
ipcMain.handle(IpcChannel.App_SetAutoUpdate, (_, isActive: boolean) => {
configManager.setAutoUpdate(isActive)
})
ipcMain.handle(IpcChannel.App_RestartTray, () => TrayService.getInstance().restartTray())
ipcMain.handle(IpcChannel.Config_Set, (_, key: string, value: any) => {

View File

@ -5,6 +5,7 @@ import logger from 'electron-log'
import { AppUpdater as _AppUpdater, autoUpdater } from 'electron-updater'
import icon from '../../../build/icon.png?asset'
import { configManager } from './ConfigManager'
export default class AppUpdater {
autoUpdater: _AppUpdater = autoUpdater
@ -15,7 +16,8 @@ export default class AppUpdater {
autoUpdater.logger = logger
autoUpdater.forceDevUpdateConfig = !app.isPackaged
autoUpdater.autoDownload = true
autoUpdater.autoDownload = configManager.getAutoUpdate()
autoUpdater.autoInstallOnAppQuit = configManager.getAutoUpdate()
// 检测下载错误
autoUpdater.on('error', (error) => {

View File

@ -14,7 +14,8 @@ enum ConfigKeys {
ZoomFactor = 'ZoomFactor',
Shortcuts = 'shortcuts',
ClickTrayToShowQuickAssistant = 'clickTrayToShowQuickAssistant',
EnableQuickAssistant = 'enableQuickAssistant'
EnableQuickAssistant = 'enableQuickAssistant',
AutoUpdate = 'autoUpdate'
}
export class ConfigManager {
@ -136,6 +137,14 @@ export class ConfigManager {
this.set(ConfigKeys.EnableQuickAssistant, value)
}
getAutoUpdate(): boolean {
return this.get<boolean>(ConfigKeys.AutoUpdate, true)
}
setAutoUpdate(value: boolean) {
this.set(ConfigKeys.AutoUpdate, value)
}
set(key: string, value: unknown) {
this.store.set(key, value)
}

View File

@ -30,6 +30,7 @@ declare global {
restartTray: () => void
setTheme: (theme: 'light' | 'dark') => void
setCustomCss: (css: string) => void
setAutoUpdate: (isActive: boolean) => void
reload: () => void
clearCache: () => Promise<{ success: boolean; error?: string }>
system: {

View File

@ -20,6 +20,7 @@ const api = {
restartTray: () => ipcRenderer.invoke(IpcChannel.App_RestartTray),
setTheme: (theme: 'light' | 'dark') => ipcRenderer.invoke(IpcChannel.App_SetTheme, theme),
setCustomCss: (css: string) => ipcRenderer.invoke(IpcChannel.App_SetCustomCss, css),
setAutoUpdate: (isActive: boolean) => ipcRenderer.invoke(IpcChannel.App_SetAutoUpdate, isActive),
openWebsite: (url: string) => ipcRenderer.invoke(IpcChannel.Open_Website, url),
clearCache: () => ipcRenderer.invoke(IpcChannel.App_ClearCache),
system: {

View File

@ -3,6 +3,7 @@ import {
AssistantIconType,
SendMessageShortcut,
setAssistantIconType,
setAutoCheckUpdate as _setAutoCheckUpdate,
setLaunchOnBoot,
setLaunchToTray,
setSendMessageShortcut as _setSendMessageShortcut,
@ -50,6 +51,11 @@ export function useSettings() {
}
},
setAutoCheckUpdate(isAutoUpdate: boolean) {
dispatch(_setAutoCheckUpdate(isAutoUpdate))
window.api.setAutoUpdate(isAutoUpdate)
},
setTheme(theme: ThemeMode) {
dispatch(setTheme(theme))
},

View File

@ -1029,7 +1029,7 @@
"general.display.title": "Display Settings",
"general.emoji_picker": "Emoji Picker",
"general.image_upload": "Image Upload",
"general.auto_check_update.title": "Auto update checking",
"general.auto_check_update.title": "Auto Update",
"general.reset.button": "Reset",
"general.reset.title": "Data Reset",
"general.restore.button": "Restore",

View File

@ -1364,7 +1364,7 @@
"content_limit": "内容の長さ制限",
"content_limit_tooltip": "検索結果の内容長を制限し、制限を超える内容は切り捨てられます。"
},
"general.auto_check_update.title": "自動更新チェックを有効にする",
"general.auto_check_update.title": "自動更新",
"quickPhrase": {
"title": "クイックフレーズ",
"add": "フレーズを追加",

View File

@ -1029,7 +1029,7 @@
"general.display.title": "显示设置",
"general.emoji_picker": "表情选择器",
"general.image_upload": "图片上传",
"general.auto_check_update.title": "自动检测更新",
"general.auto_check_update.title": "自动更新",
"general.reset.button": "重置",
"general.reset.title": "重置数据",
"general.restore.button": "恢复",

View File

@ -1364,7 +1364,7 @@
"content_limit": "內容長度限制",
"content_limit_tooltip": "限制搜尋結果的內容長度,超過限制的內容將被截斷。"
},
"general.auto_check_update.title": "啟用自動更新檢查",
"general.auto_check_update.title": "啟用自動更新",
"quickPhrase": {
"title": "快捷短語",
"add": "新增短語",

View File

@ -8,7 +8,6 @@ import { useRuntime } from '@renderer/hooks/useRuntime'
import { useSettings } from '@renderer/hooks/useSettings'
import { useAppDispatch } from '@renderer/store'
import { setUpdateState } from '@renderer/store/runtime'
import { setAutoCheckUpdate } from '@renderer/store/settings'
import { ThemeMode } from '@renderer/types'
import { compareVersions, runAsyncFunction } from '@renderer/utils'
import { Avatar, Button, Progress, Row, Switch, Tag } from 'antd'
@ -25,7 +24,7 @@ import { SettingContainer, SettingDivider, SettingGroup, SettingRow, SettingTitl
const AboutSettings: FC = () => {
const [version, setVersion] = useState('')
const { t } = useTranslation()
const { autoCheckUpdate } = useSettings()
const { autoCheckUpdate, setAutoCheckUpdate } = useSettings()
const { theme } = useTheme()
const dispatch = useAppDispatch()
const { update } = useRuntime()
@ -150,7 +149,7 @@ const AboutSettings: FC = () => {
<SettingDivider />
<SettingRow>
<SettingRowTitle>{t('settings.general.auto_check_update.title')}</SettingRowTitle>
<Switch value={autoCheckUpdate} onChange={(v) => dispatch(setAutoCheckUpdate(v))} />
<Switch value={autoCheckUpdate} onChange={(v) => setAutoCheckUpdate(v)} />
</SettingRow>
</SettingGroup>
{hasNewVersion && update.info && (