fix: app updater state (#5171)
This commit is contained in:
parent
b0d3d485cf
commit
aeba895250
@ -9,7 +9,8 @@ import { RenderMarkdown } from '../RenderMarkdown'
|
||||
import { isDev } from '@/lib/utils'
|
||||
|
||||
const DialogAppUpdater = () => {
|
||||
const { updateState, downloadAndInstallUpdate } = useAppUpdater()
|
||||
const { updateState, downloadAndInstallUpdate, checkForUpdate } =
|
||||
useAppUpdater()
|
||||
const [showReleaseNotes, setShowReleaseNotes] = useState(false)
|
||||
const [remindMeLater, setRemindMeLater] = useState(false)
|
||||
|
||||
@ -29,6 +30,11 @@ const DialogAppUpdater = () => {
|
||||
}
|
||||
}, [beta, fetchLatestRelease])
|
||||
|
||||
// Check for updates when component mounts
|
||||
useEffect(() => {
|
||||
checkForUpdate()
|
||||
}, [checkForUpdate])
|
||||
|
||||
if (remindMeLater) return null
|
||||
|
||||
return (
|
||||
|
||||
@ -24,19 +24,36 @@ export const useAppUpdater = () => {
|
||||
const checkForUpdate = useCallback(async () => {
|
||||
try {
|
||||
if (!isDev()) {
|
||||
// Production mode - use actual Tauri updater
|
||||
const update = await check()
|
||||
|
||||
if (update) {
|
||||
setUpdateState((prev) => ({
|
||||
...prev,
|
||||
isUpdateAvailable: true,
|
||||
updateInfo: update,
|
||||
}))
|
||||
console.log('Update available:', update.version)
|
||||
return update
|
||||
} else {
|
||||
// No update available - reset state
|
||||
setUpdateState((prev) => ({
|
||||
...prev,
|
||||
isUpdateAvailable: false,
|
||||
updateInfo: null,
|
||||
}))
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
} catch (error) {
|
||||
console.error('Error checking for updates:', error)
|
||||
// Reset state on error
|
||||
setUpdateState((prev) => ({
|
||||
...prev,
|
||||
isUpdateAvailable: false,
|
||||
updateInfo: null,
|
||||
}))
|
||||
return null
|
||||
}
|
||||
}, [])
|
||||
|
||||
@ -56,8 +56,7 @@ export function DataProvider() {
|
||||
// Check for app updates
|
||||
useEffect(() => {
|
||||
checkForUpdate()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
}, [checkForUpdate])
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ import {
|
||||
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
|
||||
import { windowKey } from '@/constants/windows'
|
||||
import { toast } from 'sonner'
|
||||
import { isDev } from '@/lib/utils'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const Route = createFileRoute(route.settings.general as any)({
|
||||
@ -167,9 +168,11 @@ function General() {
|
||||
const handleCheckForUpdate = async () => {
|
||||
setIsCheckingUpdate(true)
|
||||
try {
|
||||
if (isDev())
|
||||
return toast.info('You are running a development version of Jan!')
|
||||
const update = await checkForUpdate()
|
||||
if (!update) {
|
||||
toast.success('You are using the latest version of Jan!')
|
||||
toast.info('You are using the latest version of Jan!')
|
||||
}
|
||||
// If update is available, the AppUpdater dialog will automatically show
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user