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
8 changes: 7 additions & 1 deletion apps/desktop/src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { gt, valid } from 'semver'
const { autoUpdater } = electronUpdater
const UPDATE_SETTINGS_FILE = 'update-settings.json'
const UPDATES_UNAVAILABLE_MESSAGE = 'Updates are not available for this build'
/**
* electron-updater's default channel. Its `channel` setter rejects `null` once a
* channel has been set, so switching back to stable must name the channel
* explicitly instead of clearing it.
*/
const STABLE_UPDATER_CHANNEL = 'latest'
const INITIAL_CHECK_DELAY_MS = 10_000
const CHECK_INTERVAL_MS = 4 * 60 * 60 * 1_000
const RELEASE_REPOSITORY_PATH = '/PyModel/pythinker-desktop-releases/releases/tag/'
Expand Down Expand Up @@ -258,7 +264,7 @@ function hasUpdateConfig(): boolean {
function configureExplicitConsent(): void {
autoUpdater.autoDownload = false
autoUpdater.autoInstallOnAppQuit = false
autoUpdater.channel = settings.channel === 'stable' ? null : settings.channel
autoUpdater.channel = settings.channel === 'stable' ? STABLE_UPDATER_CHANNEL : settings.channel
autoUpdater.allowPrerelease = settings.channel !== 'stable'
autoUpdater.allowDowngrade = false
}
Expand Down
15 changes: 13 additions & 2 deletions apps/desktop/tests/updater.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ vi.mock('electron', () => ({
vi.mock('electron-updater', () => ({
default: {
autoUpdater: {
_channel: null as string | null,
get channel(): string | null {
return this._channel
},
set channel(value: string | null) {
if (this._channel !== null) {
if (typeof value !== 'string') throw new Error(`Channel must be a string, but got: ${String(value)}`)
if (value.length === 0) throw new Error('Channel must be not an empty string')
}
this._channel = value
},
on: vi.fn(),
checkForUpdates: vi.fn(),
downloadUpdate: vi.fn(() => Promise.resolve([])),
Expand Down Expand Up @@ -58,7 +69,7 @@ afterEach(() => {
autoUpdater.autoInstallOnAppQuit = undefined as unknown as boolean
autoUpdater.allowPrerelease = undefined as unknown as boolean
autoUpdater.allowDowngrade = undefined as unknown as boolean
autoUpdater.channel = null
;(autoUpdater as unknown as { _channel: string | null })._channel = null
})

function temporaryDirectory(): string {
Expand Down Expand Up @@ -225,7 +236,7 @@ describe('strict update consent', () => {
expect(setLocalUpdateChannel('nightly')).toMatchObject({ channel: 'nightly', status: 'idle' })
expect(setLocalNotifyUpdate(false)).toMatchObject({ notifyUpdate: false })
expect(setLocalUpdateChannel('stable')).toMatchObject({ channel: 'stable', status: 'idle' })
expect(localAutoUpdater.channel).toBeNull()
expect(localAutoUpdater.channel).toBe('latest')
expect(localAutoUpdater.allowPrerelease).toBe(false)
expect(localAutoUpdater.allowDowngrade).toBe(false)
expect(localAutoUpdater.autoDownload).toBe(false)
Expand Down
Loading