//! App manifests: the Fennec SDK's `sf_app::manifest`, plus what only the OS //! decides: which factory apps became store apps, and how a TV moves over. use std::path::{Path, PathBuf}; use anyhow::Result; pub use sf_app::manifest::*; /// The Fennec catalog: the store source with the Bluefox apps. pub const FENNEC_CATALOG: &str = "https://gitea.bluefox.support/fennec/store"; /// A factory app that became a store app (its own repo, Fennec catalog). pub struct Retired { /// The old official id (`apps/`, `sf-app-`). pub id: &'static str, /// The store app that replaces it. pub replacement: &'static str, /// Its repo (canonical https URL, as in store.toml). pub source: &'static str, /// What it asks for; the old app had the same, so it is approved. pub permissions: &'static [Permission], /// The old app's data folder (logins, Chromium profile) moves over. pub move_data: bool, } pub const RETIRED: &[Retired] = &[ Retired { // The Netflex web app; the native app keeps its own login. id: "netflex", replacement: "support.bluefox.netflex", source: "https://gitea.bluefox.support/fennec/netflex", permissions: &[Permission::Network, Permission::Gpu, Permission::Audio], move_data: false, }, Retired { id: "youtube", replacement: "support.bluefox.youtube", source: "https://gitea.bluefox.support/fennec/youtube", permissions: &[Permission::Network, Permission::Gpu, Permission::Audio, Permission::Dial], move_data: true, }, Retired { id: "steam", replacement: "support.bluefox.steam", source: "https://gitea.bluefox.support/fennec/steam", permissions: &[Permission::Network, Permission::Gpu, Permission::Audio, Permission::Gamepad, Permission::DbusSession], move_data: true, }, ]; pub fn retired(id: &str) -> Option<&'static Retired> { RETIRED.iter().find(|r| r.id == id) } pub fn is_retired(id: &str) -> bool { retired(id).is_some() } /// `sf_app::manifest::load_all`, where a retired official app (the old /// factory copy in an older image, or its `sf-app-` package) stays only /// until its store replacement is installed: the TV never loses the app. pub fn load_all(dirs: &[PathBuf], store: Option<&Path>) -> Result> { let apps = sf_app::manifest::load_all(dirs, store)?; let replaced = |id: &str| retired(id).is_some_and(|r| apps.iter().any(|a| a.origin == Origin::Store && a.id == r.replacement)); let keep: Vec = apps.iter().map(|a| a.origin == Origin::Store || !replaced(&a.id)).collect(); Ok(apps.into_iter().zip(keep).filter_map(|(a, k)| k.then_some(a)).collect()) } /// Moves the data folder of a retired app to its replacement, once the /// replacement is installed and has no data yet (runs as the TV user). pub fn migrate_data(apps: &[AppManifest]) { for r in RETIRED.iter().filter(|r| r.move_data) { if !apps.iter().any(|a| a.origin == Origin::Store && a.id == r.replacement) { continue; } let (old, new) = (sf_app::paths::app_data_dir(r.id), sf_app::paths::app_data_dir(r.replacement)); if old.is_dir() && std::fs::symlink_metadata(&new).is_err() { match std::fs::rename(&old, &new) { Ok(()) => log::info!("moved the data of {} to {}", r.id, r.replacement), Err(e) => log::warn!("moving {} to {}: {e}", old.display(), new.display()), } } } } #[cfg(test)] mod tests { use super::*; fn write(dir: &Path, id: &str, body: &str) { std::fs::create_dir_all(dir.join(id)).unwrap(); std::fs::write(dir.join(id).join("app.toml"), format!("id = \"{id}\"\nname = \"{id}\"\n{body}")).unwrap(); } #[test] fn retired_app_stays_until_replaced() { let base = std::env::temp_dir().join(format!("sf-ipc-retired-{}", std::process::id())); let (factory, store) = (base.join("factory"), base.join("store")); write(&factory, "youtube", "kind = \"web\"\nurl = \"https://www.youtube.com/tv\"\n"); write(&factory, "settings", "kind = \"builtin\"\n"); let ids = |apps: Vec| apps.into_iter().map(|a| a.id).collect::>(); assert_eq!(ids(load_all(&[factory.clone()], Some(&store)).unwrap()), ["settings", "youtube"]); write(&store, "support.bluefox.youtube", "kind = \"web\"\nurl = \"https://www.youtube.com/tv\"\n"); let mut got = ids(load_all(&[factory.clone()], Some(&store)).unwrap()); got.sort(); assert_eq!(got, ["settings", "support.bluefox.youtube"]); std::fs::remove_dir_all(&base).unwrap(); } }