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