Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

refactor: reduce check for update attempts

Louisb63aeb565cca
diff --git a/web-app/src/containers/dialogs/AppUpdater.tsx b/web-app/src/containers/dialogs/AppUpdater.tsx
index 1638c6e13..f076cae4a 100644
--- a/web-app/src/containers/dialogs/AppUpdater.tsx
+++ b/web-app/src/containers/dialogs/AppUpdater.tsx
@@ -12,12 +12,8 @@ import { useTranslation } from '@/i18n/react-i18next-compat'
const DialogAppUpdater = () => {
const { t } = useTranslation()
- const {
- updateState,
- downloadAndInstallUpdate,
- checkForUpdate,
- setRemindMeLater,
- } = useAppUpdater()
+ const { updateState, downloadAndInstallUpdate, setRemindMeLater } =
+ useAppUpdater()
const [showReleaseNotes, setShowReleaseNotes] = useState(false)
const handleUpdate = () => {
@@ -33,11 +29,6 @@ const DialogAppUpdater = () => {
}
}, [fetchLatestRelease])
- // Check for updates when component mounts
- useEffect(() => {
- checkForUpdate()
- }, [checkForUpdate])
-
const [appUpdateState, setAppUpdateState] = useState({
remindMeLater: false,
isUpdateAvailable: false,
diff --git a/web-app/src/hooks/useAppUpdater.ts b/web-app/src/hooks/useAppUpdater.ts
index 892ebe26e..f5ee22b78 100644
--- a/web-app/src/hooks/useAppUpdater.ts
+++ b/web-app/src/hooks/useAppUpdater.ts
@@ -5,9 +5,6 @@ import type { UpdateInfo } from '@/services/updater/types'
import { SystemEvent } from '@/types/events'
import { getServiceHub } from '@/hooks/useServiceHub'
-// Check for updates every hour
-const UPDATE_CHECK_INTERVAL_MS = 60 * 60 * 1000
-
export interface UpdateState {
isUpdateAvailable: boolean
updateInfo: UpdateInfo | null
@@ -60,6 +57,8 @@ export const useAppUpdater = () => {
return
}
+ console.log('Checking for updates...')
+
try {
// Reset remindMeLater if requested (e.g., when called from settings)
if (resetRemindMeLater) {
@@ -240,24 +239,6 @@ export const useAppUpdater = () => {
}
}, [updateState.updateInfo])
- // Set up periodic update checking (every hour)
- useEffect(() => {
- // Skip periodic checks if updater is disabled or in dev mode
- if (AUTO_UPDATER_DISABLED || isDev()) {
- return
- }
-
- // Set up periodic update checks
- const intervalId = setInterval(() => {
- console.log('Periodic update check triggered')
- checkForUpdate()
- }, UPDATE_CHECK_INTERVAL_MS)
-
- // Cleanup interval on unmount
- return () => {
- clearInterval(intervalId)
- }
- }, [checkForUpdate])
return {
updateState,
diff --git a/web-app/src/providers/DataProvider.tsx b/web-app/src/providers/DataProvider.tsx
index efa9d210e..43fba4839 100644
--- a/web-app/src/providers/DataProvider.tsx
+++ b/web-app/src/providers/DataProvider.tsx
@@ -13,6 +13,7 @@ import { useAppState } from '@/hooks/useAppState'
import { AppEvent, events } from '@janhq/core'
import { SystemEvent } from '@/types/events'
import { getModelToStart } from '@/utils/getModelToStart'
+import { isDev } from '@/lib/utils'
export function DataProvider() {
const { setProviders, selectedModel, selectedProvider, getProviderByName } =
@@ -93,13 +94,27 @@ export function DataProvider() {
})
}, [serviceHub, setThreads])
- // Check for app updates
+ // Check for app updates - initial check and periodic interval
useEffect(() => {
// Only check for updates if the auto updater is not disabled
// App might be distributed via other package managers
// or methods that handle updates differently
- if (!AUTO_UPDATER_DISABLED) {
+ if (AUTO_UPDATER_DISABLED || isDev()) {
+ return
+ }
+
+ // Initial check on mount
+ checkForUpdate()
+
+ // Set up periodic update checks (singleton - only runs in DataProvider)
+ const intervalId = setInterval(() => {
+ console.log('Periodic update check triggered')
checkForUpdate()
+ }, Number(UPDATE_CHECK_INTERVAL_MS))
+
+ // Cleanup interval on unmount
+ return () => {
+ clearInterval(intervalId)
}
}, [checkForUpdate])
diff --git a/web-app/src/types/global.d.ts b/web-app/src/types/global.d.ts
index c22539146..c94104fb1 100644
--- a/web-app/src/types/global.d.ts
+++ b/web-app/src/types/global.d.ts
@@ -21,6 +21,7 @@ declare global {
declare const POSTHOG_HOST: string
declare const MODEL_CATALOG_URL: string
declare const AUTO_UPDATER_DISABLED: boolean
+ declare const UPDATE_CHECK_INTERVAL_MS: number
declare const GA_MEASUREMENT_ID: string
declare const IS_DEV: boolean
interface Window {
diff --git a/web-app/vite.config.ts b/web-app/vite.config.ts
index 6f8321c2e..103956eb1 100644
--- a/web-app/vite.config.ts
+++ b/web-app/vite.config.ts
@@ -99,6 +99,9 @@ export default defineConfig(({ mode }) => {
AUTO_UPDATER_DISABLED: JSON.stringify(
env.AUTO_UPDATER_DISABLED === 'true'
),
+ UPDATE_CHECK_INTERVAL_MS: JSON.stringify(
+ Number(env.UPDATE_CHECK_INTERVAL_MS) || 60 * 60 * 1000
+ ),
},
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`