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.

fix(updater): bind requestIdleCallback to window to avoid Illegal invocation

Akarshan Biswase949bcb79127
diff --git a/extensions/llamacpp-extension/src/index.ts b/extensions/llamacpp-extension/src/index.ts
index 678ffce7f..af72e31bd 100644
--- a/extensions/llamacpp-extension/src/index.ts
+++ b/extensions/llamacpp-extension/src/index.ts
@@ -1196,8 +1196,8 @@ export default class llamacpp_extension extends AIEngine {
// Advisory and fail-soft — defer to browser idle so it yields to the
// router (already up by now) and the UI instead of running inline.
const verify = () => void this.verifyBackendDeps(backend, version)
- const ric = window.requestIdleCallback
- if (ric) ric(verify, { timeout: 3000 })
+ if (typeof window.requestIdleCallback === 'function')
+ window.requestIdleCallback(verify, { timeout: 3000 })
else setTimeout(verify, 0)
}
}
diff --git a/web-app/src/containers/dialogs/BackendUpdater.tsx b/web-app/src/containers/dialogs/BackendUpdater.tsx
index bb23f4f55..05655541c 100644
--- a/web-app/src/containers/dialogs/BackendUpdater.tsx
+++ b/web-app/src/containers/dialogs/BackendUpdater.tsx
@@ -35,12 +35,12 @@ const BackendUpdater = () => {
// doesn't compete with the initial render.
useEffect(() => {
if (!updateState.autoUpdateEnabled) return
- const ric = window.requestIdleCallback
- const idleHandle = ric
- ? ric(() => checkForUpdate(), { timeout: 3000 })
+ const hasRic = typeof window.requestIdleCallback === 'function'
+ const idleHandle = hasRic
+ ? window.requestIdleCallback(() => checkForUpdate(), { timeout: 3000 })
: window.setTimeout(() => checkForUpdate(), 0)
return () => {
- if (ric) window.cancelIdleCallback(idleHandle as number)
+ if (hasRic) window.cancelIdleCallback(idleHandle as number)
else window.clearTimeout(idleHandle as number)
}
}, [checkForUpdate, isLlamacppEnabled, updateState.autoUpdateEnabled])
diff --git a/web-app/src/providers/DataProvider.tsx b/web-app/src/providers/DataProvider.tsx
index 390c42ac9..4d32b1bdc 100644
--- a/web-app/src/providers/DataProvider.tsx
+++ b/web-app/src/providers/DataProvider.tsx
@@ -200,9 +200,9 @@ export function DataProvider() {
// Defer the initial check until the browser is idle (after first paint) so
// the network round-trip and any resulting dialog don't compete with the
// initial render.
- const ric = window.requestIdleCallback
- const idleHandle = ric
- ? ric(() => checkForUpdate(), { timeout: 3000 })
+ const hasRic = typeof window.requestIdleCallback === 'function'
+ const idleHandle = hasRic
+ ? window.requestIdleCallback(() => checkForUpdate(), { timeout: 3000 })
: window.setTimeout(() => checkForUpdate(), 0)
// Set up periodic update checks (singleton - only runs in DataProvider)
@@ -213,7 +213,7 @@ export function DataProvider() {
// Cleanup interval on unmount
return () => {
- if (ric) window.cancelIdleCallback(idleHandle as number)
+ if (hasRic) window.cancelIdleCallback(idleHandle as number)
else window.clearTimeout(idleHandle as number)
clearInterval(intervalId)
}