Skip to content

The agent that grows with you

fix(desktop): channel selector only where it can save, shows the choice at once, and never calls a custom branch main

Tekniuma7b2ba02e3b9
diff --git a/apps/desktop/electron/updater/index.ts b/apps/desktop/electron/updater/index.ts
index 291f9525aa3..bcab529ae71 100644
--- a/apps/desktop/electron/updater/index.ts
+++ b/apps/desktop/electron/updater/index.ts
@@ -60,6 +60,8 @@ export interface UpdaterStatusWire {
currentSha?: string
currentVersion?: string
channel?: string
+ /** source_check can persist a channel; runtimes older than the selector cannot. */
+ channelSelectable?: boolean
retirement?: ChannelRetirementStatus
latestTag?: string | null
targetSha?: string
diff --git a/apps/desktop/src/app/settings/about-settings.test.tsx b/apps/desktop/src/app/settings/about-settings.test.tsx
index a54c260f7af..f09c24a9431 100644
--- a/apps/desktop/src/app/settings/about-settings.test.tsx
+++ b/apps/desktop/src/app/settings/about-settings.test.tsx
@@ -126,7 +126,13 @@ describe('AboutSettings', (): void => {
it('lets a source checkout pick its channel and confirms the move to stable releases', async (): Promise<void> => {
const about = en.settings.about.channel
- $updateStatus.set({ supported: true, behind: 0, mechanism: 'posix-handoff', branch: 'main' })
+ const source = { supported: true, behind: 0, mechanism: 'posix-handoff', channelSelectable: true } as const
+ // The save resolves only when released, so the in-flight paint is observable.
+ let release!: () => void
+ vi.mocked(setUpdateChannel).mockImplementationOnce(
+ () => new Promise(resolve => (release = () => resolve({ ...source, channel: 'stable' })))
+ )
+ $updateStatus.set({ ...source, branch: 'main' })
render(<AboutSettings />)
expect(screen.getByRole('button', { name: about.main }).getAttribute('aria-pressed')).toBe('true')
@@ -139,9 +145,12 @@ describe('AboutSettings', (): void => {
await waitFor((): void => {
expect(setUpdateChannel).toHaveBeenCalledWith('stable')
})
+ // The confirmed choice shows while the save + check is still running.
+ expect(screen.getByRole('button', { name: about.stable }).getAttribute('aria-pressed')).toBe('true')
+ release()
// Back to every commit is never older code, so it needs no confirmation.
- $updateStatus.set({ supported: true, behind: 0, mechanism: 'posix-handoff', channel: 'stable' })
+ $updateStatus.set({ ...source, channel: 'stable' })
await waitFor((): void => {
expect(screen.getByRole('button', { name: about.stable }).getAttribute('aria-pressed')).toBe('true')
})
@@ -151,11 +160,13 @@ describe('AboutSettings', (): void => {
})
expect($confirmRequest.get()).toBeNull()
- // Packaged installs own their channel.
- $updateStatus.set({ supported: true, behind: 0, mechanism: 'electron-updater', channel: 'stable' })
+ // An older runtime cannot save a channel, and a packaged install owns its own.
+ $updateStatus.set({ ...source, channel: 'stable', channelSelectable: undefined })
await waitFor((): void => {
expect(screen.queryByText(about.title)).toBeNull()
})
+ $updateStatus.set({ ...source, mechanism: 'electron-updater', channel: 'stable' })
+ expect(screen.queryByText(about.title)).toBeNull()
})
it('a commit client refuses updates without hiding an unrelated backend update', (): void => {
diff --git a/apps/desktop/src/app/settings/update-channel-row.tsx b/apps/desktop/src/app/settings/update-channel-row.tsx
index bc6820c0fe9..7a6efaf9ac2 100644
--- a/apps/desktop/src/app/settings/update-channel-row.tsx
+++ b/apps/desktop/src/app/settings/update-channel-row.tsx
@@ -1,12 +1,12 @@
import { useStore } from '@nanostores/react'
-import type { ReactElement } from 'react'
+import { type ReactElement, useState } from 'react'
import { SegmentedControl } from '@/components/ui/segmented-control'
import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
import { confirm } from '@/store/confirm'
import { notifyError } from '@/store/notifications'
-import { $updateChecking, $updateStatus, setUpdateChannel, type SourceUpdateChannel, sourceUpdateChannel } from '@/store/updates'
+import { $updateChecking, $updateStatus, checkUpdates, setUpdateChannel, type SourceUpdateChannel, sourceUpdateChannel } from '@/store/updates'
import { ListRow } from './primitives'
@@ -19,7 +19,10 @@ export function UpdateChannelRow(): ReactElement | null {
const a = t.settings.about.channel
const status = useStore($updateStatus)
const checking = useStore($updateChecking)
- const channel = sourceUpdateChannel(status)
+ // The confirmed choice paints at once; the check that follows the save can be slow.
+ const [pending, setPending] = useState<SourceUpdateChannel | null>(null)
+ const saved = sourceUpdateChannel(status)
+ const channel = pending ?? saved
if (channel === null) {
return null
@@ -43,11 +46,16 @@ export function UpdateChannelRow(): ReactElement | null {
}
triggerHaptic('crisp')
+ setPending(next)
try {
await setUpdateChannel(next)
} catch (error) {
+ // A throw may still follow a save, so re-read the install instead of guessing.
notifyError(error, a.failed)
+ void checkUpdates()
+ } finally {
+ setPending(null)
}
}
@@ -55,7 +63,7 @@ export function UpdateChannelRow(): ReactElement | null {
<ListRow
action={
<SegmentedControl
- disabled={checking}
+ disabled={checking || pending !== null}
onChange={id => void change(id)}
options={[
{ id: 'stable', label: a.stable },
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 0fc4fda550e..fdc361ac4a8 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -881,6 +881,8 @@ export interface DesktopUpdateStatus {
currentVersion?: string
/** The R2 channel name; independent of source branch and package version. */
channel?: string
+ /** The install's source_check can persist a channel (older runtimes cannot). */
+ channelSelectable?: boolean
/** The latest release tag on a release-feed channel, e.g. `v0.18.0`. */
latestTag?: string | null
targetSha?: string
diff --git a/apps/desktop/src/store/updates-channel.test.ts b/apps/desktop/src/store/updates-channel.test.ts
index 28bec22d25d..9beac7377e5 100644
--- a/apps/desktop/src/store/updates-channel.test.ts
+++ b/apps/desktop/src/store/updates-channel.test.ts
@@ -4,20 +4,28 @@ import type { DesktopUpdateStatus } from '@/global'
import { sourceUpdateChannel } from './updates'
-const status = (fields: Partial<DesktopUpdateStatus>): DesktopUpdateStatus => ({ supported: true, ...fields })
+const status = (fields: Partial<DesktopUpdateStatus>): DesktopUpdateStatus => ({
+ supported: true,
+ mechanism: 'posix-handoff',
+ channelSelectable: true,
+ ...fields
+})
describe('sourceUpdateChannel', () => {
- it('offers the selector only to source checkouts on stable or main', () => {
- expect(sourceUpdateChannel(status({ mechanism: 'posix-handoff', channel: 'stable' }))).toBe('stable')
+ it('offers the selector only where the choice is stable or main and can be saved', () => {
+ expect(sourceUpdateChannel(status({ channel: 'stable' }))).toBe('stable')
expect(sourceUpdateChannel(status({ mechanism: 'windows-handoff', branch: 'main' }))).toBe('main')
-
// Packages bake their channel; a preview channel is not the user's to flip here.
for (const mechanism of ['electron-updater', 'app-installer', 'microsoft-store', 'external'] as const) {
expect(sourceUpdateChannel(status({ mechanism, channel: 'stable' }))).toBeNull()
}
- expect(sourceUpdateChannel(status({ mechanism: 'posix-handoff', channel: 'pm-preview' }))).toBeNull()
- expect(sourceUpdateChannel(status({ mechanism: 'posix-handoff', supported: false }))).toBeNull()
+ expect(sourceUpdateChannel(status({ channel: 'pm-preview' }))).toBeNull()
+ expect(sourceUpdateChannel(status({ supported: false, channel: 'stable' }))).toBeNull()
expect(sourceUpdateChannel(null)).toBeNull()
+ // A runtime older than --set-channel answers checks but cannot save a channel.
+ expect(sourceUpdateChannel(status({ channel: 'stable', channelSelectable: undefined }))).toBeNull()
+ // A custom branch is neither stable releases nor every commit on main.
+ expect(sourceUpdateChannel(status({ branch: 'feature/gui' }))).toBeNull()
})
})
diff --git a/apps/desktop/src/store/updates.ts b/apps/desktop/src/store/updates.ts
index 05ad8d803c8..5bc1645698a 100644
--- a/apps/desktop/src/store/updates.ts
+++ b/apps/desktop/src/store/updates.ts
@@ -632,21 +632,34 @@ export async function checkUpdates({ force = false }: UpdateCheckOptions = {}):
export type SourceUpdateChannel = 'main' | 'stable'
-/** The selectable channel of a source checkout, or null where the package owns it. */
+/**
+ * The selectable channel of a source checkout, or null where the selector must not
+ * appear: packages own their channel, runtimes older than the flag cannot save one,
+ * and a custom branch is neither stable releases nor every commit on main.
+ */
export function sourceUpdateChannel(status: DesktopUpdateStatus | null): SourceUpdateChannel | null {
- if (!status?.supported || (status.mechanism !== 'posix-handoff' && status.mechanism !== 'windows-handoff')) {
+ const source = status?.mechanism === 'posix-handoff' || status?.mechanism === 'windows-handoff'
+
+ if (!status?.supported || !source || !status.channelSelectable) {
return null
}
- return status.channel === undefined ? 'main' : status.channel === 'stable' ? 'stable' : null
+ if (status.channel === 'stable') {
+ return 'stable'
+ }
+
+ return status.channel === undefined && status.branch === 'main' ? 'main' : null
}
-/** Persist the source checkout's channel; the reply is a fresh check against it. */
-export async function setUpdateChannel(channel: SourceUpdateChannel): Promise<DesktopUpdateStatus | null> {
+/**
+ * Persist the source checkout's channel; the reply is a fresh check against it.
+ * An unreachable release still returns a status naming the saved channel.
+ */
+export async function setUpdateChannel(channel: SourceUpdateChannel): Promise<DesktopUpdateStatus> {
const setChannel = window.hermesDesktop?.updates?.setChannel
- if (!setChannel || $updateChecking.get()) {
- return null
+ if (!setChannel) {
+ throw new Error('This installation cannot change its update channel.')
}
$updateChecking.set(true)
diff --git a/hermes_cli/source_check.py b/hermes_cli/source_check.py
index b610f2815a3..37ffacae49b 100644
--- a/hermes_cli/source_check.py
+++ b/hermes_cli/source_check.py
@@ -461,6 +461,9 @@ def main() -> None:
set_install_channel(args.set_channel, args.install_root)
args.force = True
result = check_for_updates(**{k: v for k, v in vars(args).items() if k != "set_channel"})
+ if isinstance(result, dict):
+ # Older runtimes reject --set-channel; Desktop offers its selector only on this flag.
+ result["channelSelectable"] = True
print(json.dumps(result))