From 4350d4c9a0221bba3609ca3a33488a007303d432 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 14 Aug 2025 09:58:46 +0700 Subject: [PATCH 1/3] fix: feature toggle for auto updater --- web-app/src/routes/settings/general.tsx | 42 +++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/web-app/src/routes/settings/general.tsx b/web-app/src/routes/settings/general.tsx index ab19deccf9..3ee558ae7b 100644 --- a/web-app/src/routes/settings/general.tsx +++ b/web-app/src/routes/settings/general.tsx @@ -260,26 +260,28 @@ function General() { } /> - -
- {isCheckingUpdate - ? t('settings:general.checkingForUpdates') - : t('settings:general.checkForUpdates')} -
- - } - /> + {!AUTO_UPDATER_DISABLED && ( + +
+ {isCheckingUpdate + ? t('settings:general.checkingForUpdates') + : t('settings:general.checkForUpdates')} +
+ + } + /> + )} {/* } From 388959a1fedf8a14b472749b30a23a789cc71578 Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Thu, 14 Aug 2025 12:39:48 +0700 Subject: [PATCH 2/3] chore: gate check auto updater --- web-app/src/hooks/useAppUpdater.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web-app/src/hooks/useAppUpdater.ts b/web-app/src/hooks/useAppUpdater.ts index fb24c66004..303cb43e3d 100644 --- a/web-app/src/hooks/useAppUpdater.ts +++ b/web-app/src/hooks/useAppUpdater.ts @@ -53,6 +53,11 @@ export const useAppUpdater = () => { const checkForUpdate = useCallback( async (resetRemindMeLater = false) => { + if (AUTO_UPDATER_DISABLED) { + console.log('Auto updater is disabled') + return + } + try { // Reset remindMeLater if requested (e.g., when called from settings) if (resetRemindMeLater) { @@ -148,6 +153,11 @@ export const useAppUpdater = () => { ) const downloadAndInstallUpdate = useCallback(async () => { + if (AUTO_UPDATER_DISABLED) { + console.log('Auto updater is disabled') + return + } + if (!updateState.updateInfo) return try { From dcb46174ff03b9a3380079eefb452a8428c2e7e2 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 14 Aug 2025 14:30:43 +0700 Subject: [PATCH 3/3] fix: test --- .../src/hooks/__tests__/useAppUpdater.test.ts | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/web-app/src/hooks/__tests__/useAppUpdater.test.ts b/web-app/src/hooks/__tests__/useAppUpdater.test.ts index 250c37fed2..2c736f0f3e 100644 --- a/web-app/src/hooks/__tests__/useAppUpdater.test.ts +++ b/web-app/src/hooks/__tests__/useAppUpdater.test.ts @@ -48,6 +48,12 @@ Object.defineProperty(window, 'core', { writable: true, }) +// Mock global AUTO_UPDATER_DISABLED +Object.defineProperty(global, 'AUTO_UPDATER_DISABLED', { + value: false, + writable: true, +}) + import { isDev } from '@/lib/utils' import { check } from '@tauri-apps/plugin-updater' import { events } from '@janhq/core' @@ -251,11 +257,14 @@ describe('useAppUpdater', () => { downloadAndInstall: mockDownloadAndInstall, } + // Mock check to return the update + mockCheck.mockResolvedValue(mockUpdate) + const { result } = renderHook(() => useAppUpdater()) - // Set update info first - act(() => { - result.current.updateState.updateInfo = mockUpdate + // Set update info first by calling checkForUpdate + await act(async () => { + await result.current.checkForUpdate() }) // Mock the download and install process @@ -296,11 +305,14 @@ describe('useAppUpdater', () => { downloadAndInstall: mockDownloadAndInstall, } + // Mock check to return the update + mockCheck.mockResolvedValue(mockUpdate) + const { result } = renderHook(() => useAppUpdater()) - // Set update info first - act(() => { - result.current.updateState.updateInfo = mockUpdate + // Set update info first by calling checkForUpdate + await act(async () => { + await result.current.checkForUpdate() }) mockDownloadAndInstall.mockRejectedValue(new Error('Download failed')) @@ -338,11 +350,14 @@ describe('useAppUpdater', () => { downloadAndInstall: mockDownloadAndInstall, } + // Mock check to return the update + mockCheck.mockResolvedValue(mockUpdate) + const { result } = renderHook(() => useAppUpdater()) - // Set update info first - act(() => { - result.current.updateState.updateInfo = mockUpdate + // Set update info first by calling checkForUpdate + await act(async () => { + await result.current.checkForUpdate() }) mockDownloadAndInstall.mockImplementation(async (progressCallback) => {