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 GitHub
commit b9d6aec0e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 29 deletions

View File

@ -48,6 +48,12 @@ Object.defineProperty(window, 'core', {
writable: true, writable: true,
}) })
// Mock global AUTO_UPDATER_DISABLED
Object.defineProperty(global, 'AUTO_UPDATER_DISABLED', {
value: false,
writable: true,
})
import { isDev } from '@/lib/utils' import { isDev } from '@/lib/utils'
import { check } from '@tauri-apps/plugin-updater' import { check } from '@tauri-apps/plugin-updater'
import { events } from '@janhq/core' import { events } from '@janhq/core'
@ -251,11 +257,14 @@ describe('useAppUpdater', () => {
downloadAndInstall: mockDownloadAndInstall, downloadAndInstall: mockDownloadAndInstall,
} }
// Mock check to return the update
mockCheck.mockResolvedValue(mockUpdate)
const { result } = renderHook(() => useAppUpdater()) const { result } = renderHook(() => useAppUpdater())
// Set update info first // Set update info first by calling checkForUpdate
act(() => { await act(async () => {
result.current.updateState.updateInfo = mockUpdate await result.current.checkForUpdate()
}) })
// Mock the download and install process // Mock the download and install process
@ -296,11 +305,14 @@ describe('useAppUpdater', () => {
downloadAndInstall: mockDownloadAndInstall, downloadAndInstall: mockDownloadAndInstall,
} }
// Mock check to return the update
mockCheck.mockResolvedValue(mockUpdate)
const { result } = renderHook(() => useAppUpdater()) const { result } = renderHook(() => useAppUpdater())
// Set update info first // Set update info first by calling checkForUpdate
act(() => { await act(async () => {
result.current.updateState.updateInfo = mockUpdate await result.current.checkForUpdate()
}) })
mockDownloadAndInstall.mockRejectedValue(new Error('Download failed')) mockDownloadAndInstall.mockRejectedValue(new Error('Download failed'))
@ -338,11 +350,14 @@ describe('useAppUpdater', () => {
downloadAndInstall: mockDownloadAndInstall, downloadAndInstall: mockDownloadAndInstall,
} }
// Mock check to return the update
mockCheck.mockResolvedValue(mockUpdate)
const { result } = renderHook(() => useAppUpdater()) const { result } = renderHook(() => useAppUpdater())
// Set update info first // Set update info first by calling checkForUpdate
act(() => { await act(async () => {
result.current.updateState.updateInfo = mockUpdate await result.current.checkForUpdate()
}) })
mockDownloadAndInstall.mockImplementation(async (progressCallback) => { mockDownloadAndInstall.mockImplementation(async (progressCallback) => {

View File

@ -53,6 +53,11 @@ export const useAppUpdater = () => {
const checkForUpdate = useCallback( const checkForUpdate = useCallback(
async (resetRemindMeLater = false) => { async (resetRemindMeLater = false) => {
if (AUTO_UPDATER_DISABLED) {
console.log('Auto updater is disabled')
return
}
try { try {
// Reset remindMeLater if requested (e.g., when called from settings) // Reset remindMeLater if requested (e.g., when called from settings)
if (resetRemindMeLater) { if (resetRemindMeLater) {
@ -148,6 +153,11 @@ export const useAppUpdater = () => {
) )
const downloadAndInstallUpdate = useCallback(async () => { const downloadAndInstallUpdate = useCallback(async () => {
if (AUTO_UPDATER_DISABLED) {
console.log('Auto updater is disabled')
return
}
if (!updateState.updateInfo) return if (!updateState.updateInfo) return
try { try {

View File

@ -260,6 +260,7 @@ function General() {
</span> </span>
} }
/> />
{!AUTO_UPDATER_DISABLED && (
<CardItem <CardItem
title={t('settings:general.checkForUpdates')} title={t('settings:general.checkForUpdates')}
description={t('settings:general.checkForUpdatesDesc')} description={t('settings:general.checkForUpdatesDesc')}
@ -280,6 +281,7 @@ function General() {
</Button> </Button>
} }
/> />
)}
{/* <CardItem {/* <CardItem
title={t('common:language')} title={t('common:language')}
actions={<LanguageSwitcher />} actions={<LanguageSwitcher />}