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 502774c1..6ad71fe4 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, @@ -1237,6 +1249,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(), @@ -1505,8 +1520,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(); @@ -1996,6 +2032,10 @@ mod status_tests { d } + fn cloud_copy(v: &str) -> CloudCopy { + CloudCopy { v: v.into(), ..Default::default() } + } + 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 } } @@ -2033,6 +2073,35 @@ mod status_tests { assert!(open_sessions(&d.join("saves")).is_empty()); } + #[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 33b615c0..f7703cb5 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -10190,7 +10190,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/src-tauri/src/saves.rs b/src-tauri/src/saves.rs index d447a2ae..33bd16bd 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 @@ -1302,7 +1304,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(); @@ -1455,6 +1457,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"); 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 9d74bfc6..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'); @@ -124,6 +129,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..c6c5f029 --- /dev/null +++ b/tests/saves-tab.test.cjs @@ -0,0 +1,234 @@ +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 @@ -320,6 +495,10 @@ function saveBadgeInfo(st, phase, running) { 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: [] }; + // 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 }; @@ -405,6 +584,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 = {}; @@ -474,7 +660,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)} @@ -680,6 +866,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': { @@ -690,7 +885,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; @@ -700,8 +894,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); @@ -719,7 +913,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 9d754daa..ae4778d6 100644 --- a/ui/app.css +++ b/ui/app.css @@ -2597,9 +2597,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)} @@ -2613,3 +2614,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/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); 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] : []), ]); } }