Skip to content

Commit cab9955

Browse files
authored
Merge branch 'main' into fix/responsive-changes-editor
2 parents 6b7ca2c + 52e53e1 commit cab9955

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

apps/desktop/src/updater.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import { gt, valid } from 'semver'
88
const { autoUpdater } = electronUpdater
99
const UPDATE_SETTINGS_FILE = 'update-settings.json'
1010
const UPDATES_UNAVAILABLE_MESSAGE = 'Updates are not available for this build'
11+
/**
12+
* electron-updater's default channel. Its `channel` setter rejects `null` once a
13+
* channel has been set, so switching back to stable must name the channel
14+
* explicitly instead of clearing it.
15+
*/
16+
const STABLE_UPDATER_CHANNEL = 'latest'
1117
const INITIAL_CHECK_DELAY_MS = 10_000
1218
const CHECK_INTERVAL_MS = 4 * 60 * 60 * 1_000
1319
const RELEASE_REPOSITORY_PATH = '/PyModel/pythinker-desktop-releases/releases/tag/'
@@ -258,7 +264,7 @@ function hasUpdateConfig(): boolean {
258264
function configureExplicitConsent(): void {
259265
autoUpdater.autoDownload = false
260266
autoUpdater.autoInstallOnAppQuit = false
261-
autoUpdater.channel = settings.channel === 'stable' ? null : settings.channel
267+
autoUpdater.channel = settings.channel === 'stable' ? STABLE_UPDATER_CHANNEL : settings.channel
262268
autoUpdater.allowPrerelease = settings.channel !== 'stable'
263269
autoUpdater.allowDowngrade = false
264270
}

apps/desktop/tests/updater.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ vi.mock('electron', () => ({
1515
vi.mock('electron-updater', () => ({
1616
default: {
1717
autoUpdater: {
18+
_channel: null as string | null,
19+
get channel(): string | null {
20+
return this._channel
21+
},
22+
set channel(value: string | null) {
23+
if (this._channel !== null) {
24+
if (typeof value !== 'string') throw new Error(`Channel must be a string, but got: ${String(value)}`)
25+
if (value.length === 0) throw new Error('Channel must be not an empty string')
26+
}
27+
this._channel = value
28+
},
1829
on: vi.fn(),
1930
checkForUpdates: vi.fn(),
2031
downloadUpdate: vi.fn(() => Promise.resolve([])),
@@ -58,7 +69,7 @@ afterEach(() => {
5869
autoUpdater.autoInstallOnAppQuit = undefined as unknown as boolean
5970
autoUpdater.allowPrerelease = undefined as unknown as boolean
6071
autoUpdater.allowDowngrade = undefined as unknown as boolean
61-
autoUpdater.channel = null
72+
;(autoUpdater as unknown as { _channel: string | null })._channel = null
6273
})
6374

6475
function temporaryDirectory(): string {
@@ -225,7 +236,7 @@ describe('strict update consent', () => {
225236
expect(setLocalUpdateChannel('nightly')).toMatchObject({ channel: 'nightly', status: 'idle' })
226237
expect(setLocalNotifyUpdate(false)).toMatchObject({ notifyUpdate: false })
227238
expect(setLocalUpdateChannel('stable')).toMatchObject({ channel: 'stable', status: 'idle' })
228-
expect(localAutoUpdater.channel).toBeNull()
239+
expect(localAutoUpdater.channel).toBe('latest')
229240
expect(localAutoUpdater.allowPrerelease).toBe(false)
230241
expect(localAutoUpdater.allowDowngrade).toBe(false)
231242
expect(localAutoUpdater.autoDownload).toBe(false)

0 commit comments

Comments
 (0)