Files
os/crates/sf-ipc/src/manifest.rs
Tamas Csikel deedf1416a Split the apps and the SDK out of Fennec OS
The apps are developed apart from the OS now, each in its own repo under
gitea.bluefox.support/fennec:
- sdk: sf-app (the app contract: manifest, permissions, store rules,
  sandbox, launch; from sf-ipc), sf-ui, sf-pack, the app template, the
  developer guide. The OS depends on it by tag (v0.1.0).
- youtube, steam: store apps. netflex (native) replaces the Netflex web app.
- store: the Fennec catalog, the store source a new TV starts with.

This repo keeps the OS and its own apps (Settings, App Store, AirPlay,
Miracast). sf-ipc re-exports sf-app, so OS code is mostly unchanged.

- Store apps may register for DIAL (the `dial` permission); an official
  app with the same DIAL name wins.
- Built-in icon names are for official apps only.
- The image installs the catalog apps at build time (factory-store.toml,
  sf-update store in mkosi.postinst.chroot). Steam's system part stays in
  the image: 32-bit libraries, controller udev rules (from Valve's apt
  repo), Valve's key.
- Older TVs move over by themselves: sf-update adds the replacements to
  store.toml once, the old factory app stays until its replacement is
  installed, YouTube's and Steam's data folders move to the new ids, and
  the old sf-app-<id> packages are not installed any more.

Shell 0.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 17:58:21 +01:00

111 lines
4.6 KiB
Rust

//! 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/<id>`, `sf-app-<id>`).
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-<id>` 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<Vec<AppManifest>> {
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<bool> = 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<AppManifest>| apps.into_iter().map(|a| a.id).collect::<Vec<_>>();
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();
}
}