feat(app-update): Refactor update handling and add manual update dialog

- Modify AppUpdater to separate update dialog logic
- Add new IPC handler for manually showing update dialog
- Update renderer hooks and store to track downloaded update state
- Switch import for UpdateInfo from electron-updater to builder-util-runtime
This commit is contained in:
kangfenmao
2025-03-05 14:33:10 +08:00
parent b14c161f23
commit bdf883dcbf
14 changed files with 114 additions and 36 deletions
+9 -3
View File
@@ -1,6 +1,6 @@
import { useAppDispatch } from '@renderer/store'
import { setUpdateState } from '@renderer/store/runtime'
import type { ProgressInfo, UpdateInfo } from 'electron-updater'
import type { ProgressInfo, UpdateInfo } from 'builder-util-runtime'
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
@@ -46,8 +46,14 @@ export default function useUpdateHandler() {
})
)
}),
ipcRenderer.on('update-downloaded', () => {
dispatch(setUpdateState({ downloading: false }))
ipcRenderer.on('update-downloaded', (_, releaseInfo: UpdateInfo) => {
dispatch(
setUpdateState({
downloading: false,
info: releaseInfo,
downloaded: true
})
)
}),
ipcRenderer.on('update-error', (_, error) => {
dispatch(
+2 -1
View File
@@ -68,7 +68,8 @@
"collapse": "Collapse",
"manage": "Manage",
"select_model": "Select Model",
"show.all": "Show All"
"show.all": "Show All",
"update_available": "Update Available"
},
"chat": {
"add.assistant.title": "Add Assistant",
+2 -1
View File
@@ -68,7 +68,8 @@
"collapse": "折りたたむ",
"manage": "管理",
"select_model": "モデルを選択",
"show.all": "すべて表示"
"show.all": "すべて表示",
"update_available": "更新可能"
},
"chat": {
"add.assistant.title": "アシスタントを追加",
+2 -1
View File
@@ -68,7 +68,8 @@
"collapse": "Свернуть",
"manage": "Редактировать",
"select_model": "Выбрать модель",
"show.all": "Показать все"
"show.all": "Показать все",
"update_available": "Доступно обновление"
},
"chat": {
"add.assistant.title": "Добавить ассистента",
+2 -1
View File
@@ -68,7 +68,8 @@
"collapse": "收起",
"manage": "管理",
"select_model": "选择模型",
"show.all": "显示全部"
"show.all": "显示全部",
"update_available": "有可用更新"
},
"chat": {
"add.assistant.title": "添加助手",
+2 -1
View File
@@ -68,7 +68,8 @@
"collapse": "收起",
"manage": "管理",
"select_model": "選擇模型",
"show.all": "顯示全部"
"show.all": "顯示全部",
"update_available": "有可用更新"
},
"chat": {
"add.assistant.title": "添加助手",
+2
View File
@@ -18,6 +18,7 @@ import { FC } from 'react'
import styled from 'styled-components'
import SelectModelButton from './components/SelectModelButton'
import UpdateAppButton from './components/UpdateAppButton'
interface Props {
activeAssistant: Assistant
@@ -83,6 +84,7 @@ const HeaderNavbar: FC<Props> = ({ activeAssistant }) => {
<SelectModelButton assistant={assistant} />
</HStack>
<HStack alignItems="center" gap={8}>
<UpdateAppButton />
<NarrowIcon onClick={() => SearchPopup.show()}>
<SearchOutlined />
</NarrowIcon>
@@ -0,0 +1,45 @@
import { SyncOutlined } from '@ant-design/icons'
import { useRuntime } from '@renderer/hooks/useRuntime'
import { Button } from 'antd'
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'
const UpdateAppButton: FC = () => {
const { update } = useRuntime()
const { t } = useTranslation()
if (!update) {
return null
}
if (!update.downloaded) {
return null
}
return (
<Container>
<UpdateButton
className="nodrag"
onClick={() => window.api.showUpdateDialog()}
icon={<SyncOutlined />}
color="orange"
variant="outlined"
size="small">
{t('button.update_available')}
</UpdateButton>
</Container>
)
}
const Container = styled.div``
const UpdateButton = styled(Button)`
border-radius: 24px;
font-size: 12px;
@media (max-width: 1000px) {
display: none;
}
`
export default UpdateAppButton
@@ -36,6 +36,11 @@ const AboutSettings: FC = () => {
return
}
if (update.downloaded) {
window.api.showUpdateDialog()
return
}
dispatch(setUpdateState({ checking: true }))
try {
+3 -1
View File
@@ -1,11 +1,12 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { AppLogo, UserAvatar } from '@renderer/config/env'
import type { UpdateInfo } from 'electron-updater'
import type { UpdateInfo } from 'builder-util-runtime'
export interface UpdateState {
info: UpdateInfo | null
checking: boolean
downloading: boolean
downloaded: boolean
downloadProgress: number
available: boolean
}
@@ -43,6 +44,7 @@ const initialState: RuntimeState = {
info: null,
checking: false,
downloading: false,
downloaded: false,
downloadProgress: 0,
available: false
},