Open-source Xbox-inspired desktop launcher for Xodus on Linux
TypeScript
refactor(header): show only genuine component updates
Nexus Maintainer1cc4549c53b1
diff --git a/src/renderer/App.tsx b/src/renderer/App.tsxindex 911b844..f92f429 100644--- a/src/renderer/App.tsx+++ b/src/renderer/App.tsx@@ -4,7 +4,7 @@ import {StatusDot} from './StatusDot';import {useGameRuntimeReady} from './useGameRuntimeReady';import {useStoreAccess} from './store-access';import {GameRuntimeFields} from './GameRuntimeFields';-import {type InstalledRuntimeFamily,type GameRuntimeSelection} from '../shared/runtime-selection';+import {runtimeFamilyLabels,type InstalledRuntimeFamily,type GameRuntimeSelection} from '../shared/runtime-selection';import { CloudSaveWarning } from './CloudSaveWarning';import { CheckField } from './CheckField';import { useDialogFocus } from './use-dialog-focus';@@ -20,7 +20,7 @@ import {OverlayShortcutRecorder} from './OverlayShortcutRecorder';import {reconcileSettingsDraft, storageSettingsPatch} from './settings-draft';import {xboxOverlaySettings} from '../shared/xbox-overlay-settings';import './xbox-desktop-social.css';-import { estimateTimeRemaining } from '../shared/utils';+import { estimateTimeRemaining, isNewerVersion } from '../shared/utils';import { nexusRuntimeUpdateAvailable, runtimeDisplay, activeRuntimeIsCachyos } from '../shared/runtime-display';import { subscriptionBadge } from '../shared/subscription';import { defaultLaunchTools, normalizeLaunchTools } from '../shared/launch-tools';@@ -126,21 +126,37 @@ function AccountAvatar({ auth, large = false, license = false }: { auth: AppSnap</div>;}+/** The top bar only carries a real component-update (or restart) action. A+ * permanent readied/offline badge and a second global Settings shortcut would+ * duplicate the sidebar and the existing Settings, Home and launch surfaces.+ * Discovery only reads authoritative snapshot fields here: a managed family is+ * an update only when it is installed and its verified candidate differs, and+ * an uninstalled optional family is never advertised or checked on render. */export function TopStatus({ data, go, openFriends }: { data: AppSnapshot; go: (page: Page) => void; openFriends?: () => void }) {const restart = data.launcherUpdate?.restartRequired;+ // The default-runtime notice and the managed Standard family describe the+ // same runtime family, so one entry survives the deduplication below.+ const managed = (data.runtime.managedFamilies ?? []).filter(family =>+ Boolean(family.installed) && Boolean(family.available) && family.updateAvailable === true);+ const runtimeUpdates = new Map<string, string>();+ if (nexusRuntimeUpdateAvailable(data.runtime) && !managed.some(family => family.id === 'nexus'))+ runtimeUpdates.set('nexus', ui('home.runtime_update', { version: data.runtime.nexusVersion?.replace(/^runtime-/, '') ?? '' }).trim());+ for (const family of managed) {+ const candidate = family.available;+ if (!candidate || runtimeUpdates.has(family.id)) continue;+ const version = candidate.version.replace(/^runtime-/, '').replace(/^cachyos-/, '');+ runtimeUpdates.set(family.id, ui('home.runtime_update', { version: `${runtimeFamilyLabels[family.id]} ${version}` }).trim());+ }+ const latest = data.launcherUpdate?.latestVersion;const updates = [- data.launcherUpdate?.latestVersion && !restart ? ui("ui.launcher_ba8971d", { version: data.launcherUpdate.latestVersion }) : '',+ latest && !restart && isNewerVersion(latest, data.launcherUpdate?.currentVersion ?? '') ? ui("ui.launcher_ba8971d", { version: latest }) : '',data.backend.releaseAvailable && data.backend.updateAvailable ? ui("ui.backend_35f8dc4", { version: data.backend.releaseVersion ?? '' }).trim() : '',- nexusRuntimeUpdateAvailable(data.runtime) ? ui('home.runtime_update', { version: data.runtime.nexusVersion?.replace(/^runtime-/, '') ?? '' }).trim() : '',+ ...runtimeUpdates.values(),].filter(Boolean);const updateTitle = [restart ? ui('home.restart_update') : '', updates.length ? ui('home.available_updates', { updates: updates.join(', ') }) : ''].filter(Boolean).join(' ');- const offline = data.backend.available && data.connectivity?.state === 'offline';+ if (!restart && !updates.length) return null;return <div className="top-status">- {updates.length || restart ? <button className="update-notice" title={updateTitle} aria-label={updateTitle} onClick={() => go('settings')}><ArrowDownToLine /><strong>{restart ? ui("ui.restart_available_cad1527") : ui("ui.update_available_ff8b555")}</strong></button> : null}- <StatusDot tone={!data.backend.available ? 'red' : offline ? 'amber' : 'green'} />- <span title={offline ? `${uiText(data.connectivity?.reason) ?? ui('offline.unreachable')} ${ui('offline.header_hint')}` : undefined}>- {!data.backend.available ? ui("ui.backend_offline_5904a63") : offline ? ui('offline.header') : ui("ui.xodus_ready_b131015")}- </span><button title={ui("ui.settings_74a883a")} onClick={() => go('settings')}><Settings2 /></button>+ <button className="update-notice" title={updateTitle} aria-label={updateTitle} onClick={() => go('settings')}><ArrowDownToLine /><strong>{restart ? ui("ui.restart_available_cad1527") : ui("ui.update_available_ff8b555")}</strong></button></div>;}diff --git a/src/renderer/friends.test.tsx b/src/renderer/friends.test.tsxindex 2370133..98b968b 100644--- a/src/renderer/friends.test.tsx+++ b/src/renderer/friends.test.tsx@@ -1,7 +1,7 @@import { expect,it,vi } from 'vitest';import { renderToStaticMarkup } from 'react-dom/server';import { FriendAvatar, Friends, preloadFriends } from './Friends';-import { TopStatus } from './App';+import { TopStatus, Sidebar } from './App';import { demoSnapshot } from '../shared/demo-data';it('warms reads only after explicit intent with a supported signed-in account',async()=>{const data=demoSnapshot(),load=vi.fn(async()=>{});@@ -27,9 +27,11 @@ it('keeps the dock without an overlay, manual refresh button or permanent explanexpect(html).not.toMatch(/desktop overlay|Ctrl\+Shift\+F10|Refresh friends|Refresh conversation|friends-limitation|Chat does not change/);expect(html).not.toMatch(/Invitation sent\.|<iframe|<webview/);});-it('keeps friends out of the top bar and preserves existing navigation',()=>{+it('keeps friends and the duplicate global settings shortcut out of the top bar',()=>{const html=renderToStaticMarkup(<TopStatus data={demoSnapshot()} go={()=>{}} openFriends={()=>{}} />);- expect(html).not.toContain('Xbox friends and chat');expect(html).toContain('Settings');+ expect(html).toBe('');+ const sidebar=renderToStaticMarkup(<Sidebar data={demoSnapshot()} page="home" go={()=>{}} />);+ expect(sidebar).toContain('Settings');});it('preserves the bottom-right dock and uses a photo or an honest fallback icon',()=>{const data=demoSnapshot();diff --git a/src/renderer/header-updates.test.tsx b/src/renderer/header-updates.test.tsxnew file mode 100644index 0000000..1e7774d--- /dev/null+++ b/src/renderer/header-updates.test.tsx@@ -0,0 +1,101 @@+// @vitest-environment jsdom+import {act} from 'react';+import {createRoot,type Root} from 'react-dom/client';+import {renderToStaticMarkup} from 'react-dom/server';+import {afterEach,beforeEach,expect,it,vi} from 'vitest';+import {SettingsPage,Sidebar,TopStatus} from './App';+import {demoSnapshot} from '../shared/demo-data';+import type {AppSnapshot,ManagedFamilyStatus} from '../shared/types';++let root:Root,data:AppSnapshot,go:ReturnType<typeof vi.fn>;+const offer=(version:string,archiveName:string)=>({version,candidateSha256:'a'.repeat(64),sourceCommit:'b'.repeat(40),archiveName,requiresBackendVersion:'0.5.0',requiresLauncherVersion:'0.5.0'});+const build=(id:'nexus'|'nexus-cachyos',label:string)=>({id,label,buildId:'c'.repeat(64),manifestSha256:'d'.repeat(64),sourceCommit:'e'.repeat(40)});+const managedStandard:ManagedFamilyStatus={id:'nexus',checking:false,installing:false,installed:build('nexus','Standard'),version:'runtime-10.0',channel:'stable',available:offer('runtime-11.0','nexus-runtime-x86_64.tar.xz'),updateAvailable:true};+const managedCachyos:ManagedFamilyStatus={id:'nexus-cachyos',checking:false,installing:false,installed:build('nexus-cachyos','CachyOS'),version:'runtime-cachyos-10.0',channel:'stable',available:offer('runtime-cachyos-11.0','nexus-runtime-cachyos-x86_64.tar.xz'),updateAvailable:true};+const legacyStandard=(snapshot:AppSnapshot)=>{snapshot.runtime={...snapshot.runtime,installed:true,name:'xodus-nexus-runtime-10.0-old',nexusAvailable:true,nexusVersion:'runtime-11.0-new',nexusName:'xodus-nexus-runtime-11.0-new-x86_64.tar.xz'};};+const render=async(snapshot:AppSnapshot)=>act(async()=>root.render(<TopStatus data={snapshot} go={go}/>));+const action=()=>document.querySelector<HTMLButtonElement>('button.update-notice');+const buttons=()=>document.querySelectorAll('button').length;+const click=async(node:HTMLButtonElement|null)=>{expect(node).not.toBeNull();await act(async()=>node!.click());};++beforeEach(()=>{+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT',true);data=demoSnapshot();go=vi.fn();+ window.launcher={planComponentUpdates:vi.fn(),checkManagedRuntime:vi.fn(),installManagedRuntime:vi.fn()} as unknown as Window['launcher'];+ document.body.innerHTML='<div id="root"></div>';root=createRoot(document.getElementById('root')!);+});+afterEach(async()=>{await act(async()=>root.unmount());vi.restoreAllMocks();vi.unstubAllGlobals();document.body.innerHTML='';});++it('renders no ready badge, offline text or duplicate settings gear without a component update',async()=>{+ await render(data);+ expect(document.querySelector('.top-status')).toBeNull();expect(buttons()).toBe(0);+ expect(document.body.textContent??'').not.toMatch(/Xodus ready|Offline|Settings/);+ data.connectivity={state:'offline',reason:'No network interface is connected.'};await render(data);+ expect(document.querySelector('.top-status')).toBeNull();expect(buttons()).toBe(0);+ data.backend.available=false;await render(data);+ expect(document.querySelector('.top-status')).toBeNull();expect(buttons()).toBe(0);+});++it('keeps backend failures on the existing Settings surface instead of claiming readiness',async()=>{+ data.backend.available=false;+ const settings=renderToStaticMarkup(<SettingsPage data={data} toast={()=>{}}/>);+ expect(settings).toContain('Xodus backend');expect(settings).toContain('OFFLINE');+ await render(data);expect(document.querySelector('.top-status')).toBeNull();+});++it('opens Settings from a genuine backend update',async()=>{+ data.backend.releaseAvailable=true;data.backend.updateAvailable=true;data.backend.releaseVersion='0.5.2';+ await render(data);+ expect(action()?.getAttribute('title')).toContain('Backend 0.5.2');+ await click(action());expect(go).toHaveBeenCalledTimes(1);expect(go).toHaveBeenCalledWith('settings');+});++it('opens Settings from a newer launcher release and ignores a non-newer latestVersion',async()=>{+ data.launcherUpdate={currentVersion:'0.4.2',checking:false,checkedAt:'today',latestVersion:'0.4.2'};+ await render(data);expect(action()).toBeNull();+ data.launcherUpdate={...data.launcherUpdate,latestVersion:'0.4.3'};await render(data);+ expect(action()?.getAttribute('title')).toContain('Launcher 0.4.3');+ await click(action());expect(go).toHaveBeenCalledTimes(1);expect(go).toHaveBeenCalledWith('settings');+});++it('advertises one installed Standard runtime family and dedupes the default Standard notice',async()=>{+ legacyStandard(data);data.runtime.managedFamilies=[managedStandard];+ await render(data);+ const title=action()?.getAttribute('title')??'';+ expect(title).toContain('Runtime Standard 11.0');+ expect(title).not.toContain('Runtime 11.0-new');+ expect((title.match(/Runtime /g)??[])).toHaveLength(1);+ await click(action());expect(go).toHaveBeenCalledTimes(1);expect(go).toHaveBeenCalledWith('settings');+});++it('opens Settings for an installed managed CachyOS update',async()=>{+ data.runtime.managedFamilies=[managedCachyos];+ await render(data);+ expect(action()?.getAttribute('title')).toContain('Runtime CachyOS 11.0');+ await click(action());expect(go).toHaveBeenCalledTimes(1);expect(go).toHaveBeenCalledWith('settings');+});++it('never advertises an uninstalled optional CachyOS candidate and performs no discovery on render',async()=>{+ data.runtime.managedFamilies=[{...managedCachyos,installed:undefined,updateAvailable:true}];+ await render(data);+ expect(document.querySelector('.top-status')).toBeNull();expect(buttons()).toBe(0);+ expect(window.launcher.planComponentUpdates).not.toHaveBeenCalled();+ expect(window.launcher.checkManagedRuntime).not.toHaveBeenCalled();+ expect(window.launcher.installManagedRuntime).not.toHaveBeenCalled();+});++it('keeps a pending launcher restart actionable without a latestVersion',async()=>{+ data.launcherUpdate={currentVersion:'0.4.2',checking:false,restartRequired:true};+ data.backend.releaseAvailable=true;data.backend.updateAvailable=true;data.backend.releaseVersion='0.5.2';+ await render(data);+ expect(action()?.textContent).toContain('Restart available');+ expect(action()?.getAttribute('title')).toContain('Restart to finish launcher update.');+ await click(action());expect(go).toHaveBeenCalledTimes(1);expect(go).toHaveBeenCalledWith('settings');+});++it('leaves the sidebar Settings entry as the only global settings control',async()=>{+ await render(data);expect(action()).toBeNull();+ await act(async()=>root.render(<Sidebar data={data} page="home" go={go}/>));+ const settings=[...document.querySelectorAll<HTMLButtonElement>('button')].filter(node=>node.textContent?.trim()==='Settings');+ expect(settings).toHaveLength(1);+ await click(settings[0]);expect(go).toHaveBeenCalledTimes(1);expect(go).toHaveBeenCalledWith('settings');+});diff --git a/src/renderer/maintenance.test.tsx b/src/renderer/maintenance.test.tsxindex 0cd98b6..1311325 100644--- a/src/renderer/maintenance.test.tsx+++ b/src/renderer/maintenance.test.tsx@@ -17,20 +17,20 @@ it('offers an app-owned overlay shortcut and left/right shelf settings with leftexpect(html).toMatch(/<details class="settings-card settings-guide" aria-label="Nexus Overlay">/);expect(html).not.toContain('Desktop portal');});-it('keeps backend health and launcher update notices distinct', () => {+it('shows one update action without a permanent ready badge or duplicate settings control', () => {const data = demoSnapshot(); data.launcherUpdate!.latestVersion = '0.3.1';const html = renderToStaticMarkup(<TopStatus data={data} go={() => {}} />);- expect(html).toContain('Update available'); expect(html).toContain('Xodus ready');+ expect(html).toContain('Update available'); expect(html).toContain('Launcher 0.3.1');+ expect(html).not.toContain('Xodus ready'); expect(html).not.toContain('status-dot');+ expect(html.match(/<button/g) ?? []).toHaveLength(1);});-it('shows the offline verdict only while the backend itself is available', () => {+it('leaves the decluttered header empty while the backend is reachable, offline or unavailable', () => {const data = demoSnapshot(); data.connectivity = { state: 'offline', reason: 'No network interface is connected.' };- const offline = renderToStaticMarkup(<TopStatus data={data} go={() => {}} />);- expect(offline).toContain('status-dot amber'); expect(offline).toContain('>Offline<'); expect(offline).toContain('stored offline licenses');+ expect(renderToStaticMarkup(<TopStatus data={data} go={() => {}} />)).toBe('');data.backend.available = false;- const noBackend = renderToStaticMarkup(<TopStatus data={data} go={() => {}} />);- expect(noBackend).toContain('status-dot red'); expect(noBackend).toContain('Backend offline'); expect(noBackend).not.toContain('>Offline<');+ expect(renderToStaticMarkup(<TopStatus data={data} go={() => {}} />)).toBe('');data.backend.available = true; data.connectivity = { state: 'unknown' };- expect(renderToStaticMarkup(<TopStatus data={data} go={() => {}} />)).toContain('Xodus ready');+ expect(renderToStaticMarkup(<TopStatus data={data} go={() => {}} />)).toBe('');});it.each([[false, false, false], [true, false, false], [false, true, false], [false, false, true],@@ -47,7 +47,6 @@ it.each([for (const [available, label] of [[launcher, 'Launcher 0.3.9'], [backend, 'Backend 0.2.9'], [runtime, 'Runtime 11.0-new']] as const) {if (available) expect(html).toContain(label); else expect(html).not.toContain(label);}- expect(html).toContain('Xodus ready');});it('never advertises the Standard runtime release in the top notice while a CachyOS runtime is active', () => {const data = demoSnapshot();