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