Open-source Xbox-inspired desktop launcher for Xodus on Linux
TypeScript
feat(store): explain public Store US prices without changing account scope
Nexus Maintainer561ac42edc04
diff --git a/assets/locales/en.json b/assets/locales/en.jsonindex 2ceda3d..aea7097 100644--- a/assets/locales/en.json+++ b/assets/locales/en.json@@ -347,6 +347,8 @@"store.available_with": "Available with {{plan}}","store.id": "Store ID {{id}}","store.package_id": "Package ID {{id}}",+ "store.us_price_context": "Public Store prices come from the US Store and are shown in USD. Checkout price and local availability can differ.",+ "store.us_price_short": "US Store, USD","store.verified_msixvc": "PC MSIXVC verified","store.verified_pc": "PC package verified","time.days_left": "~{{first}}d {{second}}h left",diff --git a/src/renderer/App.tsx b/src/renderer/App.tsxindex 0474598..cca0574 100644--- a/src/renderer/App.tsx+++ b/src/renderer/App.tsx@@ -34,7 +34,7 @@ import { requestTextKeyboard } from './touch-keyboard';import { ConfirmationProvider, useConfirmation } from './Confirmation';import { GameRemovalContents } from './GameRemovalContents';import { GameDetails } from './GameDetails';-import {CatalogGameDetails,catalogGameInstalled} from './CatalogGameDetails';+import {CatalogGameDetails,catalogGameInstalled,publicStorePrice} from './CatalogGameDetails';import { GameLanguage } from './GameLanguage';import { DownloadCancelDialog } from './DownloadCancelDialog';import { OfflinePermissionsCard } from './OfflinePermissions';@@ -276,12 +276,13 @@ export function StoreProductCard({ product, selected, disabled, label, select, iproduct: CatalogProduct; selected: boolean; disabled: boolean; label: string; licensed?: boolean;select: (product: CatalogProduct,openDetails?:boolean) => void; install: (product: CatalogProduct) => void;}) {+ const price=publicStorePrice(product);return <article className={`catalog-card ${selected ? 'selected' : ''}`} data-gamepad-card><button className="catalog-card-main" data-gamepad-auto-select="focus" data-gamepad-detail-target={product.productId}onFocus={() => select(product,false)} onClick={() => select(product,true)}>{product.posterUrl ? <img src={product.posterUrl} alt={ui("ui.cover_47bbe4b", { game: product.title })} /> : <div className="catalog-cover-placeholder"><Gamepad2 /></div>}<CatalogSupportBadge product={product} />- <div><GameTitle title={product.title} /><small>{product.publisher ?? product.productId}</small><span>{product.purchasePrice ?? ui("ui.price_unavailable_6a9e657")}{product.includedWith ? ` · ${product.includedWith}` : ''}</span></div>+ <div><GameTitle title={product.title} /><small>{product.publisher ?? product.productId}</small><span title={price ? ui('store.us_price_context') : undefined}>{product.purchasePrice ?? ui("ui.price_unavailable_6a9e657")}{price ? ` · ${ui('store.us_price_short')}` : ''}{product.includedWith ? ` · ${product.includedWith}` : ''}</span></div></button>{licensed ? <button className="catalog-card-install" data-gamepad-skip data-gamepad-card-action disabled={disabled} onClick={() => install(product)}>{label === 'Preparing…' ? <LoaderCircle className="spin" /> : label === 'Installed' ? <Check /> : <Download />}{label}@@ -369,8 +370,12 @@ export function StorePage({ data, toast, go, initialQuery }: { data: AppSnapshotselect={selectProduct} install={install} />;})}</div>;if(detailOpen&&selected)return <main ref={pageRef} className="page store-page library-detail-open"><CatalogGameDetails key={`${selected.productId}:${data.auth.username}:${data.auth.player}:${data.auth.stored}:${data.auth.running}:${data.backend.binaryPath}:${data.settings.market}`} product={selected} data={data} storeMode storeAccess={access} back={()=>setDetailOpen(false)} backLabel={ui('game.back_to_store')} toast={toast}/></main>;+ // Only the product grid renders a price. The first three featured tiles are+ // artwork-only, and all catalog results render in the price-bearing grid.+ const priceGrid=catalog?catalog.products:featured?.products.slice(3)??[];+ const publicPriceShown=priceGrid.some(product=>Boolean(publicStorePrice(product)));return <main ref={pageRef} className="page store-page">- <header className="page-header"><div><h1>{ui("ui.store_ee7da93")}</h1></div><span className="catalog-source"><StatusDot />Microsoft Store</span></header>+ <header className="page-header"><div><h1>{ui("ui.store_ee7da93")}</h1>{publicPriceShown?<p>{ui('store.us_price_context')}</p>:null}</div><span className="catalog-source"><StatusDot />Microsoft Store</span></header>{!catalog ? <section className="featured-catalog"><SectionTitle title={ui("ui.featured_c533caf")} />{featuredLoading ? <div className="catalog-loading"><LoaderCircle className="spin" /><span>{ui("ui.loading_live_store_collection_20763b0")}</span></div> : featured?.products.length ? <><div className="featured-rail">{featured.products.slice(0, 3).map((product) => <button className="featured-tile" key={product.productId} data-gamepad-detail-target={product.productId} onClick={() => selectProduct(product)}>{product.heroUrl || product.posterUrl ? <img src={product.heroUrl ?? product.posterUrl} alt="" /> : <div className="featured-tile-placeholder"><Gamepad2 /></div>}<span className="featured-tile-copy"><GameTitle title={product.title} /><small>{product.publisher ?? 'Microsoft Store'} · {product.installability === 'supported' ? ui('store.verified_pc') : ui("ui.check_package_support_79592da")}</small></span></button>)}</div><SectionTitle title={ui("ui.top_paid_games_8040f77")} />{productGrid(featured.products.slice(3))}</> : <div className="catalog-empty"><Store /><h2>{ui("ui.featured_games_are_temporarily_unavailable_3901a69")}</h2><p>{featuredError ?? ui("ui.search_still_works_with_live_microsoft_store_dat_b3eeb72")}</p></div>}</section> : null}{catalog ? <><SectionTitle title={ui("ui.results_for_343a212", { query: catalog.query })} />{productGrid(catalog.products)}{catalog.products.length === 0 ? <div className="empty-state compact"><div><Search /></div><h2>{ui("ui.no_games_found_6da4c04")}</h2><p>{ui("ui.try_a_different_title_or_a_microsoft_store_produ_326af8c")}</p></div> : null}{catalog.hasMore ? <div className="load-more" data-gamepad-library-footer><button className="secondary" aria-disabled={loadingMore} aria-busy={loadingMore} onClick={() => { if (!loadingMore) void loadMore(); }}>{loadingMore ? <LoaderCircle className="spin" /> : <Plus />}{ui("ui.load_more_results_e03f1e4")}</button></div> : null}</> : null}diff --git a/src/renderer/CatalogGameDetails.tsx b/src/renderer/CatalogGameDetails.tsxindex cfdd160..4fc7dae 100644--- a/src/renderer/CatalogGameDetails.tsx+++ b/src/renderer/CatalogGameDetails.tsx@@ -13,6 +13,16 @@ export function catalogGameInstalled(product:CatalogProduct,data:AppSnapshot){export function catalogGameQueued(product:CatalogProduct,data:AppSnapshot){return data.downloads.some(task=>['running','queued','paused'].includes(task.status)&&[product.productId,product.installProductId].includes(task.productId.toUpperCase()));}+/** The public Store producer formats US prices as a dollar amount, for+ * example "$29.99". Marker text such as "Included" or "Free for 30 days"+ * never gets a currency claim, and an unrecognised or bare amount is left+ * unlabelled instead of being relabelled as USD. */+const PUBLIC_STORE_AMOUNT=/^\$\s?\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$/;+const PUBLIC_STORE_MARKER=/^(?:free|included)\b/i;+export function publicStorePrice(product:Pick<CatalogProduct,'purchasePrice'>):string|undefined{+ const value=product.purchasePrice?.trim();+ return value&&!PUBLIC_STORE_MARKER.test(value)&&PUBLIC_STORE_AMOUNT.test(value)?value:undefined;+}export function CatalogGameDetails({product,data,back,backLabel,toast,storeAccess,storeMode=false}:{product:CatalogProduct;storeMode?:boolean;storeAccess?:ReturnType<typeof useStoreAccess>;data:AppSnapshot;back:()=>void;backLabel?:string;toast:(value:{kind:'success'|'error';message:string})=>void}){const startInstall=usePackageInstall();@@ -48,7 +58,7 @@ export function CatalogGameDetails({product,data,back,backLabel,toast,storeAccesreturn <GameDetails key={installed?.id??product.productId} game={installed??{id:'catalog:'+product.productId,title:product.title,publisher:product.publisher,heroUrl:product.heroUrl,coverUrl:product.posterUrl}}detailId={product.productId} catalogProductId={installed?undefined:product.productId} publicMetadataProductId={storeMode?product.productId:undefined} data={data} back={back} backLabel={backLabel} play={<>{button}<button className="secondary" onClick={()=>window.open(product.storeUrl??`https://www.xbox.com/games/store/p/${product.productId}`,'_blank')}>{ui('ui.store_page_9c667df')}</button></>}notices={!installed?<section className="gd-install-options">{licensed?<p className={product.installability==='supported'?'supported':'unsupported'}>{uiText(product.supportNote)}</p>:null}- {product.purchasePrice||product.includedWith?<div className="catalog-badges">{product.purchasePrice?<span>{product.purchasePrice}</span>:null}{product.includedWith?<span className="pass">{ui('store.available_with',{plan:product.includedWith})}</span>:null}</div>:null}+ {product.purchasePrice||product.includedWith?<div className="catalog-price-summary"><div className="catalog-badges">{product.purchasePrice?<span>{product.purchasePrice}</span>:null}{product.includedWith?<span className="pass">{ui('store.available_with',{plan:product.includedWith})}</span>:null}</div>{storeMode&&publicStorePrice(product)?<p className="catalog-price-note">{ui('store.us_price_context')}</p>:null}</div>:null}{licensed?<label>{ui('ui.install_location_af47896')}<div className="input-action"><input value={destination} disabled={busy||queued} onChange={event=>setDestination(event.target.value)}/><button type="button" disabled={busy||queued} aria-label={ui('ui.choose_folder_3db7410')} onClick={async()=>{const value=await window.launcher.chooseDirectory(destination);if(value&&identity.current===scope)setDestination(value);}}><FolderOpen/></button></div></label>:null}</section>:undefined}/>}diff --git a/src/renderer/public-store-price.test.tsx b/src/renderer/public-store-price.test.tsxnew file mode 100644index 0000000..23927e5--- /dev/null+++ b/src/renderer/public-store-price.test.tsx@@ -0,0 +1,152 @@+// @vitest-environment jsdom+import {act} from 'react';+import {createRoot} from 'react-dom/client';+import {renderToStaticMarkup} from 'react-dom/server';+import {afterEach,expect,it,vi} from 'vitest';+import {CatalogGameDetails,publicStorePrice} from './CatalogGameDetails';+import {StorePage,StoreProductCard} from './App';+import {demoSnapshot} from '../shared/demo-data';+import {i18n,ui} from './i18n';+import type {CatalogProduct} from '../shared/types';++const product:CatalogProduct={productId:'9AAAAAAAAAAA',title:'Priced game',description:'',publisher:'Studio',installability:'supported',supportNote:'Supported',categories:[],purchasePrice:'$29.99'};+const note=ui('store.us_price_context');++function snapshot(market='CZ'){+ const data=demoSnapshot();data.games=[];data.downloads=[];data.settings.market=market;+ return data;+}+function item(id:string,purchasePrice?:string):CatalogProduct{+ return {...product,productId:id,title:id,purchasePrice};+}+function installLauncher(products:CatalogProduct[]){+ window.launcher={+ getFeaturedCatalog:vi.fn(async()=>({query:'',products,hasMore:false})),+ searchCatalog:vi.fn(async(query:string)=>({query,products:[],hasMore:false})),+ getStoreAccess:vi.fn(async()=>undefined),+ getGameDetails:vi.fn(async()=>undefined),+ getGameActivity:vi.fn(async()=>({status:'unavailable'})),+ getGameAchievements:vi.fn(async()=>({status:'unavailable',items:[]})),+ getGameRuntimeReadiness:vi.fn(async()=>false),+ launchGame:vi.fn(async()=>{}),+ } as unknown as Window['launcher'];+}+async function mount(element:React.ReactElement){+ const node=document.createElement('div'),root=createRoot(node);+ await act(async()=>{root.render(element);});+ await act(async()=>{await Promise.resolve();});+ await act(async()=>{await Promise.resolve();});+ return {node,unmount:async()=>{await act(async()=>root.unmount());}};+}+afterEach(async()=>{await i18n.changeLanguage('en');vi.unstubAllGlobals();document.body.innerHTML='';});++it('labels an actual public Store price with its US market without changing the account market or weakening access gates',async()=>{+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT',true);+ const data=snapshot('CZ');+ installLauncher([]);+ const view=await mount(<CatalogGameDetails storeMode product={product} data={data} back={()=>{}} toast={()=>{}}/>);+ try{+ const html=view.node.innerHTML;+ expect(html).toContain('$29.99');+ expect(html).toContain(note);+ expect(html).toContain('>Store page</button>');+ expect(html).not.toContain('>Install</button>');+ expect(data.settings.market).toBe('CZ');+ expect(i18n.language).toBe('en');+ }finally{await view.unmount();}+});++it.each([undefined,'Included','Free','Free for 30 days','Included with 12 months'])('does not attach a currency claim when the public Store value is %s',async purchasePrice=>{+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT',true);+ const data=snapshot();+ installLauncher([]);+ const view=await mount(<CatalogGameDetails storeMode product={{...product,purchasePrice}} data={data} back={()=>{}} toast={()=>{}}/>);+ try{+ const html=view.node.innerHTML;+ expect(html).not.toContain(note);+ expect(html).not.toContain('US Store, USD');+ }finally{await view.unmount();}+});++it.each([+ [undefined,undefined],+ ['Included',undefined],+ ['Free',undefined],+ ['Free for 30 days',undefined],+ ['Included with 12 months',undefined],+ ['29.99',undefined],+ ['USD 29.99',undefined],+ ['€29.99',undefined],+ ['$29.99','$29.99'],+ ['$30','$30'],+ ['$1,299.99','$1,299.99'],+])('recognises only a formatted US price, not marker or bare text: %s',(purchasePrice,expected)=>{+ expect(publicStorePrice({purchasePrice})).toBe(expected);+});++it('keeps an uninstalled Account Library detail price on the account market without a US claim',async()=>{+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT',true);+ const data=snapshot('DE');+ installLauncher([]);+ const view=await mount(<CatalogGameDetails product={product} data={data} back={()=>{}} toast={()=>{}}/>);+ try{+ const html=view.node.innerHTML;+ expect(html).toContain('$29.99');+ expect(html).toContain('>Install</button>');+ expect(html).toContain('Install location');+ expect(html).not.toContain(note);+ expect(data.settings.market).toBe('DE');+ }finally{await view.unmount();}+});++it('keeps an installed Store or Account Library detail free of a public price claim',async()=>{+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT',true);+ const data=snapshot('CZ');+ data.games=[{...demoSnapshot().games[0],storeId:product.productId,installState:'ready'}];+ installLauncher([]);+ const store=await mount(<CatalogGameDetails storeMode product={product} data={data} back={()=>{}} toast={()=>{}}/>);+ try{+ expect(store.node.innerHTML).toContain('>Play</button>');+ expect(store.node.innerHTML).not.toContain(note);+ }finally{await store.unmount();}+ const library=await mount(<CatalogGameDetails product={product} data={data} back={()=>{}} toast={()=>{}}/>);+ try{+ expect(library.node.innerHTML).toContain('>Play</button>');+ expect(library.node.innerHTML).not.toContain(note);+ }finally{await library.unmount();}+});++it('marks a priced public Store card with its US market and keeps a missing price neutral',()=>{+ const priced=renderToStaticMarkup(<StoreProductCard product={product} selected={false} disabled={false} label="Install" select={()=>{}} install={()=>{}}/>);+ expect(priced).toContain('$29.99 · US Store, USD');+ expect(priced).toContain('US Store and are shown in USD');+ const missing=renderToStaticMarkup(<StoreProductCard product={{...product,purchasePrice:undefined}} selected={false} disabled={false} label="Install" select={()=>{}} install={()=>{}}/>);+ expect(missing).toContain('Price unavailable');+ expect(missing).not.toContain('US Store, USD');+ expect(missing).not.toContain('US Store and are shown in USD');+ const free=renderToStaticMarkup(<StoreProductCard product={{...product,purchasePrice:'Free'}} selected={false} disabled={false} label="Install" select={()=>{}} install={()=>{}}/>);+ expect(free).toContain('Free');+ expect(free).not.toContain('US Store, USD');+});++it('shows the US price note only when the rendered Store grid contains a formatted price',async()=>{+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT',true);+ const data=snapshot('CZ');+ const page=async(products:CatalogProduct[])=>{+ installLauncher(products);+ return mount(<StorePage data={data} toast={()=>{}} go={()=>{}} initialQuery=""/>);+ };+ // The first three featured entries are artwork-only hero tiles with no price.+ const pricedHeroes=await page([item('9HERO0000001','$29.99'),item('9HERO0000002','$19.99'),item('9HERO0000003','$9.99')]);+ try{expect(pricedHeroes.node.innerHTML).not.toContain(note);}+ finally{await pricedHeroes.unmount();}+ const pricedGrid=await page([item('9HERO0000001'),item('9HERO0000002'),item('9HERO0000003'),item('9GRID0000001','$29.99')]);+ try{+ expect(pricedGrid.node.innerHTML).toContain(note);+ expect(pricedGrid.node.innerHTML).toContain('US Store, USD');+ expect(data.settings.market).toBe('CZ');+ }finally{await pricedGrid.unmount();}+ const unpricedGrid=await page([item('9HERO0000001','$29.99'),item('9HERO0000002'),item('9HERO0000003'),item('9GRID0000001')]);+ try{expect(unpricedGrid.node.innerHTML).not.toContain(note);}+ finally{await unpricedGrid.unmount();}+});diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 8baf479..111fdf7 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -230,6 +230,8 @@ button.primary svg, button.secondary svg { width: 17px; height: 17px; }.catalog-selection-copy h2 { max-width: 720px; margin: 9px 0 8px; font-size: 34px; line-height: 1.04; letter-spacing: -.04em; }.catalog-selection-copy > p { max-width: 690px; margin: 12px 0 9px; color: #c5c8cc; font-size: 11px; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }.catalog-selection-copy > small { color: #9ca1a7; font-size: 9px; }+.catalog-price-summary { display: grid; gap: 6px; }+.catalog-price-note { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }.catalog-badges { display: flex; flex-wrap: wrap; gap: 5px; }.catalog-badges span { padding: 5px 7px; border: 1px solid rgba(255,255,255,.18); background: rgba(20,22,24,.72); color: #d6d8db; font-size: 8px; font-weight: 700; text-transform: uppercase; }.catalog-badges .pass { color: #b6d5a5; border-color: rgba(101,169,69,.32); }