Implement update dismissal functionality in AppUpdateContext to enhance user experience during updates. Added methods to save and check dismissed updates, and modified update prompt logic to respect user preferences. Update modal behavior adjusted to incorporate dismissal actions.
This commit is contained in:
parent
4501f9936f
commit
65cc2cd8b5
@ -21,6 +21,42 @@ 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()
|
||||||
|
|
||||||
@ -77,6 +113,7 @@ 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)
|
||||||
@ -136,14 +173,20 @@ export const AppUpdateProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const showUpdateIfAvailable = useCallback(async () => {
|
const showUpdateIfAvailable = useCallback(
|
||||||
const update = await checkForAvailableUpdate()
|
async ({ forcePrompt = false } = {}) => {
|
||||||
if (update) {
|
const update = await checkForAvailableUpdate()
|
||||||
setNoUpdateOpen(false)
|
if (update) {
|
||||||
setAvailableUpdate(update)
|
setNoUpdateOpen(false)
|
||||||
}
|
setAvailableUpdate(update)
|
||||||
return update
|
if (forcePrompt || !isUpdateDismissed(update)) {
|
||||||
}, [checkForAvailableUpdate])
|
setUpdatePromptOpen(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return update
|
||||||
|
},
|
||||||
|
[checkForAvailableUpdate]
|
||||||
|
)
|
||||||
|
|
||||||
const checkForUpdates = useCallback(async () => {
|
const checkForUpdates = useCallback(async () => {
|
||||||
if (!isElectron) return null
|
if (!isElectron) return null
|
||||||
@ -151,7 +194,7 @@ export const AppUpdateProvider = ({ children }) => {
|
|||||||
setChecking(true)
|
setChecking(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const update = await showUpdateIfAvailable()
|
const update = await showUpdateIfAvailable({ forcePrompt: true })
|
||||||
if (!update) {
|
if (!update) {
|
||||||
setNoUpdateOpen(true)
|
setNoUpdateOpen(true)
|
||||||
}
|
}
|
||||||
@ -183,15 +226,22 @@ export const AppUpdateProvider = ({ children }) => {
|
|||||||
})
|
})
|
||||||
}, [isElectron, onAppUpdateProgress])
|
}, [isElectron, onAppUpdateProgress])
|
||||||
|
|
||||||
|
const dismissUpdatePrompt = () => {
|
||||||
|
if (availableUpdate) {
|
||||||
|
saveDismissedUpdate(availableUpdate)
|
||||||
|
}
|
||||||
|
setUpdatePromptOpen(false)
|
||||||
|
}
|
||||||
|
|
||||||
const closeUpdateModal = () => {
|
const closeUpdateModal = () => {
|
||||||
setAvailableUpdate(null)
|
setUpdatePromptOpen(false)
|
||||||
setInstallingUpdate(null)
|
setInstallingUpdate(null)
|
||||||
setUpdateProgress(null)
|
setUpdateProgress(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleUpdate = async (update) => {
|
const handleUpdate = async (update) => {
|
||||||
setNoUpdateOpen(false)
|
setNoUpdateOpen(false)
|
||||||
setAvailableUpdate(null)
|
setUpdatePromptOpen(false)
|
||||||
setInstallingUpdate(update)
|
setInstallingUpdate(update)
|
||||||
setModelWidth(550)
|
setModelWidth(550)
|
||||||
setUpdateProgress({
|
setUpdateProgress({
|
||||||
@ -215,7 +265,7 @@ export const AppUpdateProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateModalOpen = Boolean(availableUpdate || installingUpdate)
|
const updateModalOpen = Boolean(updatePromptOpen || installingUpdate)
|
||||||
const updateModalBusy =
|
const updateModalBusy =
|
||||||
Boolean(installingUpdate) && updateProgress?.phase !== 'error'
|
Boolean(installingUpdate) && updateProgress?.phase !== 'error'
|
||||||
|
|
||||||
@ -268,7 +318,13 @@ export const AppUpdateProvider = ({ children }) => {
|
|||||||
centered
|
centered
|
||||||
closable={!updateModalBusy}
|
closable={!updateModalBusy}
|
||||||
maskClosable={!updateModalBusy}
|
maskClosable={!updateModalBusy}
|
||||||
onCancel={updateModalBusy ? undefined : closeUpdateModal}
|
onCancel={
|
||||||
|
updateModalBusy
|
||||||
|
? undefined
|
||||||
|
: installingUpdate
|
||||||
|
? closeUpdateModal
|
||||||
|
: dismissUpdatePrompt
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{installingUpdate ? (
|
{installingUpdate ? (
|
||||||
<AppUpdateProgress
|
<AppUpdateProgress
|
||||||
@ -279,7 +335,7 @@ export const AppUpdateProvider = ({ children }) => {
|
|||||||
) : (
|
) : (
|
||||||
<NewAppUpdate
|
<NewAppUpdate
|
||||||
update={availableUpdate}
|
update={availableUpdate}
|
||||||
onCancel={closeUpdateModal}
|
onCancel={dismissUpdatePrompt}
|
||||||
onUpdate={handleUpdate}
|
onUpdate={handleUpdate}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user