Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions web-app/src/hooks/__tests__/useAppUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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) => {
Expand Down
10 changes: 10 additions & 0 deletions web-app/src/hooks/useAppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@

const checkForUpdate = useCallback(
async (resetRemindMeLater = false) => {
if (AUTO_UPDATER_DISABLED) {
console.log('Auto updater is disabled')
return
}

Check warning on line 59 in web-app/src/hooks/useAppUpdater.ts

View workflow job for this annotation

GitHub Actions / coverage-check

57-59 lines are not covered with tests

try {
// Reset remindMeLater if requested (e.g., when called from settings)
if (resetRemindMeLater) {
Expand Down Expand Up @@ -148,6 +153,11 @@
)

const downloadAndInstallUpdate = useCallback(async () => {
if (AUTO_UPDATER_DISABLED) {
console.log('Auto updater is disabled')
return
}

Check warning on line 159 in web-app/src/hooks/useAppUpdater.ts

View workflow job for this annotation

GitHub Actions / coverage-check

157-159 lines are not covered with tests

if (!updateState.updateInfo) return

try {
Expand Down
42 changes: 22 additions & 20 deletions web-app/src/routes/settings/general.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@

const openFileTitle = (): string => {
if (IS_MACOS) {
return t('settings:general.showInFinder')

Check warning on line 71 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

71 line is not covered with tests
} else if (IS_WINDOWS) {
return t('settings:general.showInFileExplorer')
} else {
return t('settings:general.openContainingFolder')
}

Check warning on line 76 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

75-76 lines are not covered with tests
}
const { checkForUpdate } = useAppUpdater()
const { pausePolling } = useHardware()
Expand All @@ -93,10 +93,10 @@
}, [])

const resetApp = async () => {
pausePolling()

Check warning on line 96 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

96 line is not covered with tests
// TODO: Loading indicator
await factoryReset()
}

Check warning on line 99 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

98-99 lines are not covered with tests

const handleOpenLogs = async () => {
try {
Expand All @@ -107,8 +107,8 @@

if (existingWindow) {
// If window exists, focus it
await existingWindow.setFocus()
console.log('Focused existing logs window')

Check warning on line 111 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

110-111 lines are not covered with tests
} else {
// Create a new logs window using Tauri v2 WebviewWindow API
const logsWindow = new WebviewWindow(windowKey.logsAppWindow, {
Expand All @@ -122,17 +122,17 @@

// Listen for window creation
logsWindow.once('tauri://created', () => {
console.log('Logs window created')

Check warning on line 125 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

125 line is not covered with tests
})

// Listen for window errors
logsWindow.once('tauri://error', (e) => {
console.error('Error creating logs window:', e)

Check warning on line 130 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

130 line is not covered with tests
})
}
} catch (error) {
console.error('Failed to open logs window:', error)
}

Check warning on line 135 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

134-135 lines are not covered with tests
}

const copyToClipboard = async (text: string) => {
Expand Down Expand Up @@ -260,26 +260,28 @@
</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 />}
Expand Down
Loading