From c19dbb2ef002197b80936e82309973bafab155f5 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 13:05:40 +0000 Subject: [PATCH 01/16] A cloud save badge under Play says where a game's saves stand Up to date (and how long ago), checking, uploading, getting a newer save, syncs after you play, waiting to upload (offline, or the next try), choose a save, can't upload, too big, sync paused, off, not signed in or no saves yet. Clicking it shows when it last synced and from which PC, with the button that fits: Sync Now, Try Again, Choose a Save, Turn On, Sign In or Open Saves. It reads saves_status (this PC only, never the website) and follows the save-sync event, so it changes while a save goes up or comes down. --- tests/save-badge.test.cjs | 117 +++++++++++++++++++++ ui/account.js | 215 +++++++++++++++++++++++++++++++++++++- ui/app.css | 29 +++++ ui/app.js | 4 +- 4 files changed, 361 insertions(+), 4 deletions(-) create mode 100644 tests/save-badge.test.cjs diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs new file mode 100644 index 00000000..63fde2f9 --- /dev/null +++ b/tests/save-badge.test.cjs @@ -0,0 +1,117 @@ +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const account = fs.readFileSync(path.join(__dirname, '../ui/account.js'), 'utf8'); + +// Everything from `start` to the brace that closes the first one after it (a function, or a +// const object), out of account.js. +function block(start) { + const at = account.indexOf(start); + assert.ok(at >= 0, start); + let i = account.indexOf('{', at), depth = 0; + for (; i < account.length; i++) { + if (account[i] === '{') depth++; + if (account[i] === '}' && --depth === 0) break; + } + return account.slice(at, i + 1); +} +const line = (start) => { + const at = account.indexOf(start); + assert.ok(at >= 0, start); + return account.slice(at, account.indexOf('\n', at)); +}; + +// The badge's info for a status, with the window's helpers kept to plain English. +const info = new Function(` + const N_ = (x) => x, t = (x) => x, tf = (x) => x; + const tn = (n, one, many) => (n === 1 ? one : many).replace('{n}', n); + const ago = () => 'this week', whenText = (ts) => 'at ' + ts; + ${line('const SYNC_NOW = ')} + ${line('const OPEN_SAVES = ')} + ${block('const PROBLEM_BADGE = ')} + ${block('const PHASE_BADGE = ')} + ${block('function sinceText(')} + ${block('function saveBadgeInfo(')} + ${block('function problemBadge(')} + ${block('function waitingBadge(')} + return { saveBadgeInfo, sinceText };`)(); + +const now = () => Math.floor(Date.now() / 1000); +const status = (state, more = {}) => ({ state, syncedAt: 0, waiting: 0, retryIn: null, problem: null, newest: null, ...more }); +const acts = (b) => b.acts.map(([label]) => label); + +test('the same save here and in the cloud is green, with how long ago', () => { + const b = info.saveBadgeInfo(status('up-to-date', { syncedAt: now() - 12 * 60, syncedDevice: 'Desk PC' }), undefined, false); + assert.equal(b.tone, 'ok'); + assert.equal(b.label, 'Up to date'); + assert.equal(b.note, '12 min ago'); +}); + +test('an upload running shows over what the status says', () => { + const b = info.saveBadgeInfo(status('waiting', { waiting: 1 }), 'up', false); + assert.equal(b.label, 'Uploading…'); + assert.equal(b.tone, 'cy'); +}); + +test('a game being played says its save goes up after', () => { + const b = info.saveBadgeInfo(status('up-to-date', { syncedAt: now() }), undefined, true); + assert.equal(b.label, 'Syncs after you play'); +}); + +test('a conflict still asks for a choice while the game runs', () => { + const b = info.saveBadgeInfo(status('conflict'), undefined, true); + assert.equal(b.label, 'Choose a save'); + assert.deepEqual(acts(b), ['Choose a Save']); +}); + +test('a copy queued while offline says so and offers Try Again', () => { + const b = info.saveBadgeInfo(status('waiting', { waiting: 1, problem: { kind: 'offline', text: '' } }), undefined, false); + assert.equal(b.tone, 'warn'); + assert.equal(b.note, 'offline'); + assert.deepEqual(acts(b), ['Try Again']); +}); + +test('a copy waiting its next try says when', () => { + const b = info.saveBadgeInfo(status('waiting', { waiting: 2, retryIn: 230 }), undefined, false); + assert.equal(b.note, 'next try in 4 min'); +}); + +test('a newer save that goes up after the next session offers Sync Now', () => { + const b = info.saveBadgeInfo(status('waiting'), undefined, false); + assert.deepEqual(acts(b), ['Sync Now']); +}); + +test('a copy too big to send is red and named', () => { + const b = info.saveBadgeInfo(status('problem', { problem: { kind: 'too-big-copy', text: 'Over 95 MB.' } }), undefined, false); + assert.equal(b.tone, 'bad'); + assert.equal(b.label, 'Too big for the cloud'); + assert.equal(b.text, 'Over 95 MB.'); +}); + +test('a problem of a kind it does not know reads as an upload that failed', () => { + const b = info.saveBadgeInfo(status('problem', { problem: { kind: 'something-new', text: '' } }), undefined, false); + assert.equal(b.label, 'Can\'t upload'); + assert.deepEqual(acts(b), ['Sync Now', 'Open Saves']); +}); + +test('cloud saves off offers to turn them on', () => { + const b = info.saveBadgeInfo(status('off'), undefined, false); + assert.equal(b.tone, 'dim'); + assert.deepEqual(acts(b), ['Turn On']); +}); + +test('signed out offers to sign in', () => { + const b = info.saveBadgeInfo(status('signed-out'), undefined, false); + assert.deepEqual(acts(b), ['Sign In']); +}); + +test('a game never played has nothing to sync', () => { + const b = info.saveBadgeInfo(status('none'), undefined, false); + assert.equal(b.label, 'No saves yet'); + assert.equal(b.acts.length, 0); +}); + +test('a sync over a day ago falls back to the coarse wording', () => { + assert.equal(info.sinceText(now() - 3 * 86400), 'this week'); +}); diff --git a/ui/account.js b/ui/account.js index 0f4725d1..015b67ee 100644 --- a/ui/account.js +++ b/ui/account.js @@ -20,7 +20,7 @@ async function loadAccount(fresh) { const was = !!(S.account && S.account.signedIn); try { S.account = await invoke('account_state', { fresh: !!fresh }); } catch (e) { S.account = S.account || { signedIn: false }; } // Signed in (or out) just now: what each game's Saves tab knew is out of date. - if (was !== !!S.account.signedIn) { S.saves = {}; S.savesAll = null; S.myReports = null; } + if (was !== !!S.account.signedIn) { S.saves = {}; S.savesAll = null; S.myReports = null; forgetSaveStatus(); } renderAccountBits(); if (S.account.signedIn && !S.myReports && !S.account.offline) loadMyReports(); // Notify Me: the games they're waiting on (none when signed out). @@ -125,6 +125,7 @@ async function signOut() { try { await invoke('account_signout'); } catch (e) { /* signed out here anyway */ } S.account = { signedIn: false }; S.saves = {}; + forgetSaveStatus(); // The next sign-in merges this PC's saved list with that account's again. saveUi({ lib_synced: null, lib_queue: [] }, true).catch(() => {}); toast(t('Signed out. Your saves stay on this PC.')); @@ -184,6 +185,8 @@ async function loadSaves(id) { S.saves[id] = S.saves[id] && S.saves[id] !== 'loading' ? Object.assign(S.saves[id], { busy: true }) : 'loading'; try { S.saves[id] = await invoke('saves_info', { id }); } catch (e) { S.saves[id] = { error: String(e && e.message ? e.message : e) }; } if (S.view === 'game' && S.arg === id && S.tab === 'saves') refreshGame(); + // Whatever just changed the tab (Sync Now, Back Up Now, the cloud switch) changed the badge too. + loadSaveStatus(saveIdOf(id)); } const FROM = { player: N_('You picked this folder'), developer: N_('Its developer says it saves here'), catalog: N_('RecompLauncher knows it saves here') }; // Nobody (the player, its developer or RecompLauncher) has said where this game saves. Nothing is @@ -251,6 +254,196 @@ function copyRow(id, c, k, v, current) { const savesChanged = (id) => { delete S.saves[id]; if (S.view === 'game' && S.arg === id && S.tab === 'saves') loadSaves(id); }; +// ---------- the cloud save badge beside Play ---------- +// Where a game's saves stand, on its page under Play and among Big Picture's game buttons, so the +// player doesn't have to open the Saves tab to see whether the last save reached the cloud. +// saves_status answers from this PC alone (it never asks the website); the save-sync event says +// when something runs or ends, and the status is asked again then. +S.saveStat = {}; +S.savePhase = {}; +const statLoading = new Set(); +// The badge whose details are open (its save id), and the popover goes with any full redraw. +let badgeOpen = ''; + +// A game of several that keeps its own saves goes by its own id; any other by its recomp's. +function saveIdOf(id) { + const s = subOf(id); + const own = s && Array.isArray(s.game.saves) && s.game.saves.length; + return own ? id : parentId(id); +} + +async function loadSaveStatus(sid) { + if (statLoading.has(sid)) return; + statLoading.add(sid); + try { S.saveStat[sid] = await invoke('saves_status', { id: sid }); } catch (e) { S.saveStat[sid] = null; } + statLoading.delete(sid); + paintSaveBadges(sid); +} + +// "12 min ago" for the last sync: ago() only goes down to "today", too coarse for "did that +// session's save go up?". +function sinceText(ts) { + if (!ts) return ''; + const secs = Math.max(0, Date.now() / 1000 - ts); + if (secs < 60) return t('just now'); + if (secs < 3600) return tn(Math.floor(secs / 60), '1 min ago', '{n} min ago'); + if (secs < 86400) return tn(Math.floor(secs / 3600), '1 hour ago', '{n} hours ago'); + return ago(ts); +} + +const SYNC_NOW = [N_('Sync Now'), 'saves-sync']; +const OPEN_SAVES = [N_('Open Saves'), 'tab']; + +// What a problem kept by the last sync looks like on the badge, by its kind. The backend's own +// words say why; these say it short. +const PROBLEM_BADGE = { + full: { label: N_('Can\'t upload'), note: N_('cloud full'), head: N_('Your cloud saves are full'), acts: [OPEN_SAVES] }, + 'too-big-copy': { label: N_('Too big for the cloud'), head: N_('This save is too big for the cloud'), acts: [OPEN_SAVES] }, + 'too-big-folder': { label: N_('Sync paused'), head: N_('Cloud saves are paused for this game'), acts: [OPEN_SAVES] }, + paused: { label: N_('Cloud saves paused'), head: N_('Cloud saves are paused for now'), acts: [OPEN_SAVES] }, + error: { label: N_('Can\'t upload'), head: N_('The last upload didn\'t go through'), acts: [SYNC_NOW, OPEN_SAVES] }, +}; + +// While something runs (from the save-sync event): checking before Play, a save going up or one +// coming down. +const PHASE_BADGE = { + check: { mark: 'check-run', label: N_('Checking cloud…'), head: N_('Looking for a newer save'), text: N_('Before the game starts, the launcher checks whether another PC saved after this one.') }, + up: { mark: 'up', label: N_('Uploading…'), head: N_('Sending your save'), text: N_('Your newest save is going to the cloud.') }, + down: { mark: 'down', label: N_('Getting cloud save…'), head: N_('Bringing in a newer save'), text: N_('Another PC saved after this one. Your current save is kept as a backup first.') }, +}; + +// What the badge shows for a game's status: its tone (ok, cy, warn, bad, dim), the mark inside the +// cloud, a label and a short note, and the details: a heading, a line, rows and buttons +// ([label, act]). `phase` is what's running now, `running` whether the game is. +function saveBadgeInfo(st, phase, running) { + const p = PHASE_BADGE[phase]; + if (p) return { tone: 'cy', mark: p.mark, label: t(p.label), note: '', head: t(p.head), text: t(p.text), rows: [], acts: [] }; + const synced = st.syncedAt ? [[t('Last synced'), whenText(st.syncedAt)], [t('Saved on'), st.syncedDevice || t('this PC')]] : []; + const newest = st.newest ? [[t('Last backup'), `${whenText(st.newest.when)}${st.newest.device ? ' · ' + st.newest.device : ''}`]] : []; + if (st.state === 'signed-out') return { tone: 'dim', mark: 'dash', label: t('Not signed in'), note: '', head: t('Keep this save on any PC'), text: t('Sign in to RecompStore and your saves go to the cloud after you play. It\'s free.'), rows: newest, acts: [[N_('Sign In'), 'acc-signin']] }; + if (st.state === 'off') return { tone: 'dim', mark: 'off', label: t('Cloud saves off'), note: '', head: t('Saves stay on this PC'), text: t('The launcher still keeps a copy after every session.'), rows: newest, acts: [[N_('Turn On'), 'saves-cloud']] }; + if (st.state === 'conflict') return { tone: 'warn', mark: 'conflict', label: t('Choose a save'), note: '', head: t('Both saves changed'), text: t('This PC and the cloud both changed since they last synced. Pick the one to keep; the other stays as a backup on this PC.'), rows: synced, acts: [[N_('Choose a Save'), 'saves-sync']] }; + if (st.state === 'problem') return problemBadge(st, synced); + if (running) return { tone: 'cy', mark: 'play', label: t('Syncs after you play'), note: '', head: t('Playing now'), text: t('Its save goes to the cloud when you close the game.'), rows: synced, acts: [] }; + if (st.state === 'waiting') return waitingBadge(st, synced); + if (st.state === 'up-to-date') return { tone: 'ok', mark: 'check', label: t('Up to date'), note: sinceText(st.syncedAt), head: t('Your save is in the cloud'), text: t('This PC and the cloud have the same save.'), rows: synced, acts: [SYNC_NOW, OPEN_SAVES] }; + return { tone: 'dim', mark: 'dash', label: t('No saves yet'), note: '', head: t('Nothing to sync yet'), text: t('Play it once. Its saves are backed up after, and go to the cloud too.'), rows: [], acts: [] }; +} + +function problemBadge(st, synced) { + const kind = (st.problem && st.problem.kind) || 'error'; + const b = PROBLEM_BADGE[kind] || PROBLEM_BADGE.error; + const text = st.problem && st.problem.text ? t(st.problem.text) : ''; + return { tone: 'bad', mark: 'alert', label: t(b.label), note: b.note ? t(b.note) : '', head: t(b.head), text, rows: synced, acts: b.acts }; +} + +// Saved here and not in the cloud yet: queued after a try that didn't get through (with when the +// next one is), or going up after the next session. +function waitingBadge(st, synced) { + const queued = st.waiting > 0; + const offline = st.problem && st.problem.kind === 'offline'; + const minutes = st.retryIn ? Math.max(1, Math.ceil(st.retryIn / 60)) : 0; + const note = minutes ? tn(minutes, 'next try in 1 min', 'next try in {n} min') : offline ? t('offline') : ''; + const text = !queued ? t('It goes up after you play next, or now with Sync Now.') + : offline ? t('The website can\'t be reached right now. Your save is safe here and goes up by itself when it can.') + : t('It goes up by itself on the next try.'); + const rows = queued ? [[t('Waiting'), tn(st.waiting, '1 copy', '{n} copies')], ...synced] : synced; + return { tone: 'warn', mark: 'clock', label: t('Waiting to upload'), note, head: t('Saved on this PC, not in the cloud yet'), text, rows, acts: [[queued ? N_('Try Again') : N_('Sync Now'), 'saves-sync']] }; +} + +// The cloud, with a mark inside it for the state. Drawn the same in both modes. +const BADGE_MARKS = { + check: '', + 'check-run': '', + up: '', + down: '', + clock: '', + alert: '', + conflict: '', + off: '', + dash: '', + play: '', +}; +const badgeIcon = (mark, size = 18) => ``; + +// The badge's info for a game page id, or null while it's not known (or not installed). +function saveBadgeFor(id) { + if (!S.library[parentId(id)]) return null; + const sid = saveIdOf(id); + const st = S.saveStat[sid]; + if (st === undefined) loadSaveStatus(sid); + if (!st) return null; + return saveBadgeInfo(st, S.savePhase[sid], S.running.has(parentId(sid))); +} + +// A details button: Open Saves goes to the tab, Turn On flips cloud saves on, the rest act on the +// game's saves. +function badgeButton([label, act], sid, main) { + const cls = `btn sm${main ? ' main' : ''}`; + if (act === 'tab') return ``; + if (act === 'saves-cloud') return ``; + const busy = act === 'saves-sync' && S.running.has(parentId(sid)); + return ``; +} + +function badgeInner(sid, pageId) { + const b = saveBadgeFor(pageId); + if (!b) return ''; + const open = badgeOpen === sid; + const hot = b.tone === 'warn' || b.tone === 'bad'; + const chip = ``; + if (!open) return chip; + const rows = b.rows.length ? `
${b.rows.map(([k, v]) => `
${esc(k)}
${esc(v)}
`).join('')}
` : ''; + const acts = b.acts.length ? `
${b.acts.map((x, i) => badgeButton(x, sid, i === 0)).join('')}
` : ''; + const pop = ``; + return chip + pop; +} + +// The badge on a game page (beside Play). A full redraw of the page closes its details. +function saveBadge(a) { + if (!S.library[parentId(a.id)]) return ''; + badgeOpen = ''; + const sid = saveIdOf(a.id); + return `
${badgeInner(sid, a.id)}
`; +} + +// Redraws the badges on screen (one game's, or all of them), and Big Picture's game page. +function paintSaveBadges(sid) { + for (const el of $$('[data-save-badge]')) { + if (sid && el.dataset.saveBadge !== sid) continue; + el.innerHTML = badgeInner(el.dataset.saveBadge, el.dataset.page); + } + if (window.tvRefresh && inTV()) window.tvRefresh(); +} + +function closeBadge() { + if (!badgeOpen) return; + badgeOpen = ''; + paintSaveBadges(); +} + +// Its details close on a click anywhere else, on a button in them, and on Escape. +document.addEventListener('click', (e) => { + if (!badgeOpen) return; + const inside = e.target.closest('.sbadge'); + const acted = e.target.closest('.sbadge-pop [data-act]'); + if (inside && !acted) return; + setTimeout(closeBadge, 0); +}); +document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeBadge(); }); + +// Signed in or out, or the cloud changed: every game's status is asked again. +function forgetSaveStatus() { + S.saveStat = {}; + S.savePhase = {}; + paintSaveBadges(); +} + +window.saveBadge = saveBadge; +window.saveBadgeFor = saveBadgeFor; +window.saveBadgeIcon = badgeIcon; +window.paintSaveBadges = paintSaveBadges; + // ---------- the Saves page: every game's saves in one place ---------- const CARD_ICON = ''; let savesAllBusy = null; @@ -428,6 +621,10 @@ window.accountAct = async (act, el) => { if (ok && S.account && !S.account.offline) toast(t('Connected again.')); return render(true); } + case 'saves-badge': { + badgeOpen = badgeOpen === id ? '' : id; + return paintSaveBadges(id); + } case 'saves-sync': { if (S.saves[id]?.busy) return; el.disabled = true; @@ -520,8 +717,20 @@ window.accountAct = async (act, el) => { return null; }; -T.event.listen('account', ({ payload }) => { if (payload && payload.signedIn === false) { S.account = { signedIn: false }; S.saves = {}; renderAccountBits(); if (window.afterSignIn) window.afterSignIn(); } else loadAccount(true); }); -T.event.listen('saves', ({ payload }) => { if (S.view === 'saves') loadSavesAll(); if (payload && payload.id) { delete S.saves[payload.id]; if (S.view === 'game' && S.arg === payload.id && S.tab === 'saves') loadSaves(payload.id); } }); +T.event.listen('account', ({ payload }) => { if (payload && payload.signedIn === false) { S.account = { signedIn: false }; S.saves = {}; forgetSaveStatus(); renderAccountBits(); if (window.afterSignIn) window.afterSignIn(); } else loadAccount(true); }); +T.event.listen('saves', ({ payload }) => { if (S.view === 'saves') loadSavesAll(); if (payload && payload.id) { delete S.saves[payload.id]; loadSaveStatus(payload.id); if (S.view === 'game' && S.arg === payload.id && S.tab === 'saves') loadSaves(payload.id); } }); +// A check, upload or download for a game started or ended: the badge says so, and asks for the +// outcome once it's over. +T.event.listen('save-sync', ({ payload }) => { + const sid = payload && payload.id; + if (!sid) return; + if (payload.phase !== 'idle') { + S.savePhase[sid] = payload.phase; + return paintSaveBadges(sid); + } + delete S.savePhase[sid]; + loadSaveStatus(sid); +}); // Who's signed in: what's remembered first, then the website's answer. loadAccount(false).then(() => loadAccount(true)); diff --git a/ui/app.css b/ui/app.css index dcb97948..c5b9384a 100644 --- a/ui/app.css +++ b/ui/app.css @@ -2571,3 +2571,32 @@ body.light .su-req{color:#8a5300} .poster.cvl-on .badge.tl,.poster.cvl-on .badge.tr,.poster.cvl-on .badge.rank{top:calc(var(--cvl-top) * 100% + 9px)} .poster.cvl-on .badge.tl.low{top:calc(var(--cvl-top) * 100% + 41px)} .tv-poster.cvl-on .tv-badge,.tv-poster.cvl-on .tv-rank{top:calc(var(--cvl-top) * 100% + 12px)} +/* The cloud save badge beside Play, and its details (account.js). Its colour says the state: + green in the cloud, cyan working, amber waiting or a choice, red stuck, grey no cloud. */ +.sbadge{position:relative;--sb-ok:#3ee08f;--sb-warn:var(--warn);--sb-bad:var(--bad)} +body.light .sbadge{--sb-ok:#127a45;--sb-warn:#9a6200;--sb-bad:#c53030} +.sbadge .sb-ok{--c:var(--sb-ok)}.sbadge .sb-cy{--c:var(--cyan)}.sbadge .sb-warn{--c:var(--sb-warn)}.sbadge .sb-bad{--c:var(--sb-bad)}.sbadge .sb-dim{--c:var(--dim)} +.sbadge-chip{display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 13px 0 10px;border-radius:11px;border:1px solid var(--line2);background:color-mix(in srgb,var(--card) 70%,transparent);backdrop-filter:blur(14px);color:var(--ink);font:700 13px Figtree,sans-serif;white-space:nowrap;cursor:pointer;transition:border-color .15s,background-color .15s} +.sbadge-chip:hover,.sbadge-chip[aria-expanded=true]{border-color:var(--line3);background:var(--card2)} +.sbadge-chip svg{color:var(--c);flex:none} +.sbadge-chip small{font-weight:500;font-size:12.5px;color:var(--muted)} +.sbadge-chip small::before{content:"· "} +.sbadge-chip.hot{border-color:color-mix(in srgb,var(--c) 45%,transparent);background:color-mix(in srgb,var(--c) 10%,var(--card))} +.sbadge-chip.hot b{color:var(--c)} +.sbadge-pop{position:absolute;top:calc(100% + 8px);inset-inline-end:0;z-index:30;width:340px;max-width:calc(100vw - 48px);padding:16px;border-radius:16px;background:var(--card2);border:1px solid var(--line2);box-shadow:0 24px 60px -20px rgba(0,0,0,.8);display:flex;flex-direction:column;gap:12px;text-align:start;white-space:normal;animation:dropin .16s var(--ease)} +body.light .sbadge-pop{box-shadow:0 12px 40px rgba(14,22,38,.18)} +.sbadge-h{display:flex;gap:12px;align-items:flex-start} +.sbadge-ico{width:38px;height:38px;border-radius:12px;display:grid;place-items:center;flex:none;color:var(--c);background:color-mix(in srgb,var(--c) 14%,transparent)} +.sbadge-h>div>b{display:block;font-size:15px} +.sbadge-h>div>span{display:block;margin-top:2px;font-size:13px;line-height:1.45;color:var(--muted)} +.sbadge-pop dl{margin:0;display:grid;grid-template-columns:auto minmax(0,1fr);gap:4px 14px;padding:10px 12px;border-radius:12px;background:var(--fill);border:1px solid var(--line);font-size:13px} +.sbadge-pop dt{color:var(--dim);font-weight:600} +.sbadge-pop dd{margin:0;text-align:end;font-weight:600;min-width:0;overflow-wrap:anywhere;font-variant-numeric:tabular-nums} +.sbadge-pop .acts{display:flex;gap:8px;flex-wrap:wrap} +@container gp (max-width:1260px){.sbadge-pop{inset-inline-start:0;inset-inline-end:auto}} +@media (max-width:1060px){.gp .sbadge-pop{inset-inline-start:0;inset-inline-end:auto}} +.sb-spin{animation:sbspin 1.1s linear infinite;transform-origin:12px 13px} +.sb-bob{animation:sbbob 1.2s ease-in-out infinite} +@keyframes sbspin{to{transform:rotate(360deg)}} +@keyframes sbbob{50%{transform:translateY(-1.5px)}} +@media (prefers-reduced-motion:reduce){.sb-spin,.sb-bob{animation:none}} diff --git a/ui/app.js b/ui/app.js index d9355aa2..ae7964bd 100644 --- a/ui/app.js +++ b/ui/app.js @@ -2109,7 +2109,7 @@ function pageGame(id) {
${pic(thumbOf(a.cover))}
${kick ? `${esc(kick)}` : ''}

${esc(a.name)}

${partOfLine(a)}${based(a)}${devLine(a)}${verPill(a)}${chips ? `
${chips}
` : ''}${tagsOf(a).length ? `
${tagsOf(a).map((tg) => ``).join('')}
` : ''}
-
${actions(a)}
${replacedNote(a) || betterNote(a) || reinstallNote(a) || badNote(a) || stateNote(a)}${S.library[id] && S.library[id].from_backup ? `

${esc(t('Downloaded from the RecompLauncher backup'))}

` : ''}
${igCard(a)}
+
${actions(a)}
${window.saveBadge ? window.saveBadge(a) : ''}${replacedNote(a) || betterNote(a) || reinstallNote(a) || badNote(a) || stateNote(a)}${S.library[id] && S.library[id].from_backup ? `

${esc(t('Downloaded from the RecompLauncher backup'))}

` : ''}
${igCard(a)}
${includesBox(a)}
${gameTabs(a).map(([k, n, x]) => ``).join('')}
${gameBody(a)}
`; @@ -2634,6 +2634,8 @@ function refreshGame() { $$('.tabs-in button').forEach((b) => { const on = b.dataset.tab === S.tab; b.classList.toggle('on', on); b.setAttribute('aria-selected', String(on)); }); const acts = $(`.gp-acts`); if (acts) morph(acts, actions(a)); + // The cloud save badge: the game started or closed, or its saves changed. + if (window.paintSaveBadges) window.paintSaveBadges(); const main = $('#main'), top = main.scrollTop; const body = $('#g-body'); body.classList.add('still'); From 7d2d4a38888bd5aac0c104c723381cc7e942eefb Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 13:10:45 +0000 Subject: [PATCH 02/16] Big Picture: the cloud save badge beside Play The same state as on the desktop, among the game's buttons; A opens its Saves. --- ui/tv.css | 6 ++++++ ui/tv.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/ui/tv.css b/ui/tv.css index 3e150459..1ba14374 100644 --- a/ui/tv.css +++ b/ui/tv.css @@ -1026,3 +1026,9 @@ body.linux .tv-boot .aurora i{filter:none;mix-blend-mode:normal} .tv-rail.box{right:auto;bottom:auto} .tv-rail i{position:absolute;left:0;top:0;width:100%;border-radius:6px;background:var(--acc,#34F2E8);opacity:.75;transition:transform .35s cubic-bezier(.2,.8,.2,1),height .2s} .tv-rail[hidden]{display:none} +/* The cloud save badge among a game's buttons (account.js decides the state): the cloud takes the + state's colour, and a state that needs the player tints the button. */ +.tv-sbadge{--c:#8B97AA} +.tv-sbadge.sb-ok{--c:#3ee08f}.tv-sbadge.sb-cy{--c:#34F2E8}.tv-sbadge.sb-warn{--c:#f5b83d}.tv-sbadge.sb-bad{--c:#ff7a7a} +.tv-sbadge svg{color:var(--c)} +.tv-sbadge.sb-warn,.tv-sbadge.sb-bad{border-color:color-mix(in srgb,var(--c) 50%,transparent);background:color-mix(in srgb,var(--c) 14%,rgba(var(--tvrgb),.6))} diff --git a/ui/tv.js b/ui/tv.js index 5f98c6b4..4157704f 100644 --- a/ui/tv.js +++ b/ui/tv.js @@ -1467,8 +1467,13 @@ ...(modsOk && g ? [[esc(t('Mods')), esc(tf('{n} installed', { n: (S.mods[id].installed || []).length }))]] : []), ]; const bad = checks.filter((r) => r.v === false).length; + // Where its saves stand (account.js), beside Play as on the desktop; A opens its Saves. + const sb = g && window.saveBadgeFor ? window.saveBadgeFor(id) : null; + const sbLabel = sb ? esc(sb.label) + (sb.note ? `${esc(sb.note)}` : '') : ''; + const sbBtn = sb ? `` : ''; const acts = [ mainButton(a, 'g-main'), + sbBtn, // Set Up Again beside Play, marked New while its project has options not answered yet. g && canSetUpAgain(id) ? btn('g-again', 'setup', esc(t('Set Up Again')) + (newPrepOpts(su).length ? `${esc(t('New option'))}` : ''), { id, icon: 'disc' }) : '', !g && needsSetup(a) ? btn('g-sreq', 'setupreq', esc(t('Setup Required')), { cls: 'warn-o', id, icon: 'wrench' }) : '', From 3738d3e48fd71fb2ef956d2790e5dd2ce92701c3 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 13:25:23 +0000 Subject: [PATCH 03/16] The cloud save status sits above Play as a coloured line, not a button It looked clickable as a pill. Now it's the cloud mark and the state's words in the state's colour, above Play on the desktop and above the game's buttons in Big Picture. The details it showed on a click are its tooltip; what to do about it stays on the Saves tab. --- tests/save-badge.test.cjs | 34 ++++++------ ui/account.js | 111 +++++++++++++------------------------- ui/app.css | 30 +++-------- ui/app.js | 2 +- ui/tv.css | 11 ++-- ui/tv.js | 8 +-- 6 files changed, 74 insertions(+), 122 deletions(-) diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs index 63fde2f9..4dd81dd5 100644 --- a/tests/save-badge.test.cjs +++ b/tests/save-badge.test.cjs @@ -22,24 +22,22 @@ const line = (start) => { return account.slice(at, account.indexOf('\n', at)); }; -// The badge's info for a status, with the window's helpers kept to plain English. +// The status line's info for a status, with the window's helpers kept to plain English. const info = new Function(` const N_ = (x) => x, t = (x) => x, tf = (x) => x; const tn = (n, one, many) => (n === 1 ? one : many).replace('{n}', n); const ago = () => 'this week', whenText = (ts) => 'at ' + ts; - ${line('const SYNC_NOW = ')} - ${line('const OPEN_SAVES = ')} ${block('const PROBLEM_BADGE = ')} ${block('const PHASE_BADGE = ')} ${block('function sinceText(')} ${block('function saveBadgeInfo(')} ${block('function problemBadge(')} ${block('function waitingBadge(')} - return { saveBadgeInfo, sinceText };`)(); + ${line('const badgeTip = ')} + return { saveBadgeInfo, sinceText, badgeTip };`)(); const now = () => Math.floor(Date.now() / 1000); const status = (state, more = {}) => ({ state, syncedAt: 0, waiting: 0, retryIn: null, problem: null, newest: null, ...more }); -const acts = (b) => b.acts.map(([label]) => label); test('the same save here and in the cloud is green, with how long ago', () => { const b = info.saveBadgeInfo(status('up-to-date', { syncedAt: now() - 12 * 60, syncedDevice: 'Desk PC' }), undefined, false); @@ -62,14 +60,13 @@ test('a game being played says its save goes up after', () => { test('a conflict still asks for a choice while the game runs', () => { const b = info.saveBadgeInfo(status('conflict'), undefined, true); assert.equal(b.label, 'Choose a save'); - assert.deepEqual(acts(b), ['Choose a Save']); + assert.equal(b.tone, 'warn'); }); -test('a copy queued while offline says so and offers Try Again', () => { +test('a copy queued while offline says so', () => { const b = info.saveBadgeInfo(status('waiting', { waiting: 1, problem: { kind: 'offline', text: '' } }), undefined, false); assert.equal(b.tone, 'warn'); assert.equal(b.note, 'offline'); - assert.deepEqual(acts(b), ['Try Again']); }); test('a copy waiting its next try says when', () => { @@ -77,9 +74,10 @@ test('a copy waiting its next try says when', () => { assert.equal(b.note, 'next try in 4 min'); }); -test('a newer save that goes up after the next session offers Sync Now', () => { +test('a newer save that goes up after the next session has no note', () => { const b = info.saveBadgeInfo(status('waiting'), undefined, false); - assert.deepEqual(acts(b), ['Sync Now']); + assert.equal(b.label, 'Waiting to upload'); + assert.equal(b.note, ''); }); test('a copy too big to send is red and named', () => { @@ -92,24 +90,28 @@ test('a copy too big to send is red and named', () => { test('a problem of a kind it does not know reads as an upload that failed', () => { const b = info.saveBadgeInfo(status('problem', { problem: { kind: 'something-new', text: '' } }), undefined, false); assert.equal(b.label, 'Can\'t upload'); - assert.deepEqual(acts(b), ['Sync Now', 'Open Saves']); }); -test('cloud saves off offers to turn them on', () => { +test('cloud saves off is grey', () => { const b = info.saveBadgeInfo(status('off'), undefined, false); assert.equal(b.tone, 'dim'); - assert.deepEqual(acts(b), ['Turn On']); + assert.equal(b.label, 'Cloud saves off'); }); -test('signed out offers to sign in', () => { +test('signed out says so', () => { const b = info.saveBadgeInfo(status('signed-out'), undefined, false); - assert.deepEqual(acts(b), ['Sign In']); + assert.equal(b.label, 'Not signed in'); }); test('a game never played has nothing to sync', () => { const b = info.saveBadgeInfo(status('none'), undefined, false); assert.equal(b.label, 'No saves yet'); - assert.equal(b.acts.length, 0); +}); + +test('the tooltip says what it means, then when it last synced and where', () => { + const b = info.saveBadgeInfo(status('up-to-date', { syncedAt: 100, syncedDevice: 'Desk PC' }), undefined, false); + const tip = info.badgeTip(b); + assert.equal(tip, 'Your save is in the cloud\nThis PC and the cloud have the same save.\nLast synced: at 100\nSaved on: Desk PC'); }); test('a sync over a day ago falls back to the coarse wording', () => { diff --git a/ui/account.js b/ui/account.js index 015b67ee..c980d8ce 100644 --- a/ui/account.js +++ b/ui/account.js @@ -254,16 +254,15 @@ function copyRow(id, c, k, v, current) { const savesChanged = (id) => { delete S.saves[id]; if (S.view === 'game' && S.arg === id && S.tab === 'saves') loadSaves(id); }; -// ---------- the cloud save badge beside Play ---------- -// Where a game's saves stand, on its page under Play and among Big Picture's game buttons, so the -// player doesn't have to open the Saves tab to see whether the last save reached the cloud. +// ---------- the cloud save status above Play ---------- +// Where a game's saves stand, on its page above Play and above Big Picture's game buttons, so the +// player doesn't have to open the Saves tab to see whether the last save reached the cloud. Only +// a coloured line, not a button: what to do about it is on the Saves tab. Hovering it says more. // saves_status answers from this PC alone (it never asks the website); the save-sync event says // when something runs or ends, and the status is asked again then. S.saveStat = {}; S.savePhase = {}; const statLoading = new Set(); -// The badge whose details are open (its save id), and the popover goes with any full redraw. -let badgeOpen = ''; // A game of several that keeps its own saves goes by its own id; any other by its recomp's. function saveIdOf(id) { @@ -291,17 +290,14 @@ function sinceText(ts) { return ago(ts); } -const SYNC_NOW = [N_('Sync Now'), 'saves-sync']; -const OPEN_SAVES = [N_('Open Saves'), 'tab']; - -// What a problem kept by the last sync looks like on the badge, by its kind. The backend's own -// words say why; these say it short. +// What a problem kept by the last sync looks like, by its kind. The backend's own words say why +// (in the tooltip); these say it short. const PROBLEM_BADGE = { - full: { label: N_('Can\'t upload'), note: N_('cloud full'), head: N_('Your cloud saves are full'), acts: [OPEN_SAVES] }, - 'too-big-copy': { label: N_('Too big for the cloud'), head: N_('This save is too big for the cloud'), acts: [OPEN_SAVES] }, - 'too-big-folder': { label: N_('Sync paused'), head: N_('Cloud saves are paused for this game'), acts: [OPEN_SAVES] }, - paused: { label: N_('Cloud saves paused'), head: N_('Cloud saves are paused for now'), acts: [OPEN_SAVES] }, - error: { label: N_('Can\'t upload'), head: N_('The last upload didn\'t go through'), acts: [SYNC_NOW, OPEN_SAVES] }, + full: { label: N_('Can\'t upload'), note: N_('cloud full'), head: N_('Your cloud saves are full') }, + 'too-big-copy': { label: N_('Too big for the cloud'), head: N_('This save is too big for the cloud') }, + 'too-big-folder': { label: N_('Sync paused'), head: N_('Cloud saves are paused for this game') }, + paused: { label: N_('Cloud saves paused'), head: N_('Cloud saves are paused for now') }, + error: { label: N_('Can\'t upload'), head: N_('The last upload didn\'t go through') }, }; // While something runs (from the save-sync event): checking before Play, a save going up or one @@ -312,29 +308,29 @@ const PHASE_BADGE = { down: { mark: 'down', label: N_('Getting cloud save…'), head: N_('Bringing in a newer save'), text: N_('Another PC saved after this one. Your current save is kept as a backup first.') }, }; -// What the badge shows for a game's status: its tone (ok, cy, warn, bad, dim), the mark inside the -// cloud, a label and a short note, and the details: a heading, a line, rows and buttons -// ([label, act]). `phase` is what's running now, `running` whether the game is. +// What the status line shows for a game: its tone (ok, cy, warn, bad, dim), the mark inside the +// cloud, a label and a short note, and for the tooltip a heading, a line and rows ([label, value]). +// `phase` is what's running now, `running` whether the game is. function saveBadgeInfo(st, phase, running) { const p = PHASE_BADGE[phase]; - if (p) return { tone: 'cy', mark: p.mark, label: t(p.label), note: '', head: t(p.head), text: t(p.text), rows: [], acts: [] }; + if (p) return { tone: 'cy', mark: p.mark, label: t(p.label), note: '', head: t(p.head), text: t(p.text), rows: [] }; const synced = st.syncedAt ? [[t('Last synced'), whenText(st.syncedAt)], [t('Saved on'), st.syncedDevice || t('this PC')]] : []; const newest = st.newest ? [[t('Last backup'), `${whenText(st.newest.when)}${st.newest.device ? ' · ' + st.newest.device : ''}`]] : []; - if (st.state === 'signed-out') return { tone: 'dim', mark: 'dash', label: t('Not signed in'), note: '', head: t('Keep this save on any PC'), text: t('Sign in to RecompStore and your saves go to the cloud after you play. It\'s free.'), rows: newest, acts: [[N_('Sign In'), 'acc-signin']] }; - if (st.state === 'off') return { tone: 'dim', mark: 'off', label: t('Cloud saves off'), note: '', head: t('Saves stay on this PC'), text: t('The launcher still keeps a copy after every session.'), rows: newest, acts: [[N_('Turn On'), 'saves-cloud']] }; - if (st.state === 'conflict') return { tone: 'warn', mark: 'conflict', label: t('Choose a save'), note: '', head: t('Both saves changed'), text: t('This PC and the cloud both changed since they last synced. Pick the one to keep; the other stays as a backup on this PC.'), rows: synced, acts: [[N_('Choose a Save'), 'saves-sync']] }; + if (st.state === 'signed-out') return { tone: 'dim', mark: 'dash', label: t('Not signed in'), note: '', head: t('Keep this save on any PC'), text: t('Sign in to RecompStore and your saves go to the cloud after you play. It\'s free.'), rows: newest }; + if (st.state === 'off') return { tone: 'dim', mark: 'off', label: t('Cloud saves off'), note: '', head: t('Saves stay on this PC'), text: t('The launcher still keeps a copy after every session. Turn cloud saves on in its Saves tab.'), rows: newest }; + if (st.state === 'conflict') return { tone: 'warn', mark: 'conflict', label: t('Choose a save'), note: '', head: t('Both saves changed'), text: t('This PC and the cloud both changed since they last synced. Pick the one to keep with Sync Now in its Saves tab; the other stays as a backup on this PC.'), rows: synced }; if (st.state === 'problem') return problemBadge(st, synced); - if (running) return { tone: 'cy', mark: 'play', label: t('Syncs after you play'), note: '', head: t('Playing now'), text: t('Its save goes to the cloud when you close the game.'), rows: synced, acts: [] }; + if (running) return { tone: 'cy', mark: 'play', label: t('Syncs after you play'), note: '', head: t('Playing now'), text: t('Its save goes to the cloud when you close the game.'), rows: synced }; if (st.state === 'waiting') return waitingBadge(st, synced); - if (st.state === 'up-to-date') return { tone: 'ok', mark: 'check', label: t('Up to date'), note: sinceText(st.syncedAt), head: t('Your save is in the cloud'), text: t('This PC and the cloud have the same save.'), rows: synced, acts: [SYNC_NOW, OPEN_SAVES] }; - return { tone: 'dim', mark: 'dash', label: t('No saves yet'), note: '', head: t('Nothing to sync yet'), text: t('Play it once. Its saves are backed up after, and go to the cloud too.'), rows: [], acts: [] }; + if (st.state === 'up-to-date') return { tone: 'ok', mark: 'check', label: t('Up to date'), note: sinceText(st.syncedAt), head: t('Your save is in the cloud'), text: t('This PC and the cloud have the same save.'), rows: synced }; + return { tone: 'dim', mark: 'dash', label: t('No saves yet'), note: '', head: t('Nothing to sync yet'), text: t('Play it once. Its saves are backed up after, and go to the cloud too.'), rows: [] }; } function problemBadge(st, synced) { const kind = (st.problem && st.problem.kind) || 'error'; const b = PROBLEM_BADGE[kind] || PROBLEM_BADGE.error; const text = st.problem && st.problem.text ? t(st.problem.text) : ''; - return { tone: 'bad', mark: 'alert', label: t(b.label), note: b.note ? t(b.note) : '', head: t(b.head), text, rows: synced, acts: b.acts }; + return { tone: 'bad', mark: 'alert', label: t(b.label), note: b.note ? t(b.note) : '', head: t(b.head), text, rows: synced }; } // Saved here and not in the cloud yet: queued after a try that didn't get through (with when the @@ -344,11 +340,11 @@ function waitingBadge(st, synced) { const offline = st.problem && st.problem.kind === 'offline'; const minutes = st.retryIn ? Math.max(1, Math.ceil(st.retryIn / 60)) : 0; const note = minutes ? tn(minutes, 'next try in 1 min', 'next try in {n} min') : offline ? t('offline') : ''; - const text = !queued ? t('It goes up after you play next, or now with Sync Now.') + const text = !queued ? t('It goes up after you play next, or now with Sync Now in its Saves tab.') : offline ? t('The website can\'t be reached right now. Your save is safe here and goes up by itself when it can.') : t('It goes up by itself on the next try.'); const rows = queued ? [[t('Waiting'), tn(st.waiting, '1 copy', '{n} copies')], ...synced] : synced; - return { tone: 'warn', mark: 'clock', label: t('Waiting to upload'), note, head: t('Saved on this PC, not in the cloud yet'), text, rows, acts: [[queued ? N_('Try Again') : N_('Sync Now'), 'saves-sync']] }; + return { tone: 'warn', mark: 'clock', label: t('Waiting to upload'), note, head: t('Saved on this PC, not in the cloud yet'), text, rows }; } // The cloud, with a mark inside it for the state. Drawn the same in both modes. @@ -366,72 +362,43 @@ const BADGE_MARKS = { }; const badgeIcon = (mark, size = 18) => ``; -// The badge's info for a game page id, or null while it's not known (or not installed). +// The tooltip: the heading, its line, then each row on its own line. +const badgeTip = (b) => [b.head, b.text, ...b.rows.map(([k, v]) => `${k}: ${v}`)].filter(Boolean).join('\n'); + +// The status for a game page id, or null while it's not known (or not installed). function saveBadgeFor(id) { if (!S.library[parentId(id)]) return null; const sid = saveIdOf(id); const st = S.saveStat[sid]; if (st === undefined) loadSaveStatus(sid); if (!st) return null; - return saveBadgeInfo(st, S.savePhase[sid], S.running.has(parentId(sid))); + const b = saveBadgeInfo(st, S.savePhase[sid], S.running.has(parentId(sid))); + return { ...b, tip: badgeTip(b) }; } -// A details button: Open Saves goes to the tab, Turn On flips cloud saves on, the rest act on the -// game's saves. -function badgeButton([label, act], sid, main) { - const cls = `btn sm${main ? ' main' : ''}`; - if (act === 'tab') return ``; - if (act === 'saves-cloud') return ``; - const busy = act === 'saves-sync' && S.running.has(parentId(sid)); - return ``; -} - -function badgeInner(sid, pageId) { +function badgeInner(pageId) { const b = saveBadgeFor(pageId); if (!b) return ''; - const open = badgeOpen === sid; - const hot = b.tone === 'warn' || b.tone === 'bad'; - const chip = ``; - if (!open) return chip; - const rows = b.rows.length ? `
${b.rows.map(([k, v]) => `
${esc(k)}
${esc(v)}
`).join('')}
` : ''; - const acts = b.acts.length ? `
${b.acts.map((x, i) => badgeButton(x, sid, i === 0)).join('')}
` : ''; - const pop = ``; - return chip + pop; + const note = b.note ? `${esc(b.note)}` : ''; + return `${badgeIcon(b.mark)}${esc(b.label)}${note}`; } -// The badge on a game page (beside Play). A full redraw of the page closes its details. +// The status on a game page, above Play. It says changes out loud to a screen reader. function saveBadge(a) { if (!S.library[parentId(a.id)]) return ''; - badgeOpen = ''; const sid = saveIdOf(a.id); - return `
${badgeInner(sid, a.id)}
`; + return `
${badgeInner(a.id)}
`; } -// Redraws the badges on screen (one game's, or all of them), and Big Picture's game page. +// Redraws the status lines on screen (one game's, or all of them), and Big Picture's game page. function paintSaveBadges(sid) { for (const el of $$('[data-save-badge]')) { if (sid && el.dataset.saveBadge !== sid) continue; - el.innerHTML = badgeInner(el.dataset.saveBadge, el.dataset.page); + el.innerHTML = badgeInner(el.dataset.page); } if (window.tvRefresh && inTV()) window.tvRefresh(); } -function closeBadge() { - if (!badgeOpen) return; - badgeOpen = ''; - paintSaveBadges(); -} - -// Its details close on a click anywhere else, on a button in them, and on Escape. -document.addEventListener('click', (e) => { - if (!badgeOpen) return; - const inside = e.target.closest('.sbadge'); - const acted = e.target.closest('.sbadge-pop [data-act]'); - if (inside && !acted) return; - setTimeout(closeBadge, 0); -}); -document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeBadge(); }); - // Signed in or out, or the cloud changed: every game's status is asked again. function forgetSaveStatus() { S.saveStat = {}; @@ -621,10 +588,6 @@ window.accountAct = async (act, el) => { if (ok && S.account && !S.account.offline) toast(t('Connected again.')); return render(true); } - case 'saves-badge': { - badgeOpen = badgeOpen === id ? '' : id; - return paintSaveBadges(id); - } case 'saves-sync': { if (S.saves[id]?.busy) return; el.disabled = true; diff --git a/ui/app.css b/ui/app.css index c5b9384a..28c62240 100644 --- a/ui/app.css +++ b/ui/app.css @@ -2571,30 +2571,16 @@ body.light .su-req{color:#8a5300} .poster.cvl-on .badge.tl,.poster.cvl-on .badge.tr,.poster.cvl-on .badge.rank{top:calc(var(--cvl-top) * 100% + 9px)} .poster.cvl-on .badge.tl.low{top:calc(var(--cvl-top) * 100% + 41px)} .tv-poster.cvl-on .tv-badge,.tv-poster.cvl-on .tv-rank{top:calc(var(--cvl-top) * 100% + 12px)} -/* The cloud save badge beside Play, and its details (account.js). Its colour says the state: - green in the cloud, cyan working, amber waiting or a choice, red stuck, grey no cloud. */ -.sbadge{position:relative;--sb-ok:#3ee08f;--sb-warn:var(--warn);--sb-bad:var(--bad)} +/* The cloud save status above Play (account.js): a coloured line, not a button. Its colour says + the state: green in the cloud, cyan working, amber waiting or a choice, red stuck, grey no + cloud. The tooltip says more. */ +.sbadge{--sb-ok:#3ee08f;--sb-warn:var(--warn);--sb-bad:var(--bad);min-height:20px} body.light .sbadge{--sb-ok:#127a45;--sb-warn:#9a6200;--sb-bad:#c53030} .sbadge .sb-ok{--c:var(--sb-ok)}.sbadge .sb-cy{--c:var(--cyan)}.sbadge .sb-warn{--c:var(--sb-warn)}.sbadge .sb-bad{--c:var(--sb-bad)}.sbadge .sb-dim{--c:var(--dim)} -.sbadge-chip{display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 13px 0 10px;border-radius:11px;border:1px solid var(--line2);background:color-mix(in srgb,var(--card) 70%,transparent);backdrop-filter:blur(14px);color:var(--ink);font:700 13px Figtree,sans-serif;white-space:nowrap;cursor:pointer;transition:border-color .15s,background-color .15s} -.sbadge-chip:hover,.sbadge-chip[aria-expanded=true]{border-color:var(--line3);background:var(--card2)} -.sbadge-chip svg{color:var(--c);flex:none} -.sbadge-chip small{font-weight:500;font-size:12.5px;color:var(--muted)} -.sbadge-chip small::before{content:"· "} -.sbadge-chip.hot{border-color:color-mix(in srgb,var(--c) 45%,transparent);background:color-mix(in srgb,var(--c) 10%,var(--card))} -.sbadge-chip.hot b{color:var(--c)} -.sbadge-pop{position:absolute;top:calc(100% + 8px);inset-inline-end:0;z-index:30;width:340px;max-width:calc(100vw - 48px);padding:16px;border-radius:16px;background:var(--card2);border:1px solid var(--line2);box-shadow:0 24px 60px -20px rgba(0,0,0,.8);display:flex;flex-direction:column;gap:12px;text-align:start;white-space:normal;animation:dropin .16s var(--ease)} -body.light .sbadge-pop{box-shadow:0 12px 40px rgba(14,22,38,.18)} -.sbadge-h{display:flex;gap:12px;align-items:flex-start} -.sbadge-ico{width:38px;height:38px;border-radius:12px;display:grid;place-items:center;flex:none;color:var(--c);background:color-mix(in srgb,var(--c) 14%,transparent)} -.sbadge-h>div>b{display:block;font-size:15px} -.sbadge-h>div>span{display:block;margin-top:2px;font-size:13px;line-height:1.45;color:var(--muted)} -.sbadge-pop dl{margin:0;display:grid;grid-template-columns:auto minmax(0,1fr);gap:4px 14px;padding:10px 12px;border-radius:12px;background:var(--fill);border:1px solid var(--line);font-size:13px} -.sbadge-pop dt{color:var(--dim);font-weight:600} -.sbadge-pop dd{margin:0;text-align:end;font-weight:600;min-width:0;overflow-wrap:anywhere;font-variant-numeric:tabular-nums} -.sbadge-pop .acts{display:flex;gap:8px;flex-wrap:wrap} -@container gp (max-width:1260px){.sbadge-pop{inset-inline-start:0;inset-inline-end:auto}} -@media (max-width:1060px){.gp .sbadge-pop{inset-inline-start:0;inset-inline-end:auto}} +.sbadge-line{display:inline-flex;align-items:center;gap:7px;font:700 13.5px Figtree,sans-serif;color:var(--c);white-space:nowrap;cursor:default} +.sbadge-line svg{flex:none} +.sbadge-line small{font-weight:500;font-size:12.5px;color:var(--muted)} +.sbadge-line small::before{content:"· "} .sb-spin{animation:sbspin 1.1s linear infinite;transform-origin:12px 13px} .sb-bob{animation:sbbob 1.2s ease-in-out infinite} @keyframes sbspin{to{transform:rotate(360deg)}} diff --git a/ui/app.js b/ui/app.js index ae7964bd..0fee6d8c 100644 --- a/ui/app.js +++ b/ui/app.js @@ -2109,7 +2109,7 @@ function pageGame(id) {
${pic(thumbOf(a.cover))}
${kick ? `${esc(kick)}` : ''}

${esc(a.name)}

${partOfLine(a)}${based(a)}${devLine(a)}${verPill(a)}${chips ? `
${chips}
` : ''}${tagsOf(a).length ? `
${tagsOf(a).map((tg) => ``).join('')}
` : ''}
-
${actions(a)}
${window.saveBadge ? window.saveBadge(a) : ''}${replacedNote(a) || betterNote(a) || reinstallNote(a) || badNote(a) || stateNote(a)}${S.library[id] && S.library[id].from_backup ? `

${esc(t('Downloaded from the RecompLauncher backup'))}

` : ''}
${igCard(a)}
+
${window.saveBadge ? window.saveBadge(a) : ''}
${actions(a)}
${replacedNote(a) || betterNote(a) || reinstallNote(a) || badNote(a) || stateNote(a)}${S.library[id] && S.library[id].from_backup ? `

${esc(t('Downloaded from the RecompLauncher backup'))}

` : ''}
${igCard(a)}
${includesBox(a)}
${gameTabs(a).map(([k, n, x]) => ``).join('')}
${gameBody(a)}
`; diff --git a/ui/tv.css b/ui/tv.css index 1ba14374..ccdc798e 100644 --- a/ui/tv.css +++ b/ui/tv.css @@ -1026,9 +1026,10 @@ body.linux .tv-boot .aurora i{filter:none;mix-blend-mode:normal} .tv-rail.box{right:auto;bottom:auto} .tv-rail i{position:absolute;left:0;top:0;width:100%;border-radius:6px;background:var(--acc,#34F2E8);opacity:.75;transition:transform .35s cubic-bezier(.2,.8,.2,1),height .2s} .tv-rail[hidden]{display:none} -/* The cloud save badge among a game's buttons (account.js decides the state): the cloud takes the - state's colour, and a state that needs the player tints the button. */ -.tv-sbadge{--c:#8B97AA} +/* The cloud save status above a game's buttons (account.js decides the state): a coloured line, + not a button, as on the desktop. */ +.tv-sbadge{--c:#8B97AA;margin:0;display:inline-flex;align-items:center;gap:10px;font-size:22px;font-weight:700;color:var(--c)} .tv-sbadge.sb-ok{--c:#3ee08f}.tv-sbadge.sb-cy{--c:#34F2E8}.tv-sbadge.sb-warn{--c:#f5b83d}.tv-sbadge.sb-bad{--c:#ff7a7a} -.tv-sbadge svg{color:var(--c)} -.tv-sbadge.sb-warn,.tv-sbadge.sb-bad{border-color:color-mix(in srgb,var(--c) 50%,transparent);background:color-mix(in srgb,var(--c) 14%,rgba(var(--tvrgb),.6))} +.tv-sbadge svg{flex:none} +.tv-sbadge small{font-size:20px;font-weight:600;color:var(--tvsoft,#c9d3e0)} +.tv-sbadge small::before{content:"· "} diff --git a/ui/tv.js b/ui/tv.js index 4157704f..0e74e8a7 100644 --- a/ui/tv.js +++ b/ui/tv.js @@ -1467,13 +1467,12 @@ ...(modsOk && g ? [[esc(t('Mods')), esc(tf('{n} installed', { n: (S.mods[id].installed || []).length }))]] : []), ]; const bad = checks.filter((r) => r.v === false).length; - // Where its saves stand (account.js), beside Play as on the desktop; A opens its Saves. + // Where its saves stand (account.js), above the buttons as on the desktop: a line, not a button. const sb = g && window.saveBadgeFor ? window.saveBadgeFor(id) : null; - const sbLabel = sb ? esc(sb.label) + (sb.note ? `${esc(sb.note)}` : '') : ''; - const sbBtn = sb ? `` : ''; + const sbNote = sb && sb.note ? `${esc(sb.note)}` : ''; + const sbLine = sb ? `

${window.saveBadgeIcon(sb.mark, 26)}${esc(sb.label)}${sbNote}

` : ''; const acts = [ mainButton(a, 'g-main'), - sbBtn, // Set Up Again beside Play, marked New while its project has options not answered yet. g && canSetUpAgain(id) ? btn('g-again', 'setup', esc(t('Set Up Again')) + (newPrepOpts(su).length ? `${esc(t('New option'))}` : ''), { id, icon: 'disc' }) : '', !g && needsSetup(a) ? btn('g-sreq', 'setupreq', esc(t('Setup Required')), { cls: 'warn-o', id, icon: 'wrench' }) : '', @@ -1508,6 +1507,7 @@ ${a.parent ? `

${a.menuPick ? `${esc(t('Pick the game in its menu when it starts.'))}` : ''}

` : ''} ${a.game && !a.parent ? `

${DISC_S.replace(/14/g, '24')}${htmlIn(t('Based on {game}'), { game: `${esc(a.game)}` })}${needsSetup(a) && !setupDone(id) ? `${svg('wrench', 20)}${esc(t('Setup Required'))}` : S.easy.has(id) ? `${esc(t('Easy Setup'))}` : ''}

` : ''} ${play?.last_played ? `

${esc(tf('{time} played · last played {when}', { time: playedFor(play), when: ago(play.last_played) }))}

` : ''} + ${sbLine}
${acts}
${stNote} ${tagsOf(a).length ? `
${tagsOf(a).map((tg) => ``).join('')}
` : ''} From 41a3311b6fdcb1489cd8375fcce4b4cd053df74f Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 13:47:10 +0000 Subject: [PATCH 04/16] Which save to keep: the two saves are the choices, and the newer one says so On the desktop the cards for this PC's save and the cloud's are what the player clicks (no buttons under them), with what happens to the other under the question. The one saved later has a green Newer beside its heading; in Big Picture beside its label in the sheet. ask() can show any choice as cards this way. --- tests/save-badge.test.cjs | 15 +++++++++++++++ ui/account.js | 38 +++++++++++++++++++++++++++++++------- ui/app.css | 4 ++++ ui/tv.css | 2 ++ ui/tv.js | 2 +- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs index 4dd81dd5..07cb124b 100644 --- a/tests/save-badge.test.cjs +++ b/tests/save-badge.test.cjs @@ -117,3 +117,18 @@ test('the tooltip says what it means, then when it last synced and where', () => test('a sync over a day ago falls back to the coarse wording', () => { assert.equal(info.sinceText(now() - 3 * 86400), 'this week'); }); + +// Which save the conflict dialog marks Newer. +const newerSave = new Function(`${block('function newerSave(')} return newerSave;`)(); + +test('this PC saved after the cloud copy: this PC is newer', () => { + assert.equal(newerSave({ when: 200 }, { made: 100 }), 'local'); +}); + +test('the cloud copy saved after this PC: the cloud one is newer', () => { + assert.equal(newerSave({ when: 100 }, { made: 200 }), 'cloud'); +}); + +test('saved at the same second: neither is marked', () => { + assert.equal(newerSave({ when: 100 }, { made: 100 }), ''); +}); diff --git a/ui/account.js b/ui/account.js index c980d8ce..dfe416b7 100644 --- a/ui/account.js +++ b/ui/account.js @@ -482,16 +482,21 @@ window.loadSavesAll = loadSavesAll; // ---------- before Play ---------- // Asks once per game, while signed in, whether its saves go to the cloud; then brings in a newer // save from another PC, or asks which to keep. false: don't start it. -async function ask(title, text, buttons) { +// `cards`: on the desktop the choices are big cards to click (a heading, a green tag such as +// Newer, and their `lines`), not buttons under the text. Big Picture's sheet is the same either way. +async function ask(title, text, buttons, cards) { if (inTV() && window.tvAsk) { // A button marked last (one that changes things for good) goes to the end of the list, away from the first focus. const list = buttons.filter((b) => !b.last).concat(buttons.filter((b) => b.last)); - const i = await window.tvAsk(title, list.map((b) => ({ label: b.label, sub: b.sub, icon: b.icon }))); + const i = await window.tvAsk(title, list.map((b) => ({ label: b.label, sub: b.sub, tag: b.tag, icon: b.icon }))); return i == null || i < 0 ? null : list[i].v; } + const card = (b, i) => ``; + const button = (b, i) => ``; + const choices = cards ? `
${buttons.map(card).join('')}
` : `
${buttons.map(button).join('')}
`; return new Promise((res) => { let picked = null; - const box = modal(`

${esc(title)}

${text}
${buttons.map((b, i) => ``).join('')}
`, (x, close) => { + const box = modal(`

${esc(title)}

${text}${choices}`, (x, close) => { const i = Number(String(x.dataset.x).slice(1)); if (!isNaN(i) && buttons[i]) { picked = buttons[i].v; close(); } }, title); @@ -551,15 +556,34 @@ async function beforeCloudPlay(id) { } async function pickCloudSave(id, { local, cloud }) { - const card = (h, when, dev, played) => `
${esc(h)}${esc(whenText(when))}${esc(dev)}${esc(tf('Played {time} in all', { time: fmtTime(played) }))}
`; - const v = await ask(t('Which save do you want?'), `
${card(t('This PC'), local.when, local.device, local.played)}${card(t('Cloud'), cloud.made, cloud.device, cloud.played)}

${esc(t('The other one is kept as a copy on its Saves tab, so nothing is lost.'))}

`, - [{ label: t('Keep this PC\'s'), sub: `${whenText(local.when)} · ${local.device}`, icon: 'desk', v: 'local' }, { label: t('Use the cloud one'), sub: `${whenText(cloud.made)} · ${cloud.device}`, icon: 'check', v: 'cloud' }]); - if (v == null) return false; + const v = await chooseSave(local, cloud); + if (v !== 'local' && v !== 'cloud') return false; await invoke('saves_pick', { id, keep: v, localHash: local.hash, cloudVersion: cloud.v }); toast(t(v === 'cloud' ? 'The cloud save is in place.' : 'Your save is in the cloud.')); return true; } +// Which of the two saves is newer ('local' or 'cloud'), or '' when they were saved at the same time. +function newerSave(local, cloud) { + if (local.when > cloud.made) return 'local'; + if (cloud.made > local.when) return 'cloud'; + return ''; +} + +// Both saves changed: the player picks one. On the desktop the two saves are the choices +// themselves (cards to click, no buttons under them); in Big Picture they're the sheet's two +// items. The newer one says so, and what happens to the other is said under the question. +function chooseSave(local, cloud) { + const newer = newerSave(local, cloud); + const tag = (k) => (k === newer ? t('Newer') : ''); + const played = (secs) => tf('Played {time} in all', { time: fmtTime(secs) }); + const note = `

${esc(t('The other one is kept as a copy on its Saves tab, so nothing is lost.'))}

`; + return ask(t('Which save do you want?'), note, [ + { label: t('Keep this PC\'s'), sub: `${whenText(local.when)} · ${local.device}`, lines: [whenText(local.when), local.device, played(local.played)], tag: tag('local'), icon: 'desk', v: 'local' }, + { label: t('Use the cloud one'), sub: `${whenText(cloud.made)} · ${cloud.device}`, lines: [whenText(cloud.made), cloud.device, played(cloud.played)], tag: tag('cloud'), icon: 'check', v: 'cloud' }, + ], true); +} + async function syncCloudNow(id) { const r = await invoke('saves_check', { id, manual: true }); switch (r.action) { diff --git a/ui/app.css b/ui/app.css index 28c62240..1141d484 100644 --- a/ui/app.css +++ b/ui/app.css @@ -2586,3 +2586,7 @@ body.light .sbadge{--sb-ok:#127a45;--sb-warn:#9a6200;--sb-bad:#c53030} @keyframes sbspin{to{transform:rotate(360deg)}} @keyframes sbbob{50%{transform:translateY(-1.5px)}} @media (prefers-reduced-motion:reduce){.sb-spin,.sb-bob{animation:none}} +/* "Newer" on the save that was made later, when both changed: a green word, not a pill. */ +.pick-newer{margin-left:6px;font-style:normal;font-size:12.5px;font-weight:700;color:#3ee08f} +body.light .pick-newer{color:#127a45} +.pick-note{margin:-4px 0 14px;font-size:13px} diff --git a/ui/tv.css b/ui/tv.css index ccdc798e..c3d14860 100644 --- a/ui/tv.css +++ b/ui/tv.css @@ -1033,3 +1033,5 @@ body.linux .tv-boot .aurora i{filter:none;mix-blend-mode:normal} .tv-sbadge svg{flex:none} .tv-sbadge small{font-size:20px;font-weight:600;color:var(--tvsoft,#c9d3e0)} .tv-sbadge small::before{content:"· "} +/* "Newer" beside a sheet item's label (the save made later, when both changed): green text. */ +.tv-newer{margin-left:12px;font-style:normal;font-size:19px;font-weight:700;color:#3ee08f} diff --git a/ui/tv.js b/ui/tv.js index 0e74e8a7..be2e5132 100644 --- a/ui/tv.js +++ b/ui/tv.js @@ -1738,7 +1738,7 @@ TV.sheet = { items, prev: (focused() || {}).dataset?.key }; const el = document.createElement('div'); el.className = 'tv-sheet' + (cls ? ' ' + cls : ''); - el.innerHTML = `
${head || `

${esc(title)}

`}${items.map((x, i) => `${x.gap ? '
' : ''}`).join('')}
`; + el.innerHTML = `
${head || `

${esc(title)}

`}${items.map((x, i) => `${x.gap ? '
' : ''}`).join('')}
`; stage().append(el); focus($('[data-sheet="0"]', el), true); sfx('open'); From 167261d7bb4862ce41dd6b981804a8ef5885b4b2 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 13:55:48 +0000 Subject: [PATCH 05/16] Big Picture: the cloud save choice has a cloud, not a tick --- ui/account.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/account.js b/ui/account.js index dfe416b7..e6162c24 100644 --- a/ui/account.js +++ b/ui/account.js @@ -580,7 +580,7 @@ function chooseSave(local, cloud) { const note = `

${esc(t('The other one is kept as a copy on its Saves tab, so nothing is lost.'))}

`; return ask(t('Which save do you want?'), note, [ { label: t('Keep this PC\'s'), sub: `${whenText(local.when)} · ${local.device}`, lines: [whenText(local.when), local.device, played(local.played)], tag: tag('local'), icon: 'desk', v: 'local' }, - { label: t('Use the cloud one'), sub: `${whenText(cloud.made)} · ${cloud.device}`, lines: [whenText(cloud.made), cloud.device, played(cloud.played)], tag: tag('cloud'), icon: 'check', v: 'cloud' }, + { label: t('Use the cloud one'), sub: `${whenText(cloud.made)} · ${cloud.device}`, lines: [whenText(cloud.made), cloud.device, played(cloud.played)], tag: tag('cloud'), icon: 'cloud', v: 'cloud' }, ], true); } From eb77cf4c0a7a140686ab256033492958c8a863b0 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 13:59:59 +0000 Subject: [PATCH 06/16] Choose a save's tooltip says Play settles it too, not only Sync Now --- ui/account.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/account.js b/ui/account.js index e6162c24..f0ab7220 100644 --- a/ui/account.js +++ b/ui/account.js @@ -318,7 +318,7 @@ function saveBadgeInfo(st, phase, running) { const newest = st.newest ? [[t('Last backup'), `${whenText(st.newest.when)}${st.newest.device ? ' · ' + st.newest.device : ''}`]] : []; if (st.state === 'signed-out') return { tone: 'dim', mark: 'dash', label: t('Not signed in'), note: '', head: t('Keep this save on any PC'), text: t('Sign in to RecompStore and your saves go to the cloud after you play. It\'s free.'), rows: newest }; if (st.state === 'off') return { tone: 'dim', mark: 'off', label: t('Cloud saves off'), note: '', head: t('Saves stay on this PC'), text: t('The launcher still keeps a copy after every session. Turn cloud saves on in its Saves tab.'), rows: newest }; - if (st.state === 'conflict') return { tone: 'warn', mark: 'conflict', label: t('Choose a save'), note: '', head: t('Both saves changed'), text: t('This PC and the cloud both changed since they last synced. Pick the one to keep with Sync Now in its Saves tab; the other stays as a backup on this PC.'), rows: synced }; + if (st.state === 'conflict') return { tone: 'warn', mark: 'conflict', label: t('Choose a save'), note: '', head: t('Both saves changed'), text: t('This PC and the cloud both changed since they last synced. Press Play, or Sync Now in its Saves tab, to pick the one to keep; the other stays as a backup on this PC.'), rows: synced }; if (st.state === 'problem') return problemBadge(st, synced); if (running) return { tone: 'cy', mark: 'play', label: t('Syncs after you play'), note: '', head: t('Playing now'), text: t('Its save goes to the cloud when you close the game.'), rows: synced }; if (st.state === 'waiting') return waitingBadge(st, synced); From 009c2546897b7b2b5382922966e76bcbd7eadda8 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 14:03:32 +0000 Subject: [PATCH 07/16] Choose a save says how on the line itself: press Play to pick --- tests/save-badge.test.cjs | 1 + ui/account.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs index 07cb124b..92339dd5 100644 --- a/tests/save-badge.test.cjs +++ b/tests/save-badge.test.cjs @@ -60,6 +60,7 @@ test('a game being played says its save goes up after', () => { test('a conflict still asks for a choice while the game runs', () => { const b = info.saveBadgeInfo(status('conflict'), undefined, true); assert.equal(b.label, 'Choose a save'); + assert.equal(b.note, 'press Play to pick'); assert.equal(b.tone, 'warn'); }); diff --git a/ui/account.js b/ui/account.js index f0ab7220..44ee8cc3 100644 --- a/ui/account.js +++ b/ui/account.js @@ -318,7 +318,7 @@ function saveBadgeInfo(st, phase, running) { const newest = st.newest ? [[t('Last backup'), `${whenText(st.newest.when)}${st.newest.device ? ' · ' + st.newest.device : ''}`]] : []; if (st.state === 'signed-out') return { tone: 'dim', mark: 'dash', label: t('Not signed in'), note: '', head: t('Keep this save on any PC'), text: t('Sign in to RecompStore and your saves go to the cloud after you play. It\'s free.'), rows: newest }; if (st.state === 'off') return { tone: 'dim', mark: 'off', label: t('Cloud saves off'), note: '', head: t('Saves stay on this PC'), text: t('The launcher still keeps a copy after every session. Turn cloud saves on in its Saves tab.'), rows: newest }; - if (st.state === 'conflict') return { tone: 'warn', mark: 'conflict', label: t('Choose a save'), note: '', head: t('Both saves changed'), text: t('This PC and the cloud both changed since they last synced. Press Play, or Sync Now in its Saves tab, to pick the one to keep; the other stays as a backup on this PC.'), rows: synced }; + if (st.state === 'conflict') return { tone: 'warn', mark: 'conflict', label: t('Choose a save'), note: t('press Play to pick'), head: t('Both saves changed'), text: t('This PC and the cloud both changed since they last synced. Press Play, or Sync Now in its Saves tab, to pick the one to keep; the other stays as a backup on this PC.'), rows: synced }; if (st.state === 'problem') return problemBadge(st, synced); if (running) return { tone: 'cy', mark: 'play', label: t('Syncs after you play'), note: '', head: t('Playing now'), text: t('Its save goes to the cloud when you close the game.'), rows: synced }; if (st.state === 'waiting') return waitingBadge(st, synced); From 99555cd9089c0cd8203df8f32af446aef42cb4c1 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 17:02:14 +0000 Subject: [PATCH 08/16] A save folder its developer or RecompLauncher named comes before one the player picked --- src-tauri/src/saves.rs | 58 ++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/src-tauri/src/saves.rs b/src-tauri/src/saves.rs index 227d1de9..5bee2a2e 100644 --- a/src-tauri/src/saves.rs +++ b/src-tauri/src/saves.rs @@ -48,28 +48,30 @@ pub struct Spot { pub from: &'static str, } -/// Where a game's saves are: the player's folders, else the developer's file, else the catalog. -/// Empty when none of them says: the launcher doesn't know where this game saves. +/// Where a game's saves are: the developer's file, else the catalog, else the player's folders. +/// A folder the developer or RecompLauncher named is the right one (the launcher never moves where +/// a game saves, it only reads that folder), so a folder the player picked before one was named +/// isn't used anymore. Empty when nobody says: the launcher doesn't know where this game saves. pub fn spots(dev: &[String], catalog: &[String], g: &Installed) -> Vec { - // The player's own folders: one, or several (a launcher with more than one game in it). + let list = |v: &[String], from: &'static str| v.iter().filter(|t| !t.trim().is_empty()).map(|t| Spot { template: t.trim().to_string(), from }).collect::>(); + let named = list(dev, "developer"); + if !named.is_empty() { + return named; + } + let ours = list(catalog, "catalog"); + if !ours.is_empty() { + return ours; + } + // The player's own folders: one, or several (a launcher with more than one game in it). Not a + // guess (the whole game folder, or files it was seen writing): that backed up caches and build + // folders as saves, and could put the wrong files back. let mut mine: Vec = vec![]; for t in g.save_place.iter().chain(g.more_save_places.iter()).map(|t| t.trim()).filter(|t| !t.is_empty()) { if !mine.iter().any(|m| m == t) { mine.push(t.to_string()); } } - if !mine.is_empty() { - return mine.into_iter().map(|template| Spot { template, from: "player" }).collect(); - } - let list = |v: &[String], from: &'static str| v.iter().filter(|t| !t.trim().is_empty()).map(|t| Spot { template: t.trim().to_string(), from }).collect::>(); - let named = list(dev, "developer"); - if !named.is_empty() { - return named; - } - // Nothing else: a guess (the whole game folder, or files it was seen writing) backed up caches - // and build folders as saves, and could put the wrong files back. The Saves tab says the - // launcher doesn't know, and the player picks the folder. - list(catalog, "catalog") + mine.into_iter().map(|template| Spot { template, from: "player" }).collect() } /// The player's save folders with `dir` added to `now` (the ones it has): refused when it's one of @@ -1278,7 +1280,7 @@ mod tests { assert!(add_place(&two, &d.join("TT-Xbox"), &g).is_err()); g.save_place = Some(two[0].clone()); g.more_save_places = vec![two[1].clone()]; - let s = spots(&["{install}/dev".into()], &[], &g); + let s = spots(&[], &[], &g); assert_eq!(s.iter().map(|x| (x.template.as_str(), x.from)).collect::>(), vec![("{install}/TT-Xbox/saves", "player"), ("{install}/ROTK-Xbox/saves", "player")]); // Both folders' files go in the backup, kept apart. let mut from: Vec = collect(&s, &g).iter().map(|e| e.spot).collect(); @@ -1401,6 +1403,30 @@ mod tests { assert_eq!(s.iter().map(|x| (x.template.as_str(), x.from)).collect::>(), vec![("{install}/save", "developer")]); } + #[test] + fn the_developers_folder_comes_before_one_the_player_picked() { + let mut g = game(Path::new("/games/test")); + g.save_place = Some("{install}/mine".into()); + let s = spots(&["{install}/save".into()], &[], &g); + assert_eq!(s.iter().map(|x| (x.template.as_str(), x.from)).collect::>(), vec![("{install}/save", "developer")]); + } + + #[test] + fn recomplaunchers_folder_comes_before_one_the_player_picked() { + let mut g = game(Path::new("/games/test")); + g.save_place = Some("{install}/mine".into()); + let s = spots(&[], &["{local}/Test/saves".into()], &g); + assert_eq!(s.iter().map(|x| (x.template.as_str(), x.from)).collect::>(), vec![("{local}/Test/saves", "catalog")]); + } + + #[test] + fn the_players_folder_counts_when_nobody_named_one() { + let mut g = game(Path::new("/games/test")); + g.save_place = Some("{install}/mine".into()); + let s = spots(&[], &[], &g); + assert_eq!(s.iter().map(|x| (x.template.as_str(), x.from)).collect::>(), vec![("{install}/mine", "player")]); + } + #[test] fn sharing_keeps_the_previous_save_and_the_source() { let d = tmp("sharing-copy"); From f93e89034320e655af3e013093e9555755d9608a Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 17:08:41 +0000 Subject: [PATCH 09/16] Cloud saves can be deleted from the launcher, and the core says whose save folder it is --- docs/LAUNCHER-API.md | 2 +- src-tauri/src/cloud.rs | 83 ++++++++++++++++++++++++++++++++++++++---- src-tauri/src/lib.rs | 2 +- ui/games.js | 2 +- 4 files changed, 79 insertions(+), 10 deletions(-) diff --git a/docs/LAUNCHER-API.md b/docs/LAUNCHER-API.md index c12ab640..fdd434ce 100644 --- a/docs/LAUNCHER-API.md +++ b/docs/LAUNCHER-API.md @@ -29,7 +29,7 @@ was signed out (from the account page, or the account is gone): the launcher for | `POST ?a=save-delete` | `{"game", "v"}` | | `POST ?a=signout` | This PC's token stops working | -The website keeps the newest five copies per game and 150 MB per account, refuses game files, +The website keeps the newest five copies per game and 300 MB per account, refuses game files, programs and archives inside a copy, and doesn't keep a copy whose `hash` matches the newest one. `hash` is the checksum of the whole set of save files (see `saves::set_hash`), so two PCs with the diff --git a/src-tauri/src/cloud.rs b/src-tauri/src/cloud.rs index 96d6781a..95be365b 100644 --- a/src-tauri/src/cloud.rs +++ b/src-tauri/src/cloud.rs @@ -6,7 +6,7 @@ //! of PCs, so one can be signed out from there. No password ever passes through the launcher. //! //! Cloud saves: after each session a game's new save copy (saves.rs) goes up to the account, which -//! keeps the newest five per game, up to 150 MB in all. Before a game starts, a newer copy from +//! keeps the newest five per game, up to 300 MB in all. Before a game starts, a newer copy from //! another PC is put in place first; if both changed, the player picks. docs/LAUNCHER-API.md has the //! website's side. @@ -143,7 +143,8 @@ fn save_url(action: &str) -> String { /// (When it said so, the size of the copy it refused.) static FULL: Mutex> = Mutex::new(None); static FULL_TOLD: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); -const FULL_TEXT: &str = "Your cloud saves are full (150 MB). Remove old cloud copies to make room; your saves stay on this PC."; +// No size here: the site sets it (300 MB now) and says it in its own answer. +const FULL_TEXT: &str = "Your cloud saves are full. The newest save of each game is always kept, so make room by deleting another game's cloud saves on your account page at recomplauncher.com. Your saves stay on this PC."; const FULL_REST: std::time::Duration = std::time::Duration::from_secs(3600); fn full_now() -> bool { @@ -476,13 +477,24 @@ pub fn spots_of(st: &App, id: &str, g: &Installed) -> Vec { let mut g = g.clone(); g.save_place = Default::default(); g.more_save_places.clear(); - return saves::spots(&p.game.saves, &[], &g); + return named_spots(p.game.saves, vec![], &g); } let cat = crate::cached_catalog(st); let entry = catalog::app(&cat, id).cloned().unwrap_or(Value::Null); - let dev = crate::profile::find(&g.path, &g.repo, &entry).map(|p| p.saves).unwrap_or_default(); + let profile_saves = crate::profile::find(&g.path, &g.repo, &entry).map(|p| p.saves).unwrap_or_default(); let from_cat: Vec = entry.get("saves").and_then(Value::as_array).map(|a| a.iter().filter_map(|x| x.as_str().map(String::from)).collect()).unwrap_or_default(); - saves::spots(&dev, &from_cat, g) + named_spots(profile_saves, from_cat, g) +} + +/// The save folders a profile names are the developer's only when the profile came with the +/// game's own release. One RecompLauncher keeps for the game (in the catalog, or built into the +/// launcher) is ours, and the Saves tab says so: "Set by RecompLauncher". +fn named_spots(profile_saves: Vec, from_cat: Vec, g: &Installed) -> Vec { + let developers = crate::profile::release_profile(&g.path).is_some(); + if developers || profile_saves.is_empty() { + return saves::spots(&profile_saves, &from_cat, g); + } + saves::spots(&[], &profile_saves, g) } /// Nobody (the player, the developer or the catalog) has said where the game saves. A fixed text, @@ -1179,6 +1191,9 @@ pub async fn saves_info(app: AppHandle, id: String) -> Res { "spots": spots, "local": local, "cloud": cloud, "space": space, "offline": offline, "cloudOn": g.cloud, "signedIn": signed_in(&st.dir), "synced": state.synced_hash, "pending": state.pending.is_some(), "waiting": waiting, "status": STATUS_PAGE, + // The save in the game's folder now (the last copy made or put back), and this PC's name: + // the tab marks the copy that's current and the ones another PC made. + "current": state.last_hash, "here": saves::device_name(), // Seconds until a copy that didn't get through is tried again, and whether the account's // cloud saves are full (no uploads until there's room). "retryIn": state.pending.as_deref().and_then(|p| copy_wait_left(&id, p)), "full": full_now(), @@ -1447,8 +1462,29 @@ pub async fn saves_restore(app: AppHandle, id: String, name: Option, v: blocking(move || saves::restore(&dir, &id2, &file, &spots, &g)).await? } -/// The player's own answer to where the game saves (a folder they picked), or None to go back to -/// the developer's or the catalog's folders (or none: then the launcher says it doesn't know). +/// Deletes one of a game's cloud saves. Never its newest: that's the one the next PC brings in +/// and the one this PC last synced with, so without it an older copy would look like the newest. +#[tauri::command] +pub async fn saves_cloud_delete(app: AppHandle, id: String, v: String) -> Res<()> { + let _busy = BUSY.lock().await; + let (list, _) = cloud_list(&app, &id).await?; + if !deletable(&list, &v) { + return Err(Error::Msg("The newest cloud save stays: the next PC you play on brings it in.".into())); + } + let r = post(&app, "save-delete", json!({"game": id, "v": v}), true).await?; + if let (Some(used), Some(quota)) = (r.get("used").and_then(Value::as_u64), r.get("quota").and_then(Value::as_u64)) { + room_now(used, quota); + } + Ok(()) +} + +/// A cloud save that can go: one of the list (newest first) that isn't its newest. +fn deletable(list: &[CloudCopy], v: &str) -> bool { + list.iter().skip(1).any(|c| c.v == v) +} + +/// The player's own answer to where the game saves (a folder they picked), or None to forget it. +/// It only counts while neither the developer nor the catalog names a folder (saves::spots). #[tauri::command(async)] pub fn saves_set_place(st: State<'_, App>, id: String, path: Option) -> Res { let mut l = st.lib.lock().unwrap(); @@ -1938,6 +1974,39 @@ mod status_tests { d } + fn cloud_copy(v: &str) -> CloudCopy { + CloudCopy { v: v.into(), ..Default::default() } + } + + #[test] + fn the_newest_cloud_save_is_never_deleted() { + assert!(!deletable(&[cloud_copy("new"), cloud_copy("old")], "new")); + } + + #[test] + fn an_older_cloud_save_can_be_deleted() { + assert!(deletable(&[cloud_copy("new"), cloud_copy("old")], "old")); + } + + #[test] + fn a_cloud_save_that_is_not_there_is_not_deleted() { + assert!(!deletable(&[cloud_copy("new"), cloud_copy("old")], "gone")); + } + + #[test] + fn save_folders_from_a_profile_the_release_has_are_the_developers() { + let d = tmp("release-profile"); + std::fs::write(d.join("recomplauncher.json"), r#"{"format":1}"#).unwrap(); + let g = Installed { path: d, ..Default::default() }; + assert_eq!(named_spots(vec!["{install}/save".into()], vec![], &g)[0].from, "developer"); + } + + #[test] + fn save_folders_from_a_profile_we_keep_are_recomplaunchers() { + let g = Installed { path: tmp("our-profile"), ..Default::default() }; + assert_eq!(named_spots(vec!["{install}/save".into()], vec![], &g)[0].from, "catalog"); + } + #[test] fn a_full_cloud_is_its_own_problem() { assert_eq!(problem_kind(&Error::Msg(FULL_TEXT.into())), "full"); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f647f43f..b0888060 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -10123,7 +10123,7 @@ pub fn run() { convert_copy, convert_cancel, looks_info, set_look, look_picture, ui_data, reset_settings, tray::tray_words, tray::quit_launcher, ach::ach_access, ach::ach_status, ach::ach_apply, ach::ach_profile, ach::ach_games, ach::ach_board, ach::ach_game_web, ach::ach_report, ach::ach_tracker_get, ach::ach_game, ach::ach_set_disc, ach::ach_set_folder, ach::ach_sound, ach::ach_log, ach::ach_peek, ach::ach_rule, ach::ach_reset, ach::ach_test_toast, ach::ach_toast_take, ach::ach_toast_done, cloud::account_start, cloud::account_poll, cloud::account_cancel, cloud::account_state, cloud::account_signout, - cloud::saves_check, cloud::saves_pick, cloud::saves_cloud, download_history, report_counts, play_reports, cloud::saves_info, cloud::saves_status, cloud::saves_upload_now, cloud::cloud_retry, cloud::saves_overview, cloud::saves_backup, cloud::saves_restore, cloud::saves_share, cloud::saves_set_place, cloud::saves_add_place, cloud::saves_remove_place, cloud::saves_open, saves_set_root, saves_open_root, missing_files, missing_made, dll_check, dll_aside, gpu_choice, prefer_fast_gpu, copy_check, wine_tools, deck_scores, latest_counts, team_notes, trending, ig_info, ig_view, usage::notifies, usage::notify, usage::pc_specs, usage::recomp_request, + cloud::saves_check, cloud::saves_pick, cloud::saves_cloud, download_history, report_counts, play_reports, cloud::saves_info, cloud::saves_status, cloud::saves_upload_now, cloud::cloud_retry, cloud::saves_overview, cloud::saves_backup, cloud::saves_restore, cloud::saves_cloud_delete, cloud::saves_share, cloud::saves_set_place, cloud::saves_add_place, cloud::saves_remove_place, cloud::saves_open, saves_set_root, saves_open_root, missing_files, missing_made, dll_check, dll_aside, gpu_choice, prefer_fast_gpu, copy_check, wine_tools, deck_scores, latest_counts, team_notes, trending, ig_info, ig_view, usage::notifies, usage::notify, usage::pc_specs, usage::recomp_request, adopt::adopt_scan, adopt::migrate_scan, adopt::migrate_pick, adopt::adopt_pick, adopt::adopt_add, adopt::adopt_check, adopt::set_project, usage::usage_hello, usage::usage_event, usage::data_ids, usage::reset_ids, ping::usage_open, ping::usage_mode, usage::run_report, cloud::inbox, cloud::inbox_done, cloud::betas, cloud::beta_join, cloud::beta_leave, launcher_notes, scan_info, devtools::dev_add, devtools::add_any, devtools::dev_check, devtools::dev_starter, fs_places, fs_list, fs_extract, gb_mods, gb_mod, gb_install ]) .build(tauri::generate_context!()) diff --git a/ui/games.js b/ui/games.js index 83a7f67b..1751b1d3 100644 --- a/ui/games.js +++ b/ui/games.js @@ -176,7 +176,7 @@ function playtimeRows(a, total) { // folder, settings): those get the recomp's id. Playing it, its setup, shortcuts and achievements // go by the game's own id, and so do its saves when it keeps its own. const GAME_CMDS = new Set(['play', 'game_info', 'game_setup', 'setup_inputs_run', 'desktop_shortcut', 'add_to_steam', 'ach_game', 'ach_set_disc', 'ach_set_folder']); -const SAVE_CMDS = new Set(['saves_check', 'saves_pick', 'saves_info', 'saves_status', 'saves_upload_now', 'saves_backup', 'saves_restore', 'saves_open', 'saves_open_backups']); +const SAVE_CMDS = new Set(['saves_check', 'saves_pick', 'saves_info', 'saves_status', 'saves_upload_now', 'saves_backup', 'saves_restore', 'saves_cloud_delete', 'saves_open', 'saves_open_backups']); function gameArgs(cmd, args) { if (!args || typeof args.id !== 'string') return args; const s = subOf(args.id); From 89c82728bb88cfa18497b93d4c3db83d21494ad1 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 17:15:27 +0000 Subject: [PATCH 10/16] The Saves tab, rebuilt: its status first, every save in one history, then where it saves --- tests/beta45.test.cjs | 2 +- tests/save-badge.test.cjs | 10 ++ tests/saves-tab.test.cjs | 232 ++++++++++++++++++++++++++++ tests/saves-unknown.test.cjs | 52 ++++--- ui/account.js | 287 +++++++++++++++++++++++++++++------ ui/app.css | 45 +++++- ui/tv.css | 20 ++- ui/tv.js | 82 +++++++--- 8 files changed, 637 insertions(+), 93 deletions(-) create mode 100644 tests/saves-tab.test.cjs diff --git a/tests/beta45.test.cjs b/tests/beta45.test.cjs index 1a40d696..5e71c63d 100644 --- a/tests/beta45.test.cjs +++ b/tests/beta45.test.cjs @@ -60,7 +60,7 @@ test('a game nobody says where it saves asks the player to pick its folder', () assert.equal(savesUnknown(null), false); // The same pick on the desktop and in Big Picture. const tv = read('tv.js'); - assert.match(account, /unknown \? pickRow/); + assert.match(account, /if \(savesUnknown\(s\)\) return `
\$\{unknownCard\(id\)\}/); assert.match(tv, /data-tvact="gs-place"/); assert.match(tv, /case 'gs-place':[\s\S]{0,400}invoke\('saves_set_place'/); }); diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs index 92339dd5..70d8d3d1 100644 --- a/tests/save-badge.test.cjs +++ b/tests/save-badge.test.cjs @@ -104,6 +104,16 @@ test('signed out says so', () => { assert.equal(b.label, 'Not signed in'); }); +test('a game whose save folder nobody named says it is not backed up, whatever else is set', () => { + const b = info.saveBadgeInfo(status('up-to-date', { known: false, syncedAt: now() }), undefined, false); + assert.equal(b.label, 'Saves not backed up'); +}); + +test('a game whose save folder nobody named is grey above Play, not a red alarm', () => { + const b = info.saveBadgeInfo(status('none', { known: false }), undefined, false); + assert.equal(b.tone, 'dim'); +}); + test('a game never played has nothing to sync', () => { const b = info.saveBadgeInfo(status('none'), undefined, false); assert.equal(b.label, 'No saves yet'); diff --git a/tests/saves-tab.test.cjs b/tests/saves-tab.test.cjs new file mode 100644 index 00000000..4c12cb8c --- /dev/null +++ b/tests/saves-tab.test.cjs @@ -0,0 +1,232 @@ +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const read = (f) => fs.readFileSync(path.join(__dirname, '..', f), 'utf8'); +const account = read('ui/account.js'), tv = read('ui/tv.js'), app = read('ui/app.js'); +const savesRs = read('src-tauri/src/saves.rs'), cloudRs = read('src-tauri/src/cloud.rs'); + +// Everything from `start` to the brace that closes the first one after it, out of `src`. +function block(src, start) { + const at = src.indexOf(start); + assert.ok(at >= 0, start); + let i = src.indexOf('{', at), depth = 0; + for (; i < src.length; i++) { + if (src[i] === '{') depth++; + if (src[i] === '}' && --depth === 0) break; + } + return src.slice(at, i + 1); +} +const line = (src, start) => { + const at = src.indexOf(start); + assert.ok(at >= 0, start); + return src.slice(at, src.indexOf('\n', at)); +}; + +// The Saves tab's pieces out of account.js, with the window's helpers kept to plain English. +function tab(S) { + return new Function('S', ` + const N_ = (x) => x, t = (x) => x, tf = (x, o) => x.replace(/\\{(\\w+)\\}/g, (m, k) => o[k]), esc = (x) => String(x); + const tn = (n, one, many) => (n === 1 ? one : many).replace('{n}', n); + const whenText = (ts) => 'at ' + ts, fmtB = (b) => (b ? b + ' B' : ''), fmtTime = (s) => s + ' s'; + const saveShareTitle = () => false, saveShareOn = () => false; + ${line(account, 'const FROM = ')} + ${line(account, 'const SET_ICON = ')} + ${line(account, 'const spotSet = ')} + ${line(account, 'const CURRENT_ICON = ')} + ${line(account, 'const BIN_ICON = ')} + ${line(account, 'const HISTORY_SHOWN = ')} + const MARK_ICONS = { pc: '', cloud: '', other: '' }; + ${block(account, 'function saveHistory(')} + ${block(account, 'function historyMarks(')} + ${block(account, 'function historyDetails(')} + ${block(account, 'function historyRow(')} + ${block(account, 'function historyShown(')} + ${block(account, 'function historyToggle(')} + ${block(account, 'function historyCard(')} + ${block(account, 'function whereCard(')} + ${block(account, 'function spotRow(')} + return { saveHistory, historyShown, historyToggle, historyCard, whereCard };`)(S); +} +const fresh = () => ({ savesMore: new Set() }); + +const local = (when, hash, device = 'Desk PC') => ({ name: `${when}.zip`, when, hash, device, played: 60, files: 2, size: 100 }); +const cloud = (made, hash, v, device = 'Desk PC') => ({ v, hash, made, device, played: 60, size: 100 }); + +test('a save on this PC and the same save in the cloud are one row', () => { + const rows = tab(fresh()).saveHistory({ local: [local(100, 'a')], cloud: [cloud(100, 'a', 'v1')] }); + assert.equal(rows.length, 1); + assert.equal(rows[0].name, '100.zip'); + assert.equal(rows[0].v, 'v1'); +}); + +test('the list is newest first, whichever side a save is on', () => { + const rows = tab(fresh()).saveHistory({ local: [local(100, 'a'), local(300, 'c')], cloud: [cloud(200, 'b', 'v2')] }); + assert.deepEqual(rows.map((r) => r.when), [300, 200, 100]); +}); + +test('the save in the game now is marked once', () => { + const rows = tab(fresh()).saveHistory({ local: [local(300, 'a'), local(100, 'a')], cloud: [], current: 'a' }); + assert.deepEqual(rows.map((r) => r.current), [true, false]); +}); + +test('restoring an older save moves the mark, not the rows', () => { + const s = { local: [local(300, 'c'), local(200, 'b'), local(100, 'a')], cloud: [] }; + const before = tab(fresh()).saveHistory({ ...s, current: 'c' }); + const after = tab(fresh()).saveHistory({ ...s, current: 'a' }); + assert.deepEqual(after.map((r) => r.when), before.map((r) => r.when)); + assert.equal(after[2].current, true); +}); + +test('a save another PC made says which one', () => { + const S = fresh(); + const html = tab(S).historyCard('g', { local: [], cloud: [cloud(100, 'a', 'v1', 'Steam Deck')], here: 'Desk PC', busy: false }, {}, false); + assert.match(html, /From Steam Deck/); +}); + +test('a long list shows the newest six and a way to see the rest', () => { + const S = fresh(); + const rows = Array.from({ length: 9 }, (_, i) => ({ when: 100 - i, current: false })); + const t = tab(S); + assert.equal(t.historyShown('g', rows).length, 6); + assert.equal(t.historyToggle('g', rows, 3).more, true); +}); + +test('a restored save older than the newest six is still shown', () => { + const rows = Array.from({ length: 9 }, (_, i) => ({ when: 100 - i, current: i === 7 })); + assert.equal(tab(fresh()).historyShown('g', rows).length, 8); +}); + +test('the whole list shown offers to show fewer again', () => { + const S = fresh(); + S.savesMore.add('g'); + const rows = Array.from({ length: 9 }, (_, i) => ({ when: 100 - i, current: false })); + assert.equal(tab(S).historyToggle('g', rows, 0).label, 'Show fewer saves'); +}); + +test('a short list has no show more or fewer', () => { + const rows = [{ when: 1, current: false }]; + assert.equal(tab(fresh()).historyToggle('g', rows, 0), null); +}); + +const history = (s) => tab(fresh()).historyCard('g', { local: [], cloud: [], busy: false, ...s }, {}, false); + +test('saves that stay on this PC can be backed up by hand', () => { + assert.match(history({ signedIn: true, cloudOn: false }), /data-act="saves-now"/); +}); + +test('signed out, saves can be backed up by hand', () => { + assert.match(history({ signedIn: false, cloudOn: true }), /data-act="saves-now"/); +}); + +test('with cloud saves on, Sync Now does the copy and Back up now is not offered', () => { + assert.doesNotMatch(history({ signedIn: true, cloudOn: true }), /data-act="saves-now"/); +}); + +test('Big Picture offers Back up now only without cloud saves too', () => { + assert.match(tv, /\$\{unknown \|\| \(sv\.signedIn && on\) \? '' : `
` : ''; - // Several folders the player picked (a launcher with more than one game): each can come off the list. - const many = s.spots.filter((p) => p.from === 'player').length > 1; - const unknown = savesUnknown(s); - const pickRow = `
${esc(t(SAVES_UNKNOWN))}${esc(t(SAVES_UNKNOWN_HELP))}
`; - const where = unknown ? pickRow : s.spots.map((p) => `
${esc(p.path)}${esc(t(FROM[p.from] || ''))}${p.exists ? '' : ' · ' + esc(t('Not there yet'))}
${many ? `` : `${p.from === 'player' ? `` : ''}`}
`).join('') - + `
${esc(t('Saves in more than one folder?'))}${esc(t('For a launcher with several games in it, each saving in its own folder. Backups and cloud saves cover every folder.'))}
${many ? `` : ''}
`; - const cloudCard = !signed - ? `
${CLOUD_ICON}
${esc(t('Cloud saves'))}${esc(t('Sign in to back this game\'s saves up to your account and play on with them on any PC.'))}
` - : `
${esc(t('Cloud saves'))}${esc(on ? (s.offline ? t('On. The website can\'t be reached right now; copies go up when it can.') : s.pending ? t('On. The newest copy goes up next time the launcher can reach the website.') : t('On. After you play, its saves go to your account.')) : t('Off. Its saves only stay on this PC.'))}
- ${on ? cloudStatus(id, s) : ''} - ${on && Array.isArray(s.cloud) ? (s.cloud.length ? s.cloud.map((c) => copyRow(id, c, 'v', c.v, c.hash === s.synced)).join('') : `

${esc(t('Nothing in the cloud yet. It goes up after you play.'))}

`) : ''}
`; + if (savesUnknown(s)) return `
${unknownCard(id)}${historyCard(id, s, g, true)}${savesSettingsCard(id)}
`; + return `
${saveStatusCard(id, s)}${historyCard(id, s, g, false)}${savesSettingsCard(id)}${whereCard(id, s)}
`; +} + +// Nobody has said where it saves: nothing is backed up or uploaded, even with cloud saves on, so +// it's red like a problem, and Pick a Folder is the way out. +function unknownCard(id) { + return `
${badgeIcon('alert', 30)}
${esc(t(SAVES_UNKNOWN))}${esc(t(SAVES_UNKNOWN_HELP))}
`; +} + +// A folder its developer set that's too big to look through: the player can't change it, so +// the way out is telling the developer. +const FOLDER_SET_TOO_BIG = N_('Its save folder is too big to look through, so cloud saves are paused for this game. Your saves stay on this PC. Its developer can fix where it saves: report it to them.'); + +// Where its saves stand, in the same words and colours as the line above Play, and the one thing +// to do about it. +function saveStatusCard(id, s) { + const b = saveBadgeFor(id); + if (!b) return ''; + const sid = saveIdOf(id); + const st = S.saveStat[sid] || {}; + const picked = s.spots.some((p) => p.from === 'player'); + const note = b.note ? ` · ${esc(b.note)}` : ''; + const rows = b.rows.map(([k, v]) => `${k}: ${v}`).join(' · '); + const text = statusCardText(st, b, picked); + const offline = st.problem && st.problem.kind === 'offline' && s.status; + const help = offline ? `

${esc(t('Still no answer. Check whether the website is having trouble:'))}

` : ''; + const space = s.signedIn && s.cloudOn === true ? cloudSpace() : ''; + const step = saveNextStep(st, S.savePhase[sid], S.running.has(parentId(sid)), picked); + const url = step && step.url ? ` data-url="${esc(step.url)}"` : ''; + const btn = step ? `` : ''; + return `
${badgeIcon(b.mark, 30)} +
${esc(b.label)}${note}${text ? `${esc(text)}` : ''}${rows ? `${esc(rows)}` : ''}
+ ${btn}
${help}${space}
`; +} + +// The status's line on the tab: the badge's, except where the badge points somewhere else. +function statusCardText(st, b, picked) { + // On the tab the way to pick is the button beside it, not "Play, or Sync Now". + if (st.state === 'conflict') return t('This PC and the cloud both changed since they last synced. Pick the one to keep; the other stays as a copy on this PC.'); + if (st.state === 'off') return t('The launcher still keeps a copy after every session. Turn cloud saves on to have it on any PC.'); + const kind = st.state === 'problem' && st.problem && st.problem.kind; + if (kind === 'too-big-folder' && !picked) return t(FOLDER_SET_TOO_BIG); + return b.text; +} + +// What the player can do about a status, so none leaves them stuck: a button ({ act, label }), +// or null when it sorts itself out (a sync running, the game being played, an upload's next try, +// cloud saves paused for everyone, nothing played yet). `picked`: the player chose the folder. +function saveNextStep(st, phase, running, picked) { + if (phase || running) return null; + if (st.known === false) return { act: 'saves-place', label: N_('Pick a Folder') }; + if (st.state === 'signed-out') return { act: 'acc-signin', label: N_('Sign in') }; + // saves-cloud turns them on when the button has no switch state to read. + if (st.state === 'off') return { act: 'saves-cloud', label: N_('Turn On') }; + if (st.state === 'conflict') return { act: 'saves-sync', label: N_('Choose a Save') }; + if (st.state === 'problem') return problemStep((st.problem && st.problem.kind) || 'error', picked); + if (st.state === 'waiting' || st.state === 'up-to-date') return { act: 'saves-sync', label: N_('Sync Now') }; + return null; +} + +function problemStep(kind, picked) { + if (kind === 'too-big-folder') return picked ? { act: 'saves-place', label: N_('Pick a Folder') } : { act: 'report', label: N_('Report a Problem') }; + // A save over the upload limit is the game's to make smaller. + if (kind === 'too-big-copy') return { act: 'report', label: N_('Report a Problem') }; + // The site paused cloud saves; they start again by themselves. + if (kind === 'paused') return null; + // The newest save of every game is kept, so room comes from another game's cloud saves: the + // account page lists them all. + if (kind === 'full') return { act: 'url', label: N_('Free Up Space'), url: `${SITE}/account` }; + return { act: 'saves-sync', label: N_('Try Again') }; +} + +// How full the account's cloud saves are, the same bar as Settings → Account. +function cloudSpace() { + const acc = S.account || {}; + const used = acc.used || 0, quota = acc.quota || 150 * 1024 * 1024; + const pct = Math.min(100, Math.round((used / quota) * 100)); + return `
${esc(tf('Cloud space: {used} of {quota} used', { used: fmtB(used) || '0 KB', quota: fmtB(quota) }))}
`; +} + +// Every save in one list, newest first. A copy kept on this PC and the same save in the cloud +// (the same checksum) are one row, marked as being in both places. The one in the game's folder +// now is Current. +function saveHistory(s) { + const rows = []; + const byHash = new Map(); + for (const c of s.local || []) { + const row = { when: c.when, device: c.device, played: c.played, files: c.files, size: c.size, hash: c.hash, name: c.name, v: null, current: false }; + rows.push(row); + if (c.hash && !byHash.has(c.hash)) byHash.set(c.hash, row); + } + for (const c of Array.isArray(s.cloud) ? s.cloud : []) { + const same = c.hash && byHash.get(c.hash); + if (same) { same.v = same.v || c.v; continue; } + rows.push({ when: c.made, device: c.device, played: c.played, files: 0, size: c.size, hash: c.hash, name: null, v: c.v, current: false }); + } + rows.sort((p, q) => q.when - p.when); + const now = s.current && rows.find((r) => r.hash === s.current); + if (now) now.current = true; + // Any cloud save but the newest can be deleted (saves_cloud_delete says why not that one). + const newestCloud = Array.isArray(s.cloud) && s.cloud.length ? s.cloud.reduce((p, q) => (q.made > p.made ? q : p)).v : ''; + for (const r of rows) r.deletable = !!r.v && r.v !== newestCloud; + return rows; +} + +// Where a save is kept, and whether another PC made it. +function historyMarks(r, s) { + const out = []; + if (r.name) out.push({ k: 'pc', label: t('On this PC') }); + if (r.v) out.push({ k: 'cloud', label: t('In the cloud') }); + if (r.device && s.here && r.device !== s.here) out.push({ k: 'other', label: tf('From {device}', { device: r.device }) }); + return out; +} +const MARK_ICONS = { + pc: '', + cloud: '', + other: '', +}; + +const BIN_ICON = ''; +const CURRENT_ICON = ''; + +// Details under a save: how long the game had been played then, its files and size. +function historyDetails(r) { + const played = r.played ? tf('{time} played', { time: fmtTime(r.played) }) : ''; + const files = r.files ? tn(r.files, '1 file', '{n} files') : ''; + return [played, files, fmtB(r.size)].filter(Boolean).join(' · '); +} + +function historyRow(id, r, s) { + const marks = historyMarks(r, s).map((m) => `${MARK_ICONS[m.k]}${esc(m.label)}`).join(''); + // A copy on this PC is restored from here; one only in the cloud comes down first. + const which = r.name ? `data-name="${esc(r.name)}"` : `data-v="${esc(r.v)}"`; + const put = ``; + // The save in the game now has nothing to restore: its row is lit instead, and says so where + // the others have their button. + const side = r.current ? `${CURRENT_ICON}${esc(t('In the game now'))}` : put; + // Deleting from the cloud is quieter than Restore: an icon, with its name on hover. + const del = r.deletable ? `` : ''; + return `
${esc(whenText(r.when))}${marks}${esc(historyDetails(r))}
${del}${side}
`; +} + +// The newest few; the rest one click away, so a long history doesn't push the settings far down. +const HISTORY_SHOWN = 6; +S.savesMore = new Set(); +// The newest few, and always down to the one in the game now: after an older save is restored, +// its row stays where its date puts it and the list reaches it. +function historyShown(id, rows) { + if (S.savesMore.has(id)) return rows; + const current = rows.findIndex((r) => r.current); + return rows.slice(0, Math.max(HISTORY_SHOWN, current + 1)); +} + +// Show older saves, or, once they're all shown, fewer again: { more, label }, or null when the +// list is short. `more`: how many are hidden. +function historyToggle(id, rows, more) { + if (more) return { more: true, label: tn(more, 'Show 1 older save', 'Show {n} older saves') }; + if (S.savesMore.has(id) && rows.length > HISTORY_SHOWN) return { more: false, label: t('Show fewer saves') }; + return null; +} + +function historyCard(id, s, g, unknown) { + const rows = saveHistory(s); + const shown = historyShown(id, rows); + const more = rows.length - shown.length; + const backups = ``; + const now = ``; + // Nothing to back up until a save folder is known; copies made before can still be opened. With + // cloud saves on, Sync Now copies the save before it goes up, so Back Up Now is only for a game + // whose saves stay on this PC. + const syncs = s.signedIn && s.cloudOn === true; + const acts = unknown ? (s.local.length ? backups : '') : syncs ? backups : backups + now; const emptyText = unknown ? t('No backups yet.') : g.last_played ? t('No saves found yet. If it saves somewhere unusual, its developer can say where in recomplauncher.json.') : t('Play it once and its saves are copied here after.'); - // Nothing to open or back up until a save folder is known: Pick a Folder is the one thing to do, - // so its card comes first. Copies made before (from an older version) can still be opened. - const acts = unknown ? (s.local.length ? `` : '') : ``; - const local = s.local.length ? s.local.map((c) => copyRow(id, c, 'name', c.name, false)).join('') : `

${esc(emptyText)}

`; - const whereCard = `

${esc(t('Where it saves'))}

${where}
`; - return `
${unknown ? whereCard : ''}${shareCard}${cloudCard} -

${esc(t('On this PC'))}

${acts}
${local}
- ${unknown ? '' : whereCard}
`; -} -// Where this game's cloud saves stand and how to sync them now. -function cloudStatus(id, s) { - const newest = Array.isArray(s.cloud) && s.cloud[0]; - const line = s.waiting ? tn(s.waiting, 'Waiting to upload (1 copy)', 'Waiting to upload ({n} copies)') - : newest ? tf('Last uploaded {when} from {device}', { when: whenText(newest.made), device: newest.device || t('this PC') }) - : t('Nothing in the cloud yet'); - const btn = ``; - const help = s.failed && s.status ? `

${esc(t('Still no answer. Check whether the website is having trouble:'))}

` : ''; - // Why it's still waiting: the cloud is full, or the last try didn't get through and the next is - // on its way by itself. - const why = s.waiting && s.full ? t('Your cloud saves are full. Remove old cloud copies to make room; uploads start again by themselves.') - : s.waiting && s.retryIn ? tf('The last try didn\'t get through. Next try in {when}.', { when: s.retryIn >= 60 ? tf('{n} min', { n: Math.ceil(s.retryIn / 60) }) : tf('{n} s', { n: s.retryIn }) }) - : ''; - return `
${esc(line)}${why ? `${esc(why)}` : ''}
${btn}
${help}`; + const list = rows.length ? shown.map((r) => historyRow(id, r, s)).join('') : `

${esc(emptyText)}

`; + const offline = s.cloudOn === true && s.offline ? `

${esc(t('The cloud can\'t be reached right now, so only the copies on this PC are listed.'))}

` : ''; + const toggle = historyToggle(id, rows, more); + const toggleBtn = toggle ? `` : ''; + return `

${esc(t('Save History'))}

${acts}
${offline}${list}${toggleBtn}
`; } -function copyRow(id, c, k, v, current) { - const when = c.when || c.made; - return `
${esc(whenText(when))}${current ? ` ${esc(t('Same as this PC'))}` : ''}${esc([c.device, tn(c.files || 0, '1 file', '{n} files'), fmtB(c.size)].filter((x, i) => x && !(i === 1 && !c.files)).join(' · '))}
`; + +// Sharing saves between its versions, for a game with more than one. Cloud saves on or off is in +// the game's Manage section; here the status card only offers to turn them on. +function savesSettingsCard(id) { + const shareTitle = saveShareTitle(id); + if (!shareTitle) return ''; + return `

${esc(t('Settings'))}

${esc(t(SHARE_SAVES))}${esc(t(SHARE_SAVES_HELP))}
`; +} + +// Where the game keeps its saves. A folder its developer (or RecompLauncher) named is only shown, +// with a way to open it: saying where is what recomplauncher.json is for, so there's nothing to +// change. Changing it and more folders are for a folder the player picked, which only counts +// while nobody has named one (saves::spots). +function whereCard(id, s) { + const picked = s.spots.filter((p) => p.from === 'player').length; + const rows = s.spots.map((p) => spotRow(id, p, picked > 1)).join(''); + const add = picked ? `
${esc(t('Saves in more than one folder?'))}${esc(t('For a launcher with several games in it, each saving in its own folder. Backups and cloud saves cover every folder.'))}
` : ''; + return `

${esc(t('Where it saves'))}

${rows}${add}
`; +} + +function spotRow(id, p, many) { + const from = esc(t(FROM[p.from] || '')); + const notYet = p.exists ? '' : ` · ${esc(t('Not there yet'))}`; + const said = spotSet(p) ? `${SET_ICON}${from}${notYet}` : `${from}${notYet}`; + const open = p.exists ? `` : ''; + let acts = open; + if (many) acts = ``; + else if (p.from === 'player') acts = `${open}`; + return `
${esc(p.path)}${said}
${acts}
`; } const savesChanged = (id) => { delete S.saves[id]; if (S.view === 'game' && S.arg === id && S.tab === 'saves') loadSaves(id); }; @@ -277,6 +451,7 @@ async function loadSaveStatus(sid) { try { S.saveStat[sid] = await invoke('saves_status', { id: sid }); } catch (e) { S.saveStat[sid] = null; } statLoading.delete(sid); paintSaveBadges(sid); + refreshSavesTab(sid); } // "12 min ago" for the last sync: ago() only goes down to "today", too coarse for "did that @@ -314,6 +489,10 @@ const PHASE_BADGE = { function saveBadgeInfo(st, phase, running) { const p = PHASE_BADGE[phase]; if (p) return { tone: 'cy', mark: p.mark, label: t(p.label), note: '', head: t(p.head), text: t(p.text), rows: [] }; + // Nobody has said where it saves: nothing is backed up or uploaded, whatever else is set. Many + // games are like this until their folder is known, so it's grey here, not a red alarm on every + // page; the Saves tab says it in red, with Pick a Folder. + if (st.known === false) return { tone: 'dim', mark: 'off', label: t('Saves not backed up'), note: '', head: t('The launcher doesn\'t know where this game saves'), text: t('Nothing of it is backed up or sent to the cloud. Pick its save folder on its Saves tab.'), rows: [] }; const synced = st.syncedAt ? [[t('Last synced'), whenText(st.syncedAt)], [t('Saved on'), st.syncedDevice || t('this PC')]] : []; const newest = st.newest ? [[t('Last backup'), `${whenText(st.newest.when)}${st.newest.device ? ' · ' + st.newest.device : ''}`]] : []; if (st.state === 'signed-out') return { tone: 'dim', mark: 'dash', label: t('Not signed in'), note: '', head: t('Keep this save on any PC'), text: t('Sign in to RecompStore and your saves go to the cloud after you play. It\'s free.'), rows: newest }; @@ -399,6 +578,13 @@ function paintSaveBadges(sid) { if (window.tvRefresh && inTV()) window.tvRefresh(); } +// The Saves tab leads with the same status, so it's drawn again when the status changes. Not from +// paintSaveBadges: drawing the game page paints the badges, and that would go round forever. +function refreshSavesTab(sid) { + if (inTV() || S.view !== 'game' || S.tab !== 'saves' || !S.saves[S.arg]) return; + if (saveIdOf(S.arg) === sid) refreshGame(); +} + // Signed in or out, or the cloud changed: every game's status is asked again. function forgetSaveStatus() { S.saveStat = {}; @@ -468,7 +654,7 @@ function pageSaves() { const empty = !games.length ? `
${CARD_ICON.replace('width="20" height="20"', 'width="44" height="44"')}

${esc(t('No games yet'))}

${esc(t('Install a game and play it once. Its saves are copied here after every session.'))}

` : ''; - return `

${esc(t('Saves'))}

${esc(t('After every session the launcher keeps a copy of each game\'s saves. Pick a game to put an older one back.'))}

+ return `

${esc(t('Saves'))}

${esc(t('After every session the launcher keeps a copy of each game\'s saves. Pick a game to restore an older one.'))}

${o.error ? `

${esc(t(o.error))}

` : ''}
${pcCard}${cloudCard}
${rootCard(o)} @@ -674,6 +860,15 @@ window.accountAct = async (act, el) => { toast(!r.custom ? t('Copies of your saves are kept with each game again.') : r.moved ? tn(r.moved, 'One game\'s copies moved there. New ones go there too.', '{n} games\' copies moved there. New ones go there too.') : t('New copies of your saves go there from now on.')); return loadSavesAll(); } + case 'saves-more': S.savesMore.add(id); return refreshGame(); + case 'saves-less': S.savesMore.delete(id); return refreshGame(); + case 'saves-cloud-delete': { + const v = await ask(t('Delete this save from the cloud?'), `

${esc(t('It\'s gone from your account for good. Copies on this PC stay.'))}

`, + [{ label: t('Cancel'), v: null, focus: true }, { label: t('Delete'), v: 'yes', main: true }]); + if (v !== 'yes') return; + try { await invoke('saves_cloud_delete', { id, v: el.dataset.v }); toast(t('Deleted from the cloud.')); } catch (e) { fail(e); } + return loadSaves(id); + } case 'saves-open': return invoke('saves_open', { id }).catch(fail); case 'saves-open-backups': return invoke('saves_open_backups', { id }).catch(fail); case 'saves-place': { @@ -684,7 +879,6 @@ window.accountAct = async (act, el) => { toast(t('Saved. Backups and cloud saves use that folder now.')); return loadSaves(id); } - case 'saves-place-reset': try { S.library[id] = await invoke('saves_set_place', { id, path: null }); } catch (e) { return fail(e); } return loadSaves(id); case 'saves-place-add': { const p = await pickFile({ title: t('Another folder where the game keeps its saves'), directory: true }).catch(fail); if (!p) return; @@ -694,8 +888,8 @@ window.accountAct = async (act, el) => { } case 'saves-place-remove': try { S.library[id] = await invoke('saves_remove_place', { id, template: el.dataset.t || '' }); } catch (e) { return fail(e); } return loadSaves(id); case 'saves-restore': { - const v = await ask(t('Put this save back?'), `

${esc(t('The game goes back to this save. What\'s there now is kept as a copy first, so you can switch back.'))}

`, - [{ label: t('Cancel'), v: null }, { label: t('Put it back'), v: 'yes', main: true }]); + const v = await ask(t('Restore this save?'), `

${esc(t('The game goes back to this save. What\'s there now is kept as a copy first, so you can switch back.'))}

`, + [{ label: t('Cancel'), v: null }, { label: t('Restore'), v: 'yes', main: true }]); if (v !== 'yes') return; try { await invoke('saves_restore', { id, name: el.dataset.name || null, v: el.dataset.v || null }); toast(t('That save is back in place.')); } catch (e) { fail(e); } return loadSaves(id); @@ -713,7 +907,8 @@ T.event.listen('save-sync', ({ payload }) => { if (!sid) return; if (payload.phase !== 'idle') { S.savePhase[sid] = payload.phase; - return paintSaveBadges(sid); + paintSaveBadges(sid); + return refreshSavesTab(sid); } delete S.savePhase[sid]; loadSaveStatus(sid); diff --git a/ui/app.css b/ui/app.css index 1141d484..65fa3abb 100644 --- a/ui/app.css +++ b/ui/app.css @@ -2574,9 +2574,10 @@ body.light .su-req{color:#8a5300} /* The cloud save status above Play (account.js): a coloured line, not a button. Its colour says the state: green in the cloud, cyan working, amber waiting or a choice, red stuck, grey no cloud. The tooltip says more. */ -.sbadge{--sb-ok:#3ee08f;--sb-warn:var(--warn);--sb-bad:var(--bad);min-height:20px} -body.light .sbadge{--sb-ok:#127a45;--sb-warn:#9a6200;--sb-bad:#c53030} -.sbadge .sb-ok{--c:var(--sb-ok)}.sbadge .sb-cy{--c:var(--cyan)}.sbadge .sb-warn{--c:var(--sb-warn)}.sbadge .sb-bad{--c:var(--sb-bad)}.sbadge .sb-dim{--c:var(--dim)} +.sbadge,.svs{--sb-ok:#3ee08f;--sb-warn:var(--warn);--sb-bad:var(--bad)} +.sbadge{min-height:20px} +body.light .sbadge,body.light .svs{--sb-ok:#127a45;--sb-warn:#9a6200;--sb-bad:#c53030} +.sbadge .sb-ok,.svs.sb-ok{--c:var(--sb-ok)}.sbadge .sb-cy,.svs.sb-cy{--c:var(--cyan)}.sbadge .sb-warn,.svs.sb-warn{--c:var(--sb-warn)}.sbadge .sb-bad,.svs.sb-bad{--c:var(--sb-bad)}.sbadge .sb-dim,.svs.sb-dim{--c:var(--dim)} .sbadge-line{display:inline-flex;align-items:center;gap:7px;font:700 13.5px Figtree,sans-serif;color:var(--c);white-space:nowrap;cursor:default} .sbadge-line svg{flex:none} .sbadge-line small{font-weight:500;font-size:12.5px;color:var(--muted)} @@ -2590,3 +2591,41 @@ body.light .sbadge{--sb-ok:#127a45;--sb-warn:#9a6200;--sb-bad:#c53030} .pick-newer{margin-left:6px;font-style:normal;font-size:12.5px;font-weight:700;color:#3ee08f} body.light .pick-newer{color:#127a45} .pick-note{margin:-4px 0 14px;font-size:13px} +/* The Saves tab (account.js). Its first card is the status above Play, bigger, with the one thing + to do about it; then every save in one list, marked by where it's kept. */ +.svs-row{display:flex;align-items:center;gap:16px} +.svs-ico{flex:none;display:grid;place-items:center;width:52px;height:52px;border-radius:14px;color:var(--c);background:color-mix(in srgb,var(--c) 13%,transparent)} +.svs .k{flex:1;display:flex;flex-direction:column;gap:3px;min-width:0} +.svs .k b{font-size:17px;color:var(--c)} +.svs .k b small{font-size:13.5px;font-weight:500;color:var(--muted)} +.svs .k span{font-size:13.5px;color:var(--dim)} +.svs .k>small{font-size:12.5px;color:var(--muted)} +.svs .acts{flex:none} +.svs .set-note{margin:12px 0 0} +/* No box on the desktop: the status sits on the page as the tab's heading (Big Picture keeps its item box). */ +.card.svs{background:none;border-color:transparent;padding:6px 4px 10px} +.svs-space{margin-top:14px} +.svh-marks{display:flex;flex-wrap:wrap;gap:3px 14px;margin:2px 0 1px} +.set-row .k .svm{display:inline-flex;align-items:center;gap:5px;font-size:12.5px;font-weight:600;color:var(--dim)} +.svm svg{flex:none} +.set-row .k .svm-cloud{color:var(--cyan)} +.set-row .k .svm-other{color:#b9a1ff} +body.light .set-row .k .svm-other{color:#6a4bc9} +.svh-more{margin-top:14px} +@media (max-width:640px){.svs-row{flex-wrap:wrap}.svs .acts{width:100%}} +/* The save in the game now: its row is lit green, with a green edge, and says so on the right. */ +.svh-row{--ok:#3ee08f} +body.light .svh-row{--ok:#127a45} +.svh-row.cur{margin:0 -14px;padding-left:14px;padding-right:14px;border-radius:12px;border-bottom-color:transparent;background:color-mix(in srgb,var(--ok) 9%,transparent);box-shadow:inset 3px 0 0 var(--ok)} +.card-h+.svh-row.cur{padding-top:16px} +.svh-cur{flex:none;display:inline-flex;align-items:center;gap:6px;font-size:13.5px;font-weight:700;color:var(--ok)} +/* A save folder its developer or RecompLauncher set: said in green, with a shield. */ +.set-row .k .svp-set{display:inline-flex;align-items:center;gap:5px;font-weight:700;color:#3ee08f} +body.light .set-row .k .svp-set{color:#127a45} +.svp-set svg{flex:none} +/* Delete from the cloud: a quiet icon beside Restore, red on hover. */ +.svh-row .acts{display:flex;align-items:center;gap:8px} +.svh-del{color:var(--muted)} +.svh-del:hover{color:var(--bad)} +/* One RecompLauncher set is the launcher's cyan, so it reads apart from the developer's green. */ +.set-row .k .svp-set.ours{color:var(--cyan)} diff --git a/ui/tv.css b/ui/tv.css index c3d14860..ad3f3792 100644 --- a/ui/tv.css +++ b/ui/tv.css @@ -1029,9 +1029,27 @@ body.linux .tv-boot .aurora i{filter:none;mix-blend-mode:normal} /* The cloud save status above a game's buttons (account.js decides the state): a coloured line, not a button, as on the desktop. */ .tv-sbadge{--c:#8B97AA;margin:0;display:inline-flex;align-items:center;gap:10px;font-size:22px;font-weight:700;color:var(--c)} -.tv-sbadge.sb-ok{--c:#3ee08f}.tv-sbadge.sb-cy{--c:#34F2E8}.tv-sbadge.sb-warn{--c:#f5b83d}.tv-sbadge.sb-bad{--c:#ff7a7a} +.tv-sbadge.sb-ok,.tv-svs.sb-ok{--c:#3ee08f}.tv-sbadge.sb-cy,.tv-svs.sb-cy{--c:#34F2E8}.tv-sbadge.sb-warn,.tv-svs.sb-warn{--c:#f5b83d}.tv-sbadge.sb-bad,.tv-svs.sb-bad{--c:#ff7a7a} .tv-sbadge svg{flex:none} .tv-sbadge small{font-size:20px;font-weight:600;color:var(--tvsoft,#c9d3e0)} .tv-sbadge small::before{content:"· "} /* "Newer" beside a sheet item's label (the save made later, when both changed): green text. */ .tv-newer{margin-left:12px;font-style:normal;font-size:19px;font-weight:700;color:#3ee08f} +/* A game's Saves page: the status leads it in its colour, then every save marked by where it's + kept (account.js). */ +.tv-svs{--c:#8B97AA} +.tv-svs>svg{flex:none;color:var(--c)} +.tv-svs .k b{color:var(--c)} +.tv-svs .k b i{font-style:normal;font-weight:600;color:var(--tvsoft,#c9d3e0)} +.tv-svs .k small{white-space:normal;line-height:1.35} +.tv-svh-marks{display:flex;flex-wrap:wrap;gap:2px 18px;margin:2px 0} +.tv-svm{font:600 16px Figtree,sans-serif;color:var(--tvmuted,#a7b3c4)} +.tv-svm::before{content:"";display:inline-block;width:8px;height:8px;margin-right:7px;border-radius:50%;background:currentColor;vertical-align:2px} +.tv-svm-cloud{color:#34F2E8} +.tv-svm-other{color:#b9a1ff} +.tv-svh-current{background:rgba(62,224,143,.1);box-shadow:inset 4px 0 0 #3ee08f} +.tv-svh-cur{flex:none;display:inline-flex;align-items:center;gap:8px;font:700 18px Figtree,sans-serif;color:#3ee08f} +.tv-svh-cur svg{width:22px;height:22px} +.tv-svp-set{display:inline-flex;align-items:center;gap:7px;font-weight:700;color:#3ee08f} +.tv-svp-set svg{flex:none;width:20px;height:20px} +.tv-svp-set.ours{color:#34F2E8} diff --git a/ui/tv.js b/ui/tv.js index be2e5132..f4b4a9f8 100644 --- a/ui/tv.js +++ b/ui/tv.js @@ -1267,7 +1267,7 @@ ${S.steam && S.settings.steam_sync ? `` : ''} ${S.steam ? `` : ''} - + ${head(t('Controller'))} ${(() => { const g = (S.settings.ui || {}).tv_glyphs; const v = g === 'ps' ? 'PlayStation' : g === 'xbox' ? 'Xbox' : g === 'nintendo' ? 'Nintendo' : g === 'steam' ? 'Steam' : 'Automatic'; return ``; })()} @@ -1303,24 +1303,59 @@ const none = games.length - withSaves.length; const items = withSaves.map((x) => { const a = x.a || { id: x.id, name: x.g.name }; return ``; }).join(''); return `${backdrop(null)}${gameBar()} - ${region(`${pageHead(t('Saves'), t('After every session the launcher keeps a copy of each game\'s saves. Pick a game to put an older one back.'))} + ${region(`${pageHead(t('Saves'), t('After every session the launcher keeps a copy of each game\'s saves. Pick a game to restore an older one.'))} ${o && o.error ? `

${esc(t(o.error))}

` : ''}
${!o ? `

${esc(t('Loading…'))}

` : items || `

${esc(t('Install a game and play it once. Its saves are copied here after every session.'))}

`}
${none ? `

${esc(tn(none, '1 more game has no saves yet. Play it once and its saves show up here.', '{n} more games have no saves yet. Play them once and their saves show up here.'))}

` : ''}`)} ${hints([['A', t('Open')], ['B', t('Back')]])}`; } - // One game's saves: cloud on or off, a copy now, and every copy to put back. + // One game's saves, in the desktop tab's order: where they stand (A does the one thing to do about + // it), every save in one list (A restores one), the settings, and where it saves. Back Up Now only + // without cloud saves: with them, Sync Now copies the save before it goes up. async function loadGameSaves(id) { try { TV.saves[id] = await invoke('saves_info', { id }); } catch (e) { TV.saves[id] = { error: String(e && e.message ? e.message : e) }; } + // Whatever just changed the page changed its status too. + loadSaveStatus(saveIdOf(id)); if (TV.on && TV.view === 'gsaves' && TV.arg === id) draw(true); } + // The desktop's next steps as this page's actions. Reporting a problem stays in the desktop view. + const TV_STEP = { 'acc-signin': 'account', 'saves-cloud': 'gs-cloud', 'saves-sync': 'gs-sync', 'saves-place': 'gs-place' }; + // The status, as the item that leads the page. + function savesStatusItem(id, sv) { + const b = window.saveBadgeFor(id); + if (!b) return ''; + const sid = saveIdOf(id); + const st = S.saveStat[sid] || {}; + const picked = (sv.spots || []).some((p) => p.from === 'player'); + const step = saveNextStep(st, S.savePhase[sid], S.running.has(parentId(sid)), picked); + const act = step && !sv.busy && TV_STEP[step.act]; + // Reporting stays in the desktop view, and the account page needs a browser: said instead. + const desk = !step ? '' : step.act === 'report' ? ` ${t('Report problems from the desktop view')}.` : step.act === 'url' ? ` ${t('Free up space on your account page at recomplauncher.com.')}` : ''; + const tvact = act ? ` data-tvact="${act}" data-id="${esc(id)}"` : ''; + const pill = act ? `${esc(t(step.label))}` : ''; + const note = b.note ? ` · ${esc(b.note)}` : ''; + return ``; + } + // Nobody has said where it saves: red, as on the desktop, and A picks the folder. + function savesUnknownItem(id) { + return ``; + } + function savesHistoryItem(id, r, sv) { + const marks = historyMarks(r, sv).map((m) => `${esc(m.label)}`).join(''); + const which = r.name ? `data-name="${esc(r.name)}"` : `data-v="${esc(r.v)}"`; + // A cloud save that can be deleted carries its version, for the sheet's Delete. + const del = r.deletable ? ` data-cv="${esc(r.v)}"` : ''; + const act = r.current ? '' : ` data-tvact="gs-restore" data-id="${esc(id)}" ${which}${del}`; + // The save in the game now is lit, and says so where the others say Restore. + const side = r.current ? `${CURRENT_ICON}${esc(t('In the game now'))}` : `${esc(t('Restore'))}`; + return ``; + } function pageGameSaves(id) { const a = libAppOf(id), g = S.library[id] || {}; const s0 = TV.saves[id]; if (s0 === undefined) { TV.saves[id] = 'loading'; loadGameSaves(id); } const sv = s0 && s0 !== 'loading' ? s0 : null; - const copy = (c, k, v, now) => { const when = c.when || c.made; return ``; }; let body = `

${esc(t('Loading…'))}

`; let unknown = false; if (sv && sv.error) body = `

${esc(t(sv.error))}

`; @@ -1330,25 +1365,26 @@ unknown = window.savesUnknown(sv); const on = sv.cloudOn === true; const shareTitle = saveShareTitle(id); + const rows = saveHistory(sv); + const shown = historyShown(id, rows); + const more = rows.length - shown.length; + const toggle = historyToggle(id, rows, more); + const empty = unknown ? t('No backups yet.') : g.last_played ? t('No saves found yet. If it saves somewhere unusual, its developer can say where in recomplauncher.json.') : t('Play it once and its saves are copied here after.'); body = `
- ${unknown ? `` : ''} + ${unknown ? savesUnknownItem(id) : savesStatusItem(id, sv)} + ${unknown || (sv.signedIn && on) ? '' : ``} +

${esc(t('Save History'))}

+ ${on && sv.offline ? `

${esc(t('The cloud can\'t be reached right now, so only the copies on this PC are listed.'))}

` : ''} + ${rows.length ? shown.map((r) => savesHistoryItem(id, r, sv)).join('') : `

${esc(empty)}

`} + ${toggle ? `` : ''} + ${shareTitle ? `

${esc(t('Settings'))}

` : ''} ${shareTitle ? `` : ''} - ${sv.signedIn ? `` : ''} - ${on && sv.signedIn ? (() => { - const newest = Array.isArray(sv.cloud) && sv.cloud[0]; - const line = sv.waiting ? tn(sv.waiting, 'Waiting to upload (1 copy)', 'Waiting to upload ({n} copies)') : newest ? tf('Last uploaded {when} from {device}', { when: whenText(newest.made), device: newest.device || t('this PC') }) : t('Nothing in the cloud yet'); - return ``; - })() : ''} - ${unknown ? '' : ``} -

${esc(t('On this PC'))}

- ${sv.local.length ? sv.local.map((c) => copy(c, 'name', c.name, false)).join('') : `

${esc(unknown ? t('No backups yet.') : g.last_played ? t('No saves found yet. If it saves somewhere unusual, its developer can say where in recomplauncher.json.') : t('Play it once and its saves are copied here after.'))}

`} - ${on && Array.isArray(sv.cloud) ? `

${esc(t('In the cloud'))}

${sv.cloud.length ? sv.cloud.map((c) => copy(c, 'v', c.v, c.hash === sv.synced)).join('') : `

${esc(t('Nothing in the cloud yet. It goes up after you play.'))}

`}` : ''} ${unknown ? '' : `

${esc(t('Where it saves'))}

`} - ${(sv.spots || []).map((p, i) => ``).join('')} + ${(sv.spots || []).map((p, i) => ``).join('')}
`; } return `${backdrop(a, 'game')}${gameBar()} - ${region(`${pageHead(tf('Saves for {game}', { game: a.name }), unknown ? t(SAVES_UNKNOWN) : t('After every session the launcher keeps a copy. Put an older one back with A.'))}${body}`)} + ${region(`${pageHead(tf('Saves for {game}', { game: a.name }), unknown ? t(SAVES_UNKNOWN) : t('After every session the launcher keeps a copy. Restore an older one with A.'))}${body}`)} ${hints([['A', t('Select')], ['B', t('Back')]])}`; } @@ -1767,7 +1803,7 @@ ...(g && !S.running.has(id) ? [{ label: t('Start With'), sub: t('Pick which of its programs starts this time'), icon: 'play', run: () => { closeSheet(); setTimeout(() => window.startWith(id), 250); } }] : []), ...(byId(id) && !byId(id).custom ? [window.isHidden(id) ? { label: t('Show in Discover'), sub: t('It shows in Discover and on Home again'), icon: 'search', run: async () => { closeSheet(); await window.unhideGame(id); draw(true); } } : { label: t('Hide from Discover'), sub: t('It won\'t show in Discover or on Home'), icon: 'stop', run: async () => { closeSheet(); await window.hideGame(id); draw(true); } }] : []), ...(g ? [ - { gap: true, label: t('Saves'), sub: t('Back them up, or put an older one back'), icon: 'save', run: () => go('gsaves', id) }, + { gap: true, label: t('Saves'), sub: t('Back them up, or restore an older one'), icon: 'save', run: () => go('gsaves', id) }, ...((S.setup[id] && S.setup[id] !== 'loading') || looksHere() ? [{ label: t('Game settings'), sub: t('Its own settings, and shaders'), icon: 'gear', run: () => go('gsettings', id) }] : []), { label: t('Screenshots'), icon: 'shot', run: async () => { await loadAllShots(); go('shots', id); } }, ...(S.mods[id] && S.mods[id] !== 'loading' ? [{ label: t('Mods'), icon: 'puzzle', run: () => go('mods', id) }] : []), @@ -2919,6 +2955,8 @@ if (title) await toggleSaveShare(title); return draw(true); } + case 'gs-more': sfx('select'); S.savesMore.add(id); return draw(true); + case 'gs-less': sfx('select'); S.savesMore.delete(id); return draw(true); case 'gs-backup': { sfx('select'); try { const c = await invoke('saves_backup', { id }); toast(c ? t('Backed up.') : t('Nothing changed since the last copy.')); } catch (e) { fail(e); } @@ -2935,10 +2973,12 @@ } case 'gs-restore': { sfx('open'); - const name = el.dataset.name || null, v = el.dataset.v || null; - return sheet(t('Put this save back?'), [ + const name = el.dataset.name || null, v = el.dataset.v || null, cv = el.dataset.cv || null; + const del = { label: t('Delete from the cloud'), sub: t('Gone from your account for good. Copies on this PC stay.'), icon: 'bin', cls: 'danger', run: async () => { try { await invoke('saves_cloud_delete', { id, v: cv }); toast(t('Deleted from the cloud.')); } catch (e) { fail(e); } loadGameSaves(id); } }; + return sheet(t('Restore this save?'), [ { label: t('Keep what\'s there'), sub: t('Nothing changes'), icon: 'chevL', run: () => {} }, - { label: t('Put it back'), sub: t('It takes the place of the game\'s saves on this PC'), icon: 'history', run: async () => { try { await invoke('saves_restore', { id, name, v }); toast(t('That save is back in place.')); } catch (e) { fail(e); } loadGameSaves(id); } }, + { label: t('Restore it'), sub: t('It takes the place of the game\'s saves on this PC'), icon: 'history', run: async () => { try { await invoke('saves_restore', { id, name, v }); toast(t('That save is back in place.')); } catch (e) { fail(e); } loadGameSaves(id); } }, + ...(cv ? [del] : []), ]); } } From e7dfcd316a153e2b96b4796fd399a7fed22a12a9 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 18:31:12 +0000 Subject: [PATCH 11/16] Syncs after you play stays until the save is copied, and a session the launcher didn't see end is finished at its next start --- src-tauri/src/cloud.rs | 68 ++++++++++++++++++++++++++++++++++++++- src-tauri/src/lib.rs | 19 +++++++++-- src-tauri/src/saves.rs | 27 +++++++++++++++- tests/save-badge.test.cjs | 10 ++++++ ui/account.js | 3 ++ 5 files changed, 123 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/cloud.rs b/src-tauri/src/cloud.rs index 96d6781a..85148629 100644 --- a/src-tauri/src/cloud.rs +++ b/src-tauri/src/cloud.rs @@ -576,7 +576,7 @@ fn phase(app: &AppHandle, id: &str, what: &str) { } /// Says "idle" when the work it covers ends, on every way out of it (errors included). -struct Working { +pub(crate) struct Working { app: AppHandle, id: String, } @@ -848,6 +848,8 @@ pub async fn after_session(app: &AppHandle, id: &str) -> Res let spots = spots_of(&st, id, &g); let (dir, id2, g2) = (st.dir.clone(), id.to_string(), g.clone()); let copy = blocking(move || saves::backup(&dir, &id2, &spots, &g2)).await??; + // The session's save is copied: one that fails to go up is kept as pending from here on. + set_after_play(&st.dir, id, false); if g.cloud == Some(true) && signed_in(&st.dir) { let s = saves::state(&st.dir, id); let latest = saves::list(&st.dir, id, &g).into_iter().next(); @@ -883,6 +885,54 @@ pub async fn after_session(app: &AppHandle, id: &str) -> Res Ok(copy) } +/// Marks a game's session as started (true) or its save as copied after it (false). A session +/// still marked when the launcher starts is finished then (finish_open_sessions). +pub(crate) fn set_after_play(dir: &Path, id: &str, open: bool) { + let mut s = saves::state(dir, id); + if s.after_play == open { + return; + } + s.after_play = open; + saves::set_state(dir, id, &s); +} + +/// The step after a game closes, from its end to its save copied (and sent): the status above +/// Play keeps saying "Syncs after you play" until then, instead of an "Up to date" that the +/// session's save may already have made untrue. Ends (idle) on every way out. +pub(crate) fn after_play_step(app: &AppHandle, id: &str) -> Working { + working(app, id, "after") +} + +/// Sessions the launcher didn't see to the end (it closed or crashed while a game ran, or before +/// the copy after it was made): their saves are copied and sent now. A game that's running again +/// is left to its own session. +pub(crate) async fn finish_open_sessions(app: &AppHandle) { + let st = app.state::(); + for id in open_sessions(&st.dir.join("saves")) { + if st.running.lock().unwrap().contains_key(&id) || game(&st, &id).is_err() { + continue; + } + let _step = after_play_step(app, &id); + match after_session(app, &id).await { + Ok(Some(_)) => { + let _ = app.emit("saves", json!({"id": id})); + } + Ok(None) => {} + Err(e) => eprintln!("Save copy for {id} after an unfinished session: {e}"), + } + } +} + +/// The games whose sync notes still mark a session open, by their folders under `saves`. +fn open_sessions(saves_dir: &Path) -> Vec { + let Ok(rd) = std::fs::read_dir(saves_dir) else { return vec![] }; + let app_dir = saves_dir.parent().unwrap_or(saves_dir); + rd.flatten() + .filter_map(|e| e.file_name().to_str().map(String::from)) + .filter(|id| saves::state(app_dir, id).after_play) + .collect() +} + /// Gets a cloud copy and puts it in place (what's there now is kept as a local copy first). async fn take_cloud(app: &AppHandle, id: &str, c: &CloudCopy) -> Res { let st = app.state::(); @@ -1938,6 +1988,22 @@ mod status_tests { d } + #[test] + fn a_session_started_is_open_until_its_save_is_copied() { + let d = tmp("after-play"); + set_after_play(&d, "g", true); + assert_eq!(open_sessions(&d.join("saves")), vec!["g".to_string()]); + set_after_play(&d, "g", false); + assert!(open_sessions(&d.join("saves")).is_empty()); + } + + #[test] + fn a_game_with_no_open_session_is_not_finished_at_start() { + let d = tmp("after-play-none"); + saves::set_state(&d, "g", &saves::State { last_hash: "a".into(), ..Default::default() }); + assert!(open_sessions(&d.join("saves")).is_empty()); + } + #[test] fn a_full_cloud_is_its_own_problem() { assert_eq!(problem_kind(&Error::Msg(FULL_TEXT.into())), "full"); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f647f43f..8e293737 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -3253,6 +3253,9 @@ fn start_game_with_monitor_context( let _ = std::fs::create_dir_all(marker.parent().unwrap_or(&st.dir)); // The launcher's own process id: a marker whose process is gone is stale (see marker_alive). let _ = std::fs::write(&marker, std::process::id().to_string()); + // Its save may change from here: copied after the session, or at the next start if the + // launcher closes before that. + cloud::set_after_play(&st.dir, &save_id, true); ingame::set_hotkeys(app, true, quick_menu); let _ = app.emit("game", json!({"id": id, "game": game_full, "state": "running"})); // From Big Picture mode the launcher fills the screen, so it steps aside for the game (its first @@ -3333,6 +3336,9 @@ fn start_game_with_monitor_context( } let secs = start.elapsed().as_secs(); let st = app2.state::(); + // From the game closing to its save copied, the status above Play says so, not an "Up to + // date" the session may have made untrue. Said before the window hears the game stopped. + let after_step = (secs >= 5).then(|| cloud::after_play_step(&app2, &save_id)); // A game that closes with the same code every time it's quit normally (its profile or the // catalog says which): that's a normal close, not a crash. let code = code.map(|c| if quit_code(&st, &id, prof.as_ref(), c) { 0 } else { c }); @@ -3367,6 +3373,10 @@ fn start_game_with_monitor_context( pads::PLAYING.store(!st.running.lock().unwrap().is_empty(), Ordering::Relaxed); if !st.running.lock().unwrap().contains_key(&id) { let _ = std::fs::remove_file(playing_file(&st.dir, &id)); + // Under five seconds there's no copy after it (below): nothing left to finish. + if secs < 5 { + cloud::set_after_play(&st.dir, &save_id, false); + } } if let Some(g) = st.lib.lock().unwrap().installed.get_mut(&id) { g.played_secs += secs; @@ -3423,6 +3433,7 @@ fn start_game_with_monitor_context( Err(e) => eprintln!("Save copy for {id}: {e}"), } } + drop(after_step); // Started from a shortcut with no window: the launcher's job is done. if st.headless.load(Ordering::Relaxed) && st.running.lock().unwrap().is_empty() { app2.exit(0); @@ -9997,10 +10008,14 @@ pub fn run() { repair_lost_setups(&st); }); } - // Save copies that didn't reach the cloud last time. + // Sessions the launcher didn't see to the end (it closed or crashed before their saves + // were copied) are finished first, then save copies that didn't reach the cloud. { let h = app.handle().clone(); - tauri::async_runtime::spawn(async move { cloud::upload_pending(&h).await }); + tauri::async_runtime::spawn(async move { + cloud::finish_open_sessions(&h).await; + cloud::upload_pending(&h).await; + }); } // Screenshots show in the window straight from their folder, wherever Pictures is. The // folder itself is only made when the first screenshot is taken. diff --git a/src-tauri/src/saves.rs b/src-tauri/src/saves.rs index 227d1de9..764f41af 100644 --- a/src-tauri/src/saves.rs +++ b/src-tauri/src/saves.rs @@ -698,6 +698,11 @@ pub struct State { /// Why the last sync didn't go through. Kept until one does. #[serde(default, skip_serializing_if = "Option::is_none")] pub problem: Option, + /// A session started and its save hasn't been copied since: set at Play, cleared once the + /// copy after it is made. Still set when the launcher closed (or crashed) before that, so the + /// next start makes the copy and sends it. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub after_play: bool, } /// Why a game's saves didn't reach the cloud. `kind` is one of: offline, full, paused, @@ -744,7 +749,9 @@ impl State { if kind == "too-big-folder" { return "problem"; } - if !self.behind() { + // A session whose save hasn't been copied yet may have changed it: not up to date until the + // copy after it is made. + if !self.behind() && !self.after_play { return if self.synced_hash.is_empty() && self.last_hash.is_empty() { "none" } else { "up-to-date" }; } // No connection is only waiting: it goes up by itself once the website answers. @@ -2019,6 +2026,24 @@ mod sync_state_tests { Some(Problem { kind: kind.into(), text: String::new(), at: 1 }) } + #[test] + fn a_session_not_copied_yet_is_waiting_not_up_to_date() { + let s = State { last_hash: "a".into(), synced_hash: "a".into(), after_play: true, ..Default::default() }; + assert_eq!(s.sync_state(true, true), "waiting"); + } + + #[test] + fn a_first_session_not_copied_yet_is_waiting_not_none() { + let s = State { after_play: true, ..Default::default() }; + assert_eq!(s.sync_state(true, true), "waiting"); + } + + #[test] + fn a_session_not_copied_yet_is_left_out_of_the_file_when_there_is_none() { + let s = State { last_hash: "a".into(), ..Default::default() }; + assert!(!serde_json::to_string(&s).unwrap().contains("after_play")); + } + #[test] fn signed_out_comes_first() { let s = State { last_hash: "a".into(), synced_hash: "a".into(), ..Default::default() }; diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs index 92339dd5..42c13f55 100644 --- a/tests/save-badge.test.cjs +++ b/tests/save-badge.test.cjs @@ -57,6 +57,16 @@ test('a game being played says its save goes up after', () => { assert.equal(b.label, 'Syncs after you play'); }); +test('right after the game closes it still says the save goes up after play, not up to date', () => { + const b = info.saveBadgeInfo(status('up-to-date', { syncedAt: now() }), 'after', false); + assert.equal(b.label, 'Syncs after you play'); +}); + +test('a session the launcher has not copied yet is waiting, not up to date', () => { + const b = info.saveBadgeInfo(status('waiting'), undefined, false); + assert.equal(b.tone, 'warn'); +}); + test('a conflict still asks for a choice while the game runs', () => { const b = info.saveBadgeInfo(status('conflict'), undefined, true); assert.equal(b.label, 'Choose a save'); diff --git a/ui/account.js b/ui/account.js index 44ee8cc3..6dc61dbc 100644 --- a/ui/account.js +++ b/ui/account.js @@ -306,6 +306,9 @@ const PHASE_BADGE = { check: { mark: 'check-run', label: N_('Checking cloud…'), head: N_('Looking for a newer save'), text: N_('Before the game starts, the launcher checks whether another PC saved after this one.') }, up: { mark: 'up', label: N_('Uploading…'), head: N_('Sending your save'), text: N_('Your newest save is going to the cloud.') }, down: { mark: 'down', label: N_('Getting cloud save…'), head: N_('Bringing in a newer save'), text: N_('Another PC saved after this one. Your current save is kept as a backup first.') }, + // The game just closed (or crashed, or the launcher is finishing a session it didn't see end): + // its save is being copied, and sent when cloud saves are on. + after: { mark: 'play', label: N_('Syncs after you play'), head: N_('Saving after you played'), text: N_('Its save is being copied, and sent to the cloud when cloud saves are on.') }, }; // What the status line shows for a game: its tone (ok, cy, warn, bad, dim), the mark inside the From b22fd8c494e92d7d8cc4c6c645378149645a06df Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 18:36:47 +0000 Subject: [PATCH 12/16] Which save: this PC's is dated by its first copy, so a restored older save isn't called Newer --- src-tauri/src/cloud.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/cloud.rs b/src-tauri/src/cloud.rs index 85148629..9308384f 100644 --- a/src-tauri/src/cloud.rs +++ b/src-tauri/src/cloud.rs @@ -885,6 +885,14 @@ pub async fn after_session(app: &AppHandle, id: &str) -> Res Ok(copy) } +/// When this PC's save was made, for the "which save?" choice: the time of the first copy holding +/// it (the same save is copied again before a restore or a cloud save replaces it). The files' +/// own time is only the fallback: restoring a copy writes them anew, which made an older save look +/// newer than the cloud's. +fn local_save_time(copies: &[saves::Copy], hash: &str, files_time: u64) -> u64 { + copies.iter().filter(|c| c.hash == hash).map(|c| c.when).min().unwrap_or(files_time) +} + /// Marks a game's session as started (true) or its save as copied after it (false). A session /// still marked when the launcher starts is finished then (finish_open_sessions). pub(crate) fn set_after_play(dir: &Path, id: &str, open: bool) { @@ -1117,7 +1125,8 @@ async fn check_saves(app: AppHandle, id: String, manual: bool) -> Res { s.conflict = Some(top.v.clone()); saves::set_state(&st.dir, &id, &s); let newest = entries.iter().filter_map(|e| std::fs::metadata(&e.abs).ok()?.modified().ok()).max(); - let when = newest.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()).map(|d| d.as_secs()).unwrap_or(0); + let files_time = newest.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()).map(|d| d.as_secs()).unwrap_or(0); + let when = local_save_time(&saves::list(&st.dir, &id, &g), &local, files_time); Ok(json!({"action": "conflict", "local": {"when": when, "device": saves::device_name(), "played": g.played_secs, "hash": local}, "cloud": top})) } @@ -1988,6 +1997,27 @@ mod status_tests { d } + fn copy_made(when: u64, hash: &str) -> saves::Copy { + saves::Copy { name: format!("{when}.zip"), when, size: 1, files: 1, hash: hash.into(), device: String::new(), played: 0 } + } + + #[test] + fn a_restored_save_is_dated_by_its_copy_not_by_when_it_was_written_back() { + let copies = [copy_made(300, "new"), copy_made(100, "old")]; + assert_eq!(local_save_time(&copies, "old", 500), 100); + } + + #[test] + fn a_save_copied_twice_is_dated_by_its_first_copy() { + let copies = [copy_made(400, "old"), copy_made(300, "new"), copy_made(100, "old")]; + assert_eq!(local_save_time(&copies, "old", 500), 100); + } + + #[test] + fn a_save_no_copy_holds_is_dated_by_its_files() { + assert_eq!(local_save_time(&[copy_made(300, "new")], "changed", 500), 500); + } + #[test] fn a_session_started_is_open_until_its_save_is_copied() { let d = tmp("after-play"); From b826c407012771586a7bbc43946845f60c629b17 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 18:43:20 +0000 Subject: [PATCH 13/16] No dead ends: the step after a game closes, and a session finished at the next start --- tests/saves-tab.test.cjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/saves-tab.test.cjs b/tests/saves-tab.test.cjs index 4c12cb8c..c6c5f029 100644 --- a/tests/saves-tab.test.cjs +++ b/tests/saves-tab.test.cjs @@ -169,6 +169,8 @@ const SITUATIONS = [ ['a newer save going up after the next session', { state: 'waiting' }, {}, 'saves-sync'], ['a copy waiting while offline', { state: 'waiting', problem: { kind: 'offline' } }, {}, 'saves-sync'], ['an upload running', { state: 'waiting' }, { phase: 'up' }, 'by itself'], + ['the game just closed, its save being copied', { state: 'waiting' }, { phase: 'after' }, 'by itself'], + ['the launcher crashed before copying a session (finished at its next start)', { state: 'waiting' }, {}, 'saves-sync'], ['an upload that failed', problem('error'), {}, 'saves-sync'], ['cloud saves paused by the site', problem('paused'), {}, 'by itself'], ['a save too big to upload', problem('too-big-copy'), {}, 'report'], From d71681f155b0c0ddcfdc9530fe0883aac07411d5 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 18:48:05 +0000 Subject: [PATCH 14/16] Any copy of the save ends the wait, so Waiting to upload can't outlive a Sync Now --- src-tauri/src/cloud.rs | 3 +-- src-tauri/src/saves.rs | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/cloud.rs b/src-tauri/src/cloud.rs index 9308384f..502774c1 100644 --- a/src-tauri/src/cloud.rs +++ b/src-tauri/src/cloud.rs @@ -847,9 +847,8 @@ pub async fn after_session(app: &AppHandle, id: &str) -> Res let g = game(&st, id)?; let spots = spots_of(&st, id, &g); let (dir, id2, g2) = (st.dir.clone(), id.to_string(), g.clone()); + // The copy ends the session's wait (saves::backup); one that fails to go up is kept as pending. let copy = blocking(move || saves::backup(&dir, &id2, &spots, &g2)).await??; - // The session's save is copied: one that fails to go up is kept as pending from here on. - set_after_play(&st.dir, id, false); if g.cloud == Some(true) && signed_in(&st.dir) { let s = saves::state(&st.dir, id); let latest = saves::list(&st.dir, id, &g).into_iter().next(); diff --git a/src-tauri/src/saves.rs b/src-tauri/src/saves.rs index 764f41af..d447a2ae 100644 --- a/src-tauri/src/saves.rs +++ b/src-tauri/src/saves.rs @@ -821,6 +821,19 @@ pub fn list(app_dir: &Path, id: &str, g: &Installed) -> Vec { out } +/// The save as it is now has a copy (or there is none to copy): no session waits on it anymore. +/// Every copy clears it, whatever made it (after a session, Sync Now, Back Up Now, before a restore +/// or a cloud save), so "Waiting to upload" can't outlive the copy. All of those run with the game +/// closed, so none ends a session that's still going. +fn copied(app_dir: &Path, id: &str) { + let mut st = state(app_dir, id); + if !st.after_play { + return; + } + st.after_play = false; + set_state(app_dir, id, &st); +} + /// Writes a copy of the saves as they are now. None when there are none, or nothing changed since /// the last copy. pub fn backup(app_dir: &Path, id: &str, spots: &[Spot], g: &Installed) -> Result, Error> { @@ -831,15 +844,18 @@ pub fn backup(app_dir: &Path, id: &str, spots: &[Spot], g: &Installed) -> Result return Err(too_big_error(g, spots, &too_big)); } if pre.is_empty() { + copied(app_dir, id); return Ok(None); } let (entries, infos, hash, _) = current(spots, g); if entries.is_empty() { + copied(app_dir, id); return Ok(None); } let mut st = state(app_dir, id); let all = list(app_dir, id, g); if st.last_hash == hash && all.first().map(|c| c.hash == hash).unwrap_or(false) { + copied(app_dir, id); return Ok(None); } let d = dir_of(app_dir, id, g); @@ -881,6 +897,7 @@ pub fn backup(app_dir: &Path, id: &str, spots: &[Spot], g: &Installed) -> Result } } st.last_hash = hash.clone(); + st.after_play = false; set_state(app_dir, id, &st); let size = fs::metadata(&file).map(|m| m.len()).unwrap_or(0); Ok(Some(Copy { name: format!("{when}.zip"), when, size, files: infos.len(), hash, device: man.device, played: man.played })) @@ -1315,6 +1332,36 @@ mod tests { Installed { id: "g".into(), name: "Test Game".into(), path: dir.to_path_buf(), files: vec![PathBuf::from("game.exe"), PathBuf::from("data/a.bin")], played_secs: 60, ..Default::default() } } + // A game whose saves are in {install}/save, with one save file in it. + fn game_with_a_save(d: &Path) -> (Installed, Vec, PathBuf) { + let g = game(&d.join("lib/Game")); + fs::create_dir_all(d.join("lib/Game/save")).unwrap(); + fs::write(d.join("lib/Game/save/slot.sav"), b"one").unwrap(); + let s = spots(&["{install}/save".into()], &[], &g); + (g, s, d.join("app")) + } + + #[test] + fn a_copy_of_the_save_ends_the_open_session() { + let d = tmp("copy-ends-session"); + let (g, s, app) = game_with_a_save(&d); + set_state(&app, "g", &State { after_play: true, ..Default::default() }); + backup(&app, "g", &s, &g).unwrap(); + assert!(!state(&app, "g").after_play); + } + + #[test] + fn a_save_already_copied_ends_the_open_session_too() { + let d = tmp("copied-ends-session"); + let (g, s, app) = game_with_a_save(&d); + backup(&app, "g", &s, &g).unwrap(); + let mut st = state(&app, "g"); + st.after_play = true; + set_state(&app, "g", &st); + assert!(backup(&app, "g", &s, &g).unwrap().is_none()); + assert!(!state(&app, "g").after_play); + } + #[test] fn nothing_known_means_no_save_places() { let g = game(Path::new("/games/test")); From e26b97e22a9f20e324a12bbac8f234084198621d Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 18:53:58 +0000 Subject: [PATCH 15/16] The copy after a session is only called a sync for a game that syncs --- tests/save-badge.test.cjs | 10 ++++++++++ ui/account.js | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs index 42c13f55..9d74bfc6 100644 --- a/tests/save-badge.test.cjs +++ b/tests/save-badge.test.cjs @@ -57,6 +57,16 @@ test('a game being played says its save goes up after', () => { assert.equal(b.label, 'Syncs after you play'); }); +test('with cloud saves off, the copy after a session is not called a sync', () => { + const b = info.saveBadgeInfo(status('off'), 'after', false); + assert.equal(b.label, 'Cloud saves off'); +}); + +test('signed out, the copy after a session is not called a sync', () => { + const b = info.saveBadgeInfo(status('signed-out'), 'after', false); + assert.equal(b.label, 'Not signed in'); +}); + test('right after the game closes it still says the save goes up after play, not up to date', () => { const b = info.saveBadgeInfo(status('up-to-date', { syncedAt: now() }), 'after', false); assert.equal(b.label, 'Syncs after you play'); diff --git a/ui/account.js b/ui/account.js index 6dc61dbc..ecd94c55 100644 --- a/ui/account.js +++ b/ui/account.js @@ -315,7 +315,10 @@ const PHASE_BADGE = { // cloud, a label and a short note, and for the tooltip a heading, a line and rows ([label, value]). // `phase` is what's running now, `running` whether the game is. function saveBadgeInfo(st, phase, running) { - const p = PHASE_BADGE[phase]; + // The copy after a session runs for every game; it's only shown for one that syncs. Signed out + // or with cloud saves off, the line keeps saying so instead of a sync that isn't happening. + const syncs = st.state !== 'signed-out' && st.state !== 'off' && st.known !== false; + const p = syncs && PHASE_BADGE[phase]; if (p) return { tone: 'cy', mark: p.mark, label: t(p.label), note: '', head: t(p.head), text: t(p.text), rows: [] }; const synced = st.syncedAt ? [[t('Last synced'), whenText(st.syncedAt)], [t('Saved on'), st.syncedDevice || t('this PC')]] : []; const newest = st.newest ? [[t('Last backup'), `${whenText(st.newest.when)}${st.newest.device ? ' · ' + st.newest.device : ''}`]] : []; From c2def1933078b6643e04acadbd48c70d475742f1 Mon Sep 17 00:00:00 2001 From: Zacharias Xenakis Date: Thu, 19 Nov 2026 18:55:20 +0000 Subject: [PATCH 16/16] A game with no known save folder keeps saying so after a session --- tests/save-badge.test.cjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/save-badge.test.cjs b/tests/save-badge.test.cjs index 43082a46..bb2b5a50 100644 --- a/tests/save-badge.test.cjs +++ b/tests/save-badge.test.cjs @@ -67,6 +67,11 @@ test('signed out, the copy after a session is not called a sync', () => { assert.equal(b.label, 'Not signed in'); }); +test('with no known save folder, the step after a session does not hide that nothing is backed up', () => { + const b = info.saveBadgeInfo(status('none', { known: false }), 'after', false); + assert.equal(b.label, 'Saves not backed up'); +}); + test('right after the game closes it still says the save goes up after play, not up to date', () => { const b = info.saveBadgeInfo(status('up-to-date', { syncedAt: now() }), 'after', false); assert.equal(b.label, 'Syncs after you play');