Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix: app updater does not remind for new update without restarting
Louis11685a509d29
diff --git a/web-app/src/containers/SetupScreen.tsx b/web-app/src/containers/SetupScreen.tsxindex 54cecd02c..740496d80 100644--- a/web-app/src/containers/SetupScreen.tsx+++ b/web-app/src/containers/SetupScreen.tsx@@ -14,8 +14,9 @@ import {} from '@/constants/models'import { toast } from 'sonner'import { Button } from '@/components/ui/button'-import { IconEye, IconSquareCheck} from '@tabler/icons-react'+import { IconEye, IconSquareCheck } from '@tabler/icons-react'import { cn } from '@/lib/utils'+import { useGeneralSetting } from '@/hooks/useGeneralSetting'type CacheEntry = {status: 'RED' | 'YELLOW' | 'GREEN' | 'GREY'@@ -103,7 +104,7 @@ function SetupScreen() {try {const repo = await serviceHub.models()- .fetchHuggingFaceRepo(NEW_JAN_MODEL_HF_REPO)+ .fetchHuggingFaceRepo(NEW_JAN_MODEL_HF_REPO, huggingfaceToken)if (repo) {const catalogModel = serviceHub@@ -263,7 +264,9 @@ function SetupScreen() {const downloadedSize = useMemo(() => {if (!defaultVariant) return { current: 0, total: 0 }- const process = downloadProcesses.find((e) => e.id === defaultVariant.model_id)+ const process = downloadProcesses.find(+ (e) => e.id === defaultVariant.model_id+ )return {current: process?.current || 0,total: process?.total || 0,@@ -283,6 +286,8 @@ function SetupScreen() {)}, [defaultVariant, llamaProvider])+ const huggingfaceToken = useGeneralSetting((state) => state.huggingfaceToken)+const handleQuickStart = useCallback(() => {// If metadata is still loading, queue the downloadif (!defaultVariant || !janNewModel || !isSupportCheckComplete) {@@ -301,7 +306,7 @@ function SetupScreen() {(e) => e.model_id.toLowerCase() === 'mmproj-f16') || janNewModel.mmproj_models?.[0])?.path,- undefined, // No HF token needed for public model+ huggingfaceToken, // Use HF token from general settingstrue // Skip verification for faster download)}, [@@ -310,6 +315,7 @@ function SetupScreen() {isSupportCheckComplete,addLocalDownloadingModel,serviceHub,+ huggingfaceToken,])// Process queued quick start when metadata becomes availablediff --git a/web-app/src/hooks/__tests__/useAppUpdater.test.ts b/web-app/src/hooks/__tests__/useAppUpdater.test.tsindex fd1a41482..5e550ce2f 100644--- a/web-app/src/hooks/__tests__/useAppUpdater.test.ts+++ b/web-app/src/hooks/__tests__/useAppUpdater.test.ts@@ -264,6 +264,114 @@ describe('useAppUpdater', () => {})})+ describe('periodic update checking', () => {+ beforeEach(() => {+ vi.useFakeTimers()+ })++ afterEach(() => {+ vi.useRealTimers()+ })++ it('should set up periodic update check interval', async () => {+ const mockUpdate = {+ version: '1.2.0',+ downloadAndInstall: vi.fn(),+ }+ mockUpdaterCheck.mockResolvedValue(mockUpdate)++ const { result } = renderHook(() => useAppUpdater())++ // Initial check happens immediately in DataProvider, not here+ expect(mockUpdaterCheck).not.toHaveBeenCalled()++ // Fast-forward 1 hour+ await act(async () => {+ vi.advanceTimersByTime(60 * 60 * 1000)+ await Promise.resolve() // Allow pending promises to resolve+ })++ expect(mockUpdaterCheck).toHaveBeenCalledTimes(1)+ })++ it('should clean up periodic interval on unmount', () => {+ const { unmount } = renderHook(() => useAppUpdater())++ const clearIntervalSpy = vi.spyOn(global, 'clearInterval')++ unmount()++ expect(clearIntervalSpy).toHaveBeenCalled()+ })++ it('should not set up periodic check if AUTO_UPDATER_DISABLED is true', async () => {+ Object.defineProperty(global, 'AUTO_UPDATER_DISABLED', {+ value: true,+ writable: true,+ })++ const { result } = renderHook(() => useAppUpdater())++ await act(async () => {+ vi.advanceTimersByTime(60 * 60 * 1000)+ await vi.runAllTimersAsync()+ })++ expect(mockUpdaterCheck).not.toHaveBeenCalled()++ // Reset+ Object.defineProperty(global, 'AUTO_UPDATER_DISABLED', {+ value: false,+ writable: true,+ })+ })++ it('should not set up periodic check in dev mode', async () => {+ mockIsDev.mockReturnValue(true)++ const { result } = renderHook(() => useAppUpdater())++ await act(async () => {+ vi.advanceTimersByTime(60 * 60 * 1000)+ await vi.runAllTimersAsync()+ })++ expect(mockUpdaterCheck).not.toHaveBeenCalled()++ mockIsDev.mockReturnValue(false)+ })++ it('should trigger multiple checks over multiple hours', async () => {+ mockUpdaterCheck.mockResolvedValue(null)++ const { result } = renderHook(() => useAppUpdater())++ // First hour+ await act(async () => {+ vi.advanceTimersByTime(60 * 60 * 1000)+ await Promise.resolve()+ })++ expect(mockUpdaterCheck).toHaveBeenCalledTimes(1)++ // Second hour+ await act(async () => {+ vi.advanceTimersByTime(60 * 60 * 1000)+ await Promise.resolve()+ })++ expect(mockUpdaterCheck).toHaveBeenCalledTimes(2)++ // Third hour+ await act(async () => {+ vi.advanceTimersByTime(60 * 60 * 1000)+ await Promise.resolve()+ })++ expect(mockUpdaterCheck).toHaveBeenCalledTimes(3)+ })+ })+describe('downloadAndInstallUpdate', () => {it('should download and install update successfully', async () => {const mockDownloadAndInstall = vi.fn()diff --git a/web-app/src/hooks/useAppUpdater.ts b/web-app/src/hooks/useAppUpdater.tsindex 3e6a4b9b9..892ebe26e 100644--- a/web-app/src/hooks/useAppUpdater.ts+++ b/web-app/src/hooks/useAppUpdater.ts@@ -5,6 +5,9 @@ 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: booleanupdateInfo: UpdateInfo | null@@ -237,6 +240,25 @@ 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,checkForUpdate,