diff --git a/crates/summit-cli/src/main.rs b/crates/summit-cli/src/main.rs index 7699484..9cd6059 100644 --- a/crates/summit-cli/src/main.rs +++ b/crates/summit-cli/src/main.rs @@ -168,10 +168,7 @@ fn main() -> Result<()> { println!("resolved {n}"); } Cmd::Add { title, path, software } => { - anyhow::ensure!(path.exists(), "{} does not exist", path.display()); - let id = format!("custom:{}", title.to_lowercase().replace(' ', "-")); - let custom = state::Custom { id: id.clone(), title, path: state::path_text(&path.canonicalize()?)?, software }; - state::update(|st| { st.custom.retain(|c| c.id != id); st.custom.push(custom); })?; println!("added {id}"); + println!("added {}", state::add_custom(&title, &path, software)?); } Cmd::Enhance { profile, source, no_watermark, out, max_ticks, dry_run } => { let eng = engine::find_engine().ok_or_else(|| anyhow::anyhow!("engine not found: set SUMMIT_ENGINE to the engine/ folder"))?; diff --git a/crates/summit-core/src/state.rs b/crates/summit-core/src/state.rs index bbb00fa..2c30cfc 100644 --- a/crates/summit-core/src/state.rs +++ b/crates/summit-core/src/state.rs @@ -35,6 +35,37 @@ pub fn load() -> State { pub fn save(s: &State) -> Result<()> { write_atomic(&path()?, serde_json::to_string_pretty(s)?.as_bytes()) } +/// The entry `summit add` (and the launcher's Add a game) stores: id `custom:`. +pub fn custom_for(title: &str, path: &std::path::Path, software: bool) -> Result { + let title = title.trim(); + anyhow::ensure!(!title.is_empty(), "the name is empty"); + anyhow::ensure!(path.exists(), "{} does not exist", path.display()); + let id = format!("custom:{}", title.to_lowercase().replace(' ', "-")); + Ok(Custom { id, title: title.to_string(), path: path_text(&path.canonicalize()?)?, software }) +} + +/// Add (or replace, same id) an entry by hand. Returns its id. +pub fn add_custom(title: &str, path: &std::path::Path, software: bool) -> Result { + let c = custom_for(title, path, software)?; + let id = c.id.clone(); + update(|st| { st.custom.retain(|x| x.id != id); st.custom.push(c); })?; + Ok(id) +} + +/// A name for a game from the file picked to start it: its folder's name, unless that folder is a generic one +/// (`bin`, `x86_64`, `Binaries/Linux`...), then the next folder up; the file name if no folder fits. +pub fn title_guess(file: &std::path::Path) -> String { + const GENERIC: &[&str] = &["bin", "bin32", "bin64", "x86", "x64", "x86_64", "amd64", "linux", "linux64", "linux32", + "win32", "win64", "windows", "binaries", "game", "games", "release", "build", "data", "app", "files", "home", "opt", "usr", "local", "applications"]; + let tidy = |s: &str| s.replace(['_', '-'], " ").split_whitespace().collect::>().join(" "); + for dir in file.ancestors().skip(1).take(3) { + let Some(name) = dir.file_name().and_then(|n| n.to_str()) else { break }; + if !name.starts_with('.') && !GENERIC.contains(&name.to_ascii_lowercase().as_str()) { return tidy(name); } + } + let stem = file.file_stem().and_then(|n| n.to_str()).unwrap_or("Game"); + tidy(stem.split('.').next().unwrap_or(stem)) +} + /// Load, change and save `state.json` while holding a lock (`flock` on `state.json.lock`), so the launcher saving a /// pin and `summit run` saving a session at the same moment both keep their change. Returns the saved state. pub fn update(f: impl FnOnce(&mut State)) -> Result { update_at(&path()?, f) } @@ -112,6 +143,22 @@ pub fn apply(entries: &mut [crate::model::Entry], st: &State) { #[cfg(test)] mod tests { + #[test] + fn title_guess_skips_generic_folders() { + use std::path::Path; + assert_eq!(super::title_guess(Path::new("/home/u/Games/Voidrunner/top_down_shooter")), "Voidrunner"); + assert_eq!(super::title_guess(Path::new("/games/Hollow_Knight/bin/x86_64/hollow_knight.x86_64")), "Hollow Knight"); + assert_eq!(super::title_guess(Path::new("/games/Cool-Game/Binaries/Linux/CoolGame-Linux-Shipping")), "Cool Game"); + assert_eq!(super::title_guess(Path::new("/opt/bin/launch.sh")), "launch"); + } + #[test] + fn custom_ids_and_refusals() { + let f = std::env::current_exe().unwrap(); + let c = super::custom_for(" My Game ", &f, false).unwrap(); + assert_eq!((c.id.as_str(), c.title.as_str()), ("custom:my-game", "My Game")); + assert!(super::custom_for(" ", &f, false).is_err()); + assert!(super::custom_for("X", std::path::Path::new("/nonexistent/summit/x"), false).is_err()); + } #[test] fn concurrent_updates_all_land() { let d = std::env::temp_dir().join(format!("summit-state-lock-{}", std::process::id())); diff --git a/crates/summit-gui/src/art.rs b/crates/summit-gui/src/art.rs index 644200b..def7f2a 100644 --- a/crates/summit-gui/src/art.rs +++ b/crates/summit-gui/src/art.rs @@ -11,12 +11,12 @@ pub type Rgb = SharedPixelBuffer; pub type Rgba = SharedPixelBuffer; pub enum Job { - Cover { idx: usize, path: PathBuf }, + Cover { idx: usize, gen: u64, path: PathBuf }, Backdrop { idx: usize, seq: u64, hero: Option, cover: Option, logo: Option, c1: [u8; 3], c2: [u8; 3] }, } pub enum Done { - Cover { idx: usize, img: Option }, + Cover { idx: usize, gen: u64, img: Option }, Backdrop { idx: usize, seq: u64, img: Rgb, logo: Option }, } @@ -87,7 +87,7 @@ pub fn logo(path: &Path) -> Option { pub fn run(job: Job) -> Done { match job { - Job::Cover { idx, path } => Done::Cover { idx, img: cover(&path) }, + Job::Cover { idx, gen, path } => Done::Cover { idx, gen, img: cover(&path) }, Job::Backdrop { idx, seq, hero, cover, logo: l, c1, c2 } => Done::Backdrop { idx, seq, img: backdrop(hero.as_deref(), cover.as_deref(), c1, c2), logo: l.as_deref().and_then(logo), }, @@ -175,7 +175,7 @@ mod tests { #[test] fn queue_loader_hands_jobs_back() { let l = Loader::queued(); - l.push(Job::Cover { idx: 3, path: "/x".into() }); + l.push(Job::Cover { idx: 3, gen: 0, path: "/x".into() }); assert_eq!(l.take().len(), 1); assert!(l.take().is_empty()); } diff --git a/crates/summit-gui/src/data.rs b/crates/summit-gui/src/data.rs index 05f9898..edc590f 100644 --- a/crates/summit-gui/src/data.rs +++ b/crates/summit-gui/src/data.rs @@ -232,15 +232,36 @@ pub fn last_error(log: &str) -> Option { /// The desktop's file dialog for picking a cover: kdialog on KDE, zenity elsewhere (whichever is installed, the /// desktop's own first). `None` when neither is there. pub fn art_picker(kde: bool, have: impl Fn(&str) -> bool, start: &str) -> Option> { + file_picker(kde, have, start, "Summit: pick a cover image", Some(("Images", "*.png *.jpg *.jpeg *.webp"))) +} + +/// Add a game: pick the file that starts it (any file: Linux games rarely have an extension). +pub fn exe_picker(kde: bool, have: impl Fn(&str) -> bool, start: &str) -> Option> { + file_picker(kde, have, start, "Summit: pick the file that starts the game", None) +} + +/// The desktop's own dialog first (kdialog on KDE, zenity elsewhere); `filter` is (label, "*.a *.b"). +fn file_picker(kde: bool, have: impl Fn(&str) -> bool, start: &str, title: &str, filter: Option<(&str, &str)>) -> Option> { let order = if kde { ["kdialog", "zenity"] } else { ["zenity", "kdialog"] }; let name = order.into_iter().find(|n| have(n))?; - Some(if name == "kdialog" { - vec!["kdialog".to_string(), "--title".into(), "Summit: pick a cover image".into(), - "--getopenfilename".into(), start.into(), "*.png *.jpg *.jpeg *.webp|Images".into()] + let mut v = if name == "kdialog" { + vec!["kdialog".to_string(), "--title".into(), title.into(), "--getopenfilename".into(), start.into()] } else { - vec!["zenity".to_string(), "--file-selection".into(), "--title=Summit: pick a cover image".into(), - format!("--filename={start}/"), "--file-filter=Images | *.png *.jpg *.jpeg *.webp".into()] - }) + vec!["zenity".to_string(), "--file-selection".into(), format!("--title={title}"), format!("--filename={start}/")] + }; + if let Some((label, pats)) = filter { + v.push(if name == "kdialog" { format!("{pats}|{label}") } else { format!("--file-filter={label} | {pats}") }); + } + Some(v) +} + +/// After picking the file: ask for the game's name, with a guess filled in. Same tool as the file dialog. +pub fn name_prompt(tool: &str, guess: &str) -> Vec { + if tool == "kdialog" { + vec!["kdialog".into(), "--title".into(), "Summit: add a game".into(), "--inputbox".into(), "Name of the game".into(), guess.into()] + } else { + vec!["zenity".into(), "--entry".into(), "--title=Summit: add a game".into(), "--text=Name of the game".into(), format!("--entry-text={guess}")] + } } #[cfg(test)] @@ -260,6 +281,11 @@ mod tests { assert_eq!(super::art_picker(true, |n: &str| n == "zenity", "/h").unwrap()[0], "zenity"); assert!(super::art_picker(false, |_: &str| false, "/h").is_none()); assert!(super::art_picker(false, both, "/h").unwrap().contains(&"--filename=/h/".to_string())); + assert_eq!(super::art_picker(true, both, "/h").unwrap().last().unwrap(), "*.png *.jpg *.jpeg *.webp|Images"); + assert_eq!(super::exe_picker(true, both, "/g").unwrap().last().unwrap(), "/g"); + assert!(super::exe_picker(false, both, "/g").unwrap().iter().all(|a| !a.starts_with("--file-filter"))); + assert_eq!(super::name_prompt("zenity", "Voidrunner").last().unwrap(), "--entry-text=Voidrunner"); + assert_eq!(super::name_prompt("kdialog", "Voidrunner").last().unwrap(), "Voidrunner"); } use super::*; diff --git a/crates/summit-gui/src/main.rs b/crates/summit-gui/src/main.rs index 32da201..ce6f3cc 100644 --- a/crates/summit-gui/src/main.rs +++ b/crates/summit-gui/src/main.rs @@ -42,6 +42,10 @@ pub struct App { save_timer: slint::Timer, /// The profile editor's game id and the outputs listed when it opened (or why there is no list). editing: RefCell>, + /// Folders given on the command line, scanned again when the library reloads. + folders: Vec, + /// Bumped when the library reloads: a cover loaded for the old list is dropped, not put on the wrong row. + gen: Cell, } /// The monitors listed when the profile editor opened, or why there is no list. @@ -66,6 +70,7 @@ impl App { let action = match launch::plan(e, self.cli().as_deref(), false) { launch::Plan::Run(_) if launch::is_install(e) => "INSTALL", launch::Plan::Run(_) => "PLAY", + launch::Plan::Unsupported(_) if e.source == Source::Heuristic => "ADD", launch::Plan::Unsupported(_) => "", }; Game { @@ -116,7 +121,7 @@ impl App { fn want_cover(&self, idx: usize) { if idx >= self.entries.borrow().len() || !self.requested.borrow_mut().insert(idx) { return; } let path = self.cover_path(&self.entries.borrow()[idx]); - if let Some(path) = path { self.loader.push(art::Job::Cover { idx, path }); } + if let Some(path) = path { self.loader.push(art::Job::Cover { idx, gen: self.gen.get(), path }); } } fn focus_game(&self, idx: i32) { @@ -131,7 +136,8 @@ impl App { pub fn apply(&self, done: art::Done) { match done { - art::Done::Cover { idx, img } => { + art::Done::Cover { idx, gen, img } => { + if gen != self.gen.get() { return; } let Some(img) = img else { return }; let Some(mut g) = self.games.row_data(idx) else { return }; g.cover = Image::from_rgb8(img); g.has_cover = true; @@ -190,6 +196,7 @@ impl App { launch::Plan::Run(_) if e.source == Source::Steam => ("PLAY", true, "Starts through summit run and the Steam client: the display profile is applied, Steam keeps the playtime. Not tested with a real Steam yet.".to_string()), launch::Plan::Run(_) if e.source == Source::Lutris => ("PLAY", true, "Starts through summit run and Lutris. Not tested yet.".to_string()), launch::Plan::Run(_) => ("PLAY", true, "Summit starts it, applies the launch profile and tracks the session.".to_string()), + launch::Plan::Unsupported(_) if e.source == Source::Heuristic => ("ADD", true, "Found on disk. ADD asks for the file that starts it and a name, then the game can be played from Summit.".to_string()), launch::Plan::Unsupported(why) => ("PLAY", false, format!("Summit cannot start this yet: {why}.")), }; let (can_enhance, enhance_note) = self.enhance_available(&e); @@ -222,6 +229,7 @@ impl App { fn play(&self, idx: i32) { let Some(e) = self.entries.borrow().get(idx.max(0) as usize).cloned() else { return }; + if e.source == Source::Heuristic { return self.add_game(idx); } // Checked for this entry: Play on Home's hero is not the game whose page was opened last. let enhance = profile::load(&e.id).map(|p| p.enhance).unwrap_or(false) && self.enhance_available(&e).0; let argv = match launch::plan(&e, self.cli().as_deref(), enhance) { @@ -277,6 +285,69 @@ impl App { } } + // ---- adding games ---- + /// "Add a game" (idx -1, from the Library) or ADD on a folder found on disk: the desktop's file dialog picks the + /// file that starts the game, a second dialog asks for its name, then the library reloads with it. + fn add_game(&self, idx: i32) { + let found = usize::try_from(idx).ok().and_then(|i| self.entries.borrow().get(i).cloned()); + let hint = "or from a terminal: summit add \"My Game\" /path/to/game"; + if self.headless { return self.toast(format!("Headless render, no file dialog ({hint})")); } + let kde = display::detect_desktop() == display::Desktop::Kde; + let home = std::env::var("HOME").unwrap_or_else(|_| "/".into()); + let start = found.as_ref().and_then(|e| e.path.clone()).into_iter() + .chain([format!("{home}/Games"), home.clone()]) + .find(|d| std::path::Path::new(d).is_dir()).unwrap_or(home); + let Some(argv) = data::exe_picker(kde, summit_core::doctor::on_path, &start) else { + return self.toast(format!("No file dialog found: install zenity or kdialog, {hint}")); + }; + let found_title = found.map(|e| e.title); + std::thread::spawn(move || { + let ask = |argv: &[String]| -> Option { + let o = std::process::Command::new(&argv[0]).args(&argv[1..]).stdin(std::process::Stdio::null()).stderr(std::process::Stdio::null()).output().ok()?; + if !o.status.success() { return None; } // cancelled + Some(String::from_utf8_lossy(&o.stdout).trim_end_matches(['\n', '\r']).to_string()).filter(|s| !s.trim().is_empty()) + }; + let Some(file) = ask(&argv).map(PathBuf::from) else { return }; + let guess = found_title.unwrap_or_else(|| state::title_guess(&file)); + let Some(title) = ask(&data::name_prompt(&argv[0], &guess)) else { return }; + let _ = slint::invoke_from_event_loop(move || with_app(|a| a.finish_add(&title, &file))); + }); + } + + fn finish_add(&self, title: &str, file: &std::path::Path) { + if file.is_dir() { return self.toast(format!("{} is a folder: pick the file that starts the game", tilde(file))); } + let id = match state::add_custom(title, file, false) { + Ok(id) => id, + Err(err) => return self.toast(format!("Could not add {title}: {err}")), + }; + self.reload(); + let idx = self.entries.borrow().iter().position(|e| e.id == id); + if let Some(i) = idx { self.open_detail(i as i32); } + use std::os::unix::fs::PermissionsExt; + let runnable = std::fs::metadata(file).map(|m| m.permissions().mode() & 0o111 != 0).unwrap_or(false); + self.toast(if runnable { format!("Added {title}") } else { + format!("Added {title}, but {} is not executable: Play will fail until it is (chmod +x)", tilde(file)) + }); + } + + /// Scan everything again (after adding a game): new list, shelves, counts; covers load again as cards ask. + fn reload(&self) { + let mut entries = scan::full(&self.folders, 4); + let st = state::load(); + state::apply(&mut entries, &st); + *self.state.borrow_mut() = st; + *self.entries.borrow_mut() = entries; + self.gen.set(self.gen.get() + 1); + self.requested.borrow_mut().clear(); + self.loaded.borrow_mut().clear(); + self.backdrop_for.set(-1); + let rows: Vec = self.entries.borrow().iter().map(|e| self.row(e, None)).collect(); + self.games.set_vec(rows); + self.fill_static(); + self.rebuild_shelves(); + self.requery(); + } + // ---- artwork ---- /// "Change artwork": the desktop's file dialog runs on a thread of its own; the picked file becomes the cover. fn change_art(&self, idx: i32) { @@ -503,6 +574,7 @@ fn pick(v: &str, names: &[String]) -> Option { pub fn build(headless: bool) -> Rc { let args: Vec = std::env::args().skip(1).collect(); let folders: Vec = args.iter().filter(|a| !a.starts_with("--")).map(Into::into).collect(); + let scan_folders = folders.clone(); let mut entries = scan::full(&folders, 4); let st = state::load(); state::apply(&mut entries, &st); @@ -518,6 +590,7 @@ pub fn build(headless: bool) -> Rc { backdrop_seq: Cell::new(0), backdrop_for: Cell::new(-1), settings: RefCell::new(prefs::load()), default_profile: RefCell::new(profile::load("default").unwrap_or_default()), theme_keys, headless, base_scale: Cell::new(1.0), fullscreen: Cell::new(false), save_timer: slint::Timer::default(), editing: RefCell::new(None), + folders: scan_folders, gen: Cell::new(0), }); APP.with(|a| *a.borrow_mut() = Some(app.clone())); @@ -544,6 +617,7 @@ pub fn build(headless: bool) -> Rc { lib.on_toggle_enhance(|i| with_app(|a| a.toggle_enhance(i))); lib.on_open_profile(|i| with_app(|a| a.open_profile(i))); lib.on_change_art(|i| with_app(|a| a.change_art(i))); + lib.on_add_game(|i| with_app(|a| a.add_game(i))); lib.on_open_clips(|| with_app(|a| a.open_clips())); lib.set_clips_dir(summit_core::engine::clips_dir().map(|d| tilde(&d)).unwrap_or_default().into()); lib.on_prof_set(|r, v| with_app(|a| a.prof_set(r, v))); diff --git a/crates/summit-gui/ui/detail.slint b/crates/summit-gui/ui/detail.slint index c01b307..2fdf6bf 100644 --- a/crates/summit-gui/ui/detail.slint +++ b/crates/summit-gui/ui/detail.slint @@ -150,7 +150,7 @@ export component DetailView inherits Rectangle { if root.g.pinned: Tag { text: "Pinned to Home"; tint: Theme.p.accent; } } HorizontalLayout { alignment: start; spacing: 12px; padding-top: 8px; - Btn { h: 56px; primary: true; enabled: root.d.can-play; text: root.d.play-label; icon: root.d.play-label == "INSTALL" ? Icons.download : Icons.play; icon-solid: root.d.play-label != "INSTALL"; + Btn { h: 56px; primary: true; enabled: root.d.can-play; text: root.d.play-label; icon: root.d.play-label == "INSTALL" ? Icons.download : root.d.play-label == "ADD" ? Icons.plus : Icons.play; icon-solid: root.d.play-label == "PLAY"; focused: root.open && root.btn == 0; clicked => { Lib.play(root.d.idx); } } Btn { h: 56px; enabled: root.d.can-enhance; text: root.compact ? "" : (root.d.enhance ? "Enhance on" : "Enhance off"); icon: Icons.sparkle; icon-solid: root.d.enhance; badge: root.d.can-enhance ? "" : "N/A"; focused: root.open && root.btn == 1; clicked => { Lib.toggle-enhance(root.d.idx); } } diff --git a/crates/summit-gui/ui/home.slint b/crates/summit-gui/ui/home.slint index 6122d40..cf73677 100644 --- a/crates/summit-gui/ui/home.slint +++ b/crates/summit-gui/ui/home.slint @@ -122,7 +122,7 @@ export component HomeView inherits Rectangle { HorizontalLayout { alignment: center; LogoMark { size: 88px; } } Text { text: "No games yet"; color: Theme.p.text; font-size: Theme.t-2xl; font-weight: 800; horizontal-alignment: center; } Text { text: "Summit looks in Steam, Heroic and Lutris. Nothing was found on this machine."; color: Theme.p.dim; font-size: Theme.t-md; horizontal-alignment: center; } - Text { text: "Add anything by hand: summit add \"My Game\" ~/Games/mygame/run.sh"; color: Theme.p.faint; font-size: Theme.t-sm; horizontal-alignment: center; } + Text { text: "Add anything by hand: Library > + Add a game (or summit add \"My Game\" ~/Games/mygame/run.sh)"; color: Theme.p.faint; font-size: Theme.t-sm; horizontal-alignment: center; } } } @@ -158,7 +158,7 @@ export component HomeView inherits Rectangle { } HorizontalLayout { alignment: start; spacing: 12px; padding-top: 4px; - Btn { h: Theme.big ? 56px : 48px; primary: true; enabled: root.g.action != ""; text: root.g.action == "" ? "PLAY" : root.g.action; icon: root.g.action == "INSTALL" ? Icons.download : Icons.play; icon-solid: root.g.action != "INSTALL"; + Btn { h: Theme.big ? 56px : 48px; primary: true; enabled: root.g.action != ""; text: root.g.action == "" ? "PLAY" : root.g.action; icon: root.g.action == "INSTALL" ? Icons.download : root.g.action == "ADD" ? Icons.plus : Icons.play; icon-solid: root.g.action == "" || root.g.action == "PLAY"; focused: root.active && root.srow == -1 && root.btn == 0; clicked => { root.hero-action(0); } } Btn { h: Theme.big ? 56px : 48px; text: "Details"; icon: Icons.info; focused: root.active && root.srow == -1 && root.btn == 1; clicked => { root.hero-action(1); } } Btn { h: Theme.big ? 56px : 48px; text: root.g.pinned ? "Pinned" : "Pin"; icon: Icons.pin; icon-solid: root.g.pinned; focused: root.active && root.srow == -1 && root.btn == 2; clicked => { root.hero-action(2); } } diff --git a/crates/summit-gui/ui/library.slint b/crates/summit-gui/ui/library.slint index b1a0867..228db62 100644 --- a/crates/summit-gui/ui/library.slint +++ b/crates/summit-gui/ui/library.slint @@ -67,7 +67,7 @@ component EmptyState inherits Rectangle { export component LibraryView inherits Rectangle { in property active; in-out property zone: 1; // 0 toolbar, 1 items - in-out property tool: 0; // 0..2 filter chips, 3 sort chip, 4 search + in-out property tool: 0; // 0..2 filter chips, 3 sort chip, 4 add a game, 5 search in-out property sel: 0; out property typing: search.typing; callback exit-up(); @@ -84,7 +84,7 @@ export component LibraryView inherits Rectangle { property top-pad: root.list ? 0px : 12px; property <[string]> sorts: ["Recently played", "Most played", "A to Z"]; - public function focus-search() { root.zone = 0; root.tool = 4; search.grab(); } + public function focus-search() { root.zone = 0; root.tool = 5; search.grab(); } function reveal() { if (root.zone != 1) { return; } if (root.list) { list-view.show(root.sel); } else { grid-view.show(Math.floor(root.sel / root.cols)); } @@ -92,13 +92,15 @@ export component LibraryView inherits Rectangle { function activate(t: int) { if (t <= 2) { Lib.filter = t; Lib.query(); } else if (t == 3) { Lib.sort = Math.mod(Lib.sort + 1, 3); Lib.query(); } + else if (t == 4) { Lib.add-game(-1); } else { search.grab(); } } changed n => { if (root.sel > Math.max(0, root.n - 1)) { root.sel = 0; } if (root.n == 0) { root.zone = 0; } } public function key(e: KeyEvent) -> bool { + if (root.n == 0) { root.zone = 0; } // nothing to focus below: an empty library starts empty, so `changed n` never ran if (root.zone == 0) { if (e.text == Key.LeftArrow) { root.tool = Math.max(0, root.tool - 1); } - else if (e.text == Key.RightArrow) { root.tool = Math.min(4, root.tool + 1); } + else if (e.text == Key.RightArrow) { root.tool = Math.min(5, root.tool + 1); } else if (e.text == Key.DownArrow) { if (root.n > 0) { root.zone = 1; root.reveal(); } } else if (e.text == Key.UpArrow) { root.exit-up(); } else if (e.text == Key.Return || e.text == " ") { root.activate(root.tool); } @@ -135,7 +137,7 @@ export component LibraryView inherits Rectangle { Text { x: Theme.pad + 104px; y: 30px; text: root.n == Lib.total-games ? root.n + " games" : root.n + " of " + Lib.total-games + " games"; color: Theme.p.dim; font-size: Theme.t-sm; } search := SearchBox { x: root.width - Theme.pad - self.width; y: 16px; width: Math.min(320px, root.width - 2 * Theme.pad - 260px); - focused: root.active && root.zone == 0 && root.tool == 4; + focused: root.active && root.zone == 0 && root.tool == 5; done => { root.refocus(); if (root.n > 0) { root.zone = 1; root.sel = 0; root.reveal(); } } } HorizontalLayout { @@ -145,11 +147,13 @@ export component LibraryView inherits Rectangle { Chip { text: "Not installed"; active: Lib.filter == 2; focused: root.active && root.zone == 0 && root.tool == 2; clicked => { root.activate(2); } } Rectangle { width: 16px; Rectangle { x: 8px; y: 7px; width: 1px; height: 20px; background: Theme.p.border; } } Chip { text: "Sort: " + root.sorts[Lib.sort]; focused: root.active && root.zone == 0 && root.tool == 3; clicked => { root.activate(3); } } + Rectangle { width: 16px; Rectangle { x: 8px; y: 7px; width: 1px; height: 20px; background: Theme.p.border; } } + Chip { text: "+ Add a game"; focused: root.active && root.zone == 0 && root.tool == 4; clicked => { root.activate(4); } } } if root.n == 0: EmptyState { y: root.head-h; height: root.height - root.head-h; title: Lib.total-games == 0 ? "No games yet" : "Nothing matches"; - hint: Lib.total-games == 0 ? "Summit found no games on this machine. Add one with: summit add \"My Game\" /path/to/game" : "Try another filter, or clear the search."; } + hint: Lib.total-games == 0 ? "Summit found no games on this machine. Add one with + Add a game above (it asks for the file that starts it)." : "Try another filter, or clear the search."; } // ---- cover grid: one ListView row per grid row, so only the rows on screen exist ---- grid-view := ListView { diff --git a/crates/summit-gui/ui/widgets.slint b/crates/summit-gui/ui/widgets.slint index cc01b2c..77941df 100644 --- a/crates/summit-gui/ui/widgets.slint +++ b/crates/summit-gui/ui/widgets.slint @@ -16,7 +16,7 @@ export struct Game { c1: color, // fallback gradient, from the title c2: color, reasons: string, // detection reasons on one line - action: string, // "Play", "Install", or "" when Summit cannot start it yet + action: string, // "PLAY", "INSTALL", "ADD" (found on disk), or "" when Summit cannot start it yet } export struct URow { header: bool, label: string, count: int, idx: int } @@ -90,6 +90,7 @@ export global Lib { callback prof-set(int, int); // row, option index callback toggle-enhance(int); callback change-art(int); + callback add-game(int); // -1: Add a game; an entry found on disk: add that folder's game in property clips-dir; // where saved clips go callback open-clips(); // pick a cover image with the desktop's file dialog in property hotkey-status; // the global save-clip key, for the settings page @@ -119,6 +120,7 @@ export global Icons { out property search: "M11 4a7 7 0 1 0 0 14a7 7 0 0 0 0-14z M20.5 20.5l-4.4-4.4"; out property play: "M7 4.5 L19.5 12 L7 19.5 Z"; out property pin: "M7 3.5 H17 V20.5 L12 16.5 L7 20.5 Z"; + out property plus: "M12 5 V19 M5 12 H19"; out property check: "M5 12.5 L10 17.5 L19 7"; out property download: "M12 4 V15 M7 10.5 L12 15.5 L17 10.5 M5 20 H19"; out property picture: "M4 5 H20 V19 H4 Z M4 16 L9 11 L13 15 L16 12 L20 16 M8.5 8.5 H8.51";