Compare commits
No commits in common. "00cde6e8c5699ede1603537906e519f07d95ec45" and "4501f9936f28b16601dec7289cf9ae482d8aee83" have entirely different histories.
00cde6e8c5
...
4501f9936f
@ -4,7 +4,6 @@ import { Button, Flex, Modal, Progress, Typography, theme } from 'antd'
|
||||
|
||||
import CloudIcon from '../../../Icons/CloudIcon'
|
||||
import HostIcon from '../../../Icons/HostIcon'
|
||||
import ReloadIcon from '../../../Icons/ReloadIcon'
|
||||
|
||||
import CheckCircleIcon from '../../../Icons/CheckCircleIcon'
|
||||
import XMarkCircleIcon from '../../../Icons/XMarkCircleIcon'
|
||||
@ -46,15 +45,6 @@ const STAGE_CONFIG = {
|
||||
complete: 'Installed',
|
||||
error: 'Install failed'
|
||||
}
|
||||
},
|
||||
restart: {
|
||||
icon: ReloadIcon,
|
||||
labels: {
|
||||
pending: 'Restart',
|
||||
active: 'Restarting...',
|
||||
complete: 'Restarted',
|
||||
error: 'Restart failed'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,25 +62,20 @@ const getDownloadStageStatus = (phase, isError) => {
|
||||
return 'pending'
|
||||
}
|
||||
|
||||
const isInstallComplete = (phase, message) =>
|
||||
phase === 'installing' &&
|
||||
String(message || '')
|
||||
.toLowerCase()
|
||||
.includes('complete')
|
||||
|
||||
const getInstallStageStatus = (phase, isError, message) => {
|
||||
if (isError && ['downloaded', 'installing'].includes(phase)) return 'error'
|
||||
if (isInstallComplete(phase, message)) return 'complete'
|
||||
if (
|
||||
phase === 'installing' &&
|
||||
String(message || '')
|
||||
.toLowerCase()
|
||||
.includes('complete')
|
||||
) {
|
||||
return 'complete'
|
||||
}
|
||||
if (phase === 'installing') return 'active'
|
||||
return 'pending'
|
||||
}
|
||||
|
||||
const getRestartStageStatus = (phase, isError, message) => {
|
||||
if (isError && isInstallComplete(phase, message)) return 'error'
|
||||
if (isInstallComplete(phase, message)) return 'active'
|
||||
return 'pending'
|
||||
}
|
||||
|
||||
const getProgressStatus = (stageStatus) => {
|
||||
if (stageStatus === 'error') return 'exception'
|
||||
if (stageStatus === 'complete') return 'success'
|
||||
@ -116,19 +101,25 @@ const UpdateStage = ({ stage, status, percent, detail }) => {
|
||||
: StageIcon
|
||||
|
||||
return (
|
||||
<Flex align='start' gap='middle' style={{ width: '100%' }}>
|
||||
<StatusIcon style={{ fontSize: 22, color, flexShrink: 0 }} />
|
||||
<Flex align='start' gap='24px' style={{ flex: 1, minWidth: 0 }}>
|
||||
<Text style={{ flexShrink: 0 }}>{config.labels[resolvedStatus]}</Text>
|
||||
<Flex align='center' gap='middle'>
|
||||
<StatusIcon style={{ fontSize: 20, color, flexShrink: 0 }} />
|
||||
<Flex align='center' gap='small' style={{ flex: 1, minWidth: 0 }}>
|
||||
<Text style={{ flexShrink: 0, minWidth: 96 }}>
|
||||
{config.labels[resolvedStatus]}
|
||||
</Text>
|
||||
{showProgress && (
|
||||
<Flex vertical gap={2} style={{ flex: 1 }}>
|
||||
<Flex vertical gap={4}>
|
||||
<Progress
|
||||
percent={resolvedPercent}
|
||||
status={getProgressStatus(resolvedStatus)}
|
||||
showInfo={typeof resolvedPercent === 'number'}
|
||||
style={{ flex: 1, margin: 0 }}
|
||||
/>
|
||||
{detail && <Text type='secondary'>{detail}</Text>}
|
||||
{detail && (
|
||||
<Text type='secondary' style={{ marginLeft: 36 }}>
|
||||
{detail}
|
||||
</Text>
|
||||
)}
|
||||
</Flex>
|
||||
)}
|
||||
</Flex>
|
||||
@ -137,7 +128,7 @@ const UpdateStage = ({ stage, status, percent, detail }) => {
|
||||
}
|
||||
|
||||
UpdateStage.propTypes = {
|
||||
stage: PropTypes.oneOf(['download', 'install', 'restart']).isRequired,
|
||||
stage: PropTypes.oneOf(['download', 'install']).isRequired,
|
||||
status: PropTypes.oneOf(['pending', 'active', 'complete', 'error'])
|
||||
.isRequired,
|
||||
percent: PropTypes.number,
|
||||
@ -159,7 +150,6 @@ const AppUpdateProgress = ({ progress, update, onClose }) => {
|
||||
|
||||
const downloadStatus = getDownloadStageStatus(phase, isError)
|
||||
const installStatus = getInstallStageStatus(phase, isError, message)
|
||||
const restartStatus = getRestartStageStatus(phase, isError, message)
|
||||
|
||||
const downloadPercent =
|
||||
downloadStatus === 'active' ? (phase === 'preparing' ? 0 : percent) : null
|
||||
@ -173,8 +163,6 @@ const AppUpdateProgress = ({ progress, update, onClose }) => {
|
||||
|
||||
const installDetail = installStatus === 'active' ? message : null
|
||||
|
||||
const restartDetail = restartStatus === 'active' ? message : null
|
||||
|
||||
return (
|
||||
<Flex vertical gap='middle'>
|
||||
<Text>
|
||||
@ -197,11 +185,6 @@ const AppUpdateProgress = ({ progress, update, onClose }) => {
|
||||
percent={installPercent}
|
||||
detail={installDetail}
|
||||
/>
|
||||
<UpdateStage
|
||||
stage='restart'
|
||||
status={restartStatus}
|
||||
detail={restartDetail}
|
||||
/>
|
||||
</Flex>
|
||||
|
||||
<Modal
|
||||
|
||||
@ -21,42 +21,6 @@ const { Text } = Typography
|
||||
const UPDATE_CHECK_INTERVAL_MS = 5 * 60 * 1000
|
||||
const DEFAULT_UPDATE_BRANCH = 'main'
|
||||
const CURRENT_BUILD_NUMBER = import.meta.env.VITE_BUILD_NUMBER
|
||||
const APP_UPDATE_DISMISSED_KEY = 'appUpdateDismissed'
|
||||
|
||||
const getDismissedUpdate = () => {
|
||||
try {
|
||||
const stored = sessionStorage.getItem(APP_UPDATE_DISMISSED_KEY)
|
||||
return stored ? JSON.parse(stored) : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const isUpdateDismissed = (update) => {
|
||||
if (!update) return false
|
||||
|
||||
const dismissed = getDismissedUpdate()
|
||||
if (!dismissed) return false
|
||||
|
||||
return (
|
||||
dismissed.version === update.version &&
|
||||
dismissed.buildNumber === update.buildNumber &&
|
||||
dismissed.branch === update.branch
|
||||
)
|
||||
}
|
||||
|
||||
const saveDismissedUpdate = (update) => {
|
||||
if (!update) return
|
||||
|
||||
sessionStorage.setItem(
|
||||
APP_UPDATE_DISMISSED_KEY,
|
||||
JSON.stringify({
|
||||
version: update.version,
|
||||
buildNumber: update.buildNumber,
|
||||
branch: update.branch
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const AppUpdateContext = createContext()
|
||||
|
||||
@ -113,7 +77,6 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
const [checking, setChecking] = useState(false)
|
||||
const [noUpdateOpen, setNoUpdateOpen] = useState(false)
|
||||
const [availableUpdate, setAvailableUpdate] = useState(null)
|
||||
const [updatePromptOpen, setUpdatePromptOpen] = useState(false)
|
||||
const [installingUpdate, setInstallingUpdate] = useState(null)
|
||||
const [updateProgress, setUpdateProgress] = useState(null)
|
||||
const runningCheckRef = useRef(null)
|
||||
@ -173,20 +136,14 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
}
|
||||
}, [])
|
||||
|
||||
const showUpdateIfAvailable = useCallback(
|
||||
async ({ forcePrompt = false } = {}) => {
|
||||
const update = await checkForAvailableUpdate()
|
||||
if (update) {
|
||||
setNoUpdateOpen(false)
|
||||
setAvailableUpdate(update)
|
||||
if (forcePrompt || !isUpdateDismissed(update)) {
|
||||
setUpdatePromptOpen(true)
|
||||
}
|
||||
}
|
||||
return update
|
||||
},
|
||||
[checkForAvailableUpdate]
|
||||
)
|
||||
const showUpdateIfAvailable = useCallback(async () => {
|
||||
const update = await checkForAvailableUpdate()
|
||||
if (update) {
|
||||
setNoUpdateOpen(false)
|
||||
setAvailableUpdate(update)
|
||||
}
|
||||
return update
|
||||
}, [checkForAvailableUpdate])
|
||||
|
||||
const checkForUpdates = useCallback(async () => {
|
||||
if (!isElectron) return null
|
||||
@ -194,7 +151,7 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
setChecking(true)
|
||||
|
||||
try {
|
||||
const update = await showUpdateIfAvailable({ forcePrompt: true })
|
||||
const update = await showUpdateIfAvailable()
|
||||
if (!update) {
|
||||
setNoUpdateOpen(true)
|
||||
}
|
||||
@ -226,22 +183,15 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
})
|
||||
}, [isElectron, onAppUpdateProgress])
|
||||
|
||||
const dismissUpdatePrompt = () => {
|
||||
if (availableUpdate) {
|
||||
saveDismissedUpdate(availableUpdate)
|
||||
}
|
||||
setUpdatePromptOpen(false)
|
||||
}
|
||||
|
||||
const closeUpdateModal = () => {
|
||||
setUpdatePromptOpen(false)
|
||||
setAvailableUpdate(null)
|
||||
setInstallingUpdate(null)
|
||||
setUpdateProgress(null)
|
||||
}
|
||||
|
||||
const handleUpdate = async (update) => {
|
||||
setNoUpdateOpen(false)
|
||||
setUpdatePromptOpen(false)
|
||||
setAvailableUpdate(null)
|
||||
setInstallingUpdate(update)
|
||||
setModelWidth(550)
|
||||
setUpdateProgress({
|
||||
@ -265,7 +215,7 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const updateModalOpen = Boolean(updatePromptOpen || installingUpdate)
|
||||
const updateModalOpen = Boolean(availableUpdate || installingUpdate)
|
||||
const updateModalBusy =
|
||||
Boolean(installingUpdate) && updateProgress?.phase !== 'error'
|
||||
|
||||
@ -318,13 +268,7 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
centered
|
||||
closable={!updateModalBusy}
|
||||
maskClosable={!updateModalBusy}
|
||||
onCancel={
|
||||
updateModalBusy
|
||||
? undefined
|
||||
: installingUpdate
|
||||
? closeUpdateModal
|
||||
: dismissUpdatePrompt
|
||||
}
|
||||
onCancel={updateModalBusy ? undefined : closeUpdateModal}
|
||||
>
|
||||
{installingUpdate ? (
|
||||
<AppUpdateProgress
|
||||
@ -335,7 +279,7 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
) : (
|
||||
<NewAppUpdate
|
||||
update={availableUpdate}
|
||||
onCancel={dismissUpdatePrompt}
|
||||
onCancel={closeUpdateModal}
|
||||
onUpdate={handleUpdate}
|
||||
/>
|
||||
)}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user