Skip to content

Commit 6ac3d6d

Browse files
Minh141120louis-jan
authored andcommitted
Merge pull request #6175 from menloresearch/fix/feature-toggle-auto-updater
fix: feature toggle auto updater
1 parent 25e3787 commit 6ac3d6d

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

web-app/src/hooks/__tests__/useAppUpdater.test.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Object.defineProperty(window, 'core', {
4848
writable: true,
4949
})
5050

51+
// Mock global AUTO_UPDATER_DISABLED
52+
Object.defineProperty(global, 'AUTO_UPDATER_DISABLED', {
53+
value: false,
54+
writable: true,
55+
})
56+
5157
import { isDev } from '@/lib/utils'
5258
import { check } from '@tauri-apps/plugin-updater'
5359
import { events } from '@janhq/core'
@@ -251,11 +257,14 @@ describe('useAppUpdater', () => {
251257
downloadAndInstall: mockDownloadAndInstall,
252258
}
253259

260+
// Mock check to return the update
261+
mockCheck.mockResolvedValue(mockUpdate)
262+
254263
const { result } = renderHook(() => useAppUpdater())
255264

256-
// Set update info first
257-
act(() => {
258-
result.current.updateState.updateInfo = mockUpdate
265+
// Set update info first by calling checkForUpdate
266+
await act(async () => {
267+
await result.current.checkForUpdate()
259268
})
260269

261270
// Mock the download and install process
@@ -296,11 +305,14 @@ describe('useAppUpdater', () => {
296305
downloadAndInstall: mockDownloadAndInstall,
297306
}
298307

308+
// Mock check to return the update
309+
mockCheck.mockResolvedValue(mockUpdate)
310+
299311
const { result } = renderHook(() => useAppUpdater())
300312

301-
// Set update info first
302-
act(() => {
303-
result.current.updateState.updateInfo = mockUpdate
313+
// Set update info first by calling checkForUpdate
314+
await act(async () => {
315+
await result.current.checkForUpdate()
304316
})
305317

306318
mockDownloadAndInstall.mockRejectedValue(new Error('Download failed'))
@@ -338,11 +350,14 @@ describe('useAppUpdater', () => {
338350
downloadAndInstall: mockDownloadAndInstall,
339351
}
340352

353+
// Mock check to return the update
354+
mockCheck.mockResolvedValue(mockUpdate)
355+
341356
const { result } = renderHook(() => useAppUpdater())
342357

343-
// Set update info first
344-
act(() => {
345-
result.current.updateState.updateInfo = mockUpdate
358+
// Set update info first by calling checkForUpdate
359+
await act(async () => {
360+
await result.current.checkForUpdate()
346361
})
347362

348363
mockDownloadAndInstall.mockImplementation(async (progressCallback) => {

web-app/src/hooks/useAppUpdater.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export const useAppUpdater = () => {
5353

5454
const checkForUpdate = useCallback(
5555
async (resetRemindMeLater = false) => {
56+
if (AUTO_UPDATER_DISABLED) {
57+
console.log('Auto updater is disabled')
58+
return
59+
}
60+
5661
try {
5762
// Reset remindMeLater if requested (e.g., when called from settings)
5863
if (resetRemindMeLater) {
@@ -148,6 +153,11 @@ export const useAppUpdater = () => {
148153
)
149154

150155
const downloadAndInstallUpdate = useCallback(async () => {
156+
if (AUTO_UPDATER_DISABLED) {
157+
console.log('Auto updater is disabled')
158+
return
159+
}
160+
151161
if (!updateState.updateInfo) return
152162

153163
try {

web-app/src/routes/settings/general.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -260,26 +260,28 @@ function General() {
260260
</span>
261261
}
262262
/>
263-
<CardItem
264-
title={t('settings:general.checkForUpdates')}
265-
description={t('settings:general.checkForUpdatesDesc')}
266-
className="flex-col sm:flex-row items-start sm:items-center sm:justify-between gap-y-2"
267-
actions={
268-
<Button
269-
variant="link"
270-
size="sm"
271-
className="p-0"
272-
onClick={handleCheckForUpdate}
273-
disabled={isCheckingUpdate}
274-
>
275-
<div className="cursor-pointer rounded-sm hover:bg-main-view-fg/15 bg-main-view-fg/10 transition-all duration-200 ease-in-out px-2 py-1 gap-1">
276-
{isCheckingUpdate
277-
? t('settings:general.checkingForUpdates')
278-
: t('settings:general.checkForUpdates')}
279-
</div>
280-
</Button>
281-
}
282-
/>
263+
{!AUTO_UPDATER_DISABLED && (
264+
<CardItem
265+
title={t('settings:general.checkForUpdates')}
266+
description={t('settings:general.checkForUpdatesDesc')}
267+
className="flex-col sm:flex-row items-start sm:items-center sm:justify-between gap-y-2"
268+
actions={
269+
<Button
270+
variant="link"
271+
size="sm"
272+
className="p-0"
273+
onClick={handleCheckForUpdate}
274+
disabled={isCheckingUpdate}
275+
>
276+
<div className="cursor-pointer rounded-sm hover:bg-main-view-fg/15 bg-main-view-fg/10 transition-all duration-200 ease-in-out px-2 py-1 gap-1">
277+
{isCheckingUpdate
278+
? t('settings:general.checkingForUpdates')
279+
: t('settings:general.checkForUpdates')}
280+
</div>
281+
</Button>
282+
}
283+
/>
284+
)}
283285
{/* <CardItem
284286
title={t('common:language')}
285287
actions={<LanguageSwitcher />}

0 commit comments

Comments
 (0)