Merge pull request #6175 from menloresearch/fix/feature-toggle-auto-updater

fix: feature toggle auto updater
This commit is contained in:
Nguyen Ngoc Minh 2025-08-14 15:27:07 +07:00 committed by Louis
parent 25e3787677
commit 6ac3d6de26
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
3 changed files with 56 additions and 29 deletions

View File

@ -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) => {

View File

@ -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 {

View File

@ -260,26 +260,28 @@ function General() {
</span>
}
/>
<CardItem
title={t('settings:general.checkForUpdates')}
description={t('settings:general.checkForUpdatesDesc')}
className="flex-col sm:flex-row items-start sm:items-center sm:justify-between gap-y-2"
actions={
<Button
variant="link"
size="sm"
className="p-0"
onClick={handleCheckForUpdate}
disabled={isCheckingUpdate}
>
<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">
{isCheckingUpdate
? t('settings:general.checkingForUpdates')
: t('settings:general.checkForUpdates')}
</div>
</Button>
}
/>
{!AUTO_UPDATER_DISABLED && (
<CardItem
title={t('settings:general.checkForUpdates')}
description={t('settings:general.checkForUpdatesDesc')}
className="flex-col sm:flex-row items-start sm:items-center sm:justify-between gap-y-2"
actions={
<Button
variant="link"
size="sm"
className="p-0"
onClick={handleCheckForUpdate}
disabled={isCheckingUpdate}
>
<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">
{isCheckingUpdate
? t('settings:general.checkingForUpdates')
: t('settings:general.checkForUpdates')}
</div>
</Button>
}
/>
)}
{/* <CardItem
title={t('common:language')}
actions={<LanguageSwitcher />}