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>
This commit is contained in:
Tamas Csikel
2026-10-25 17:58:21 +01:00
parent d7e9fe4568
commit deedf1416a
67 changed files with 393 additions and 13476 deletions

View File

@@ -16,6 +16,7 @@
mod appstore;
mod config;
mod forge;
mod migrate;
mod registry;
mod store;
@@ -65,6 +66,9 @@ fn run(cmd: &str) -> Result<()> {
/// installed, with where to get them. None if store.toml can't be read
/// (then nothing is installed or removed).
fn store_plan(cfg: &Config, store: &Store) -> Option<(sf_ipc::store::Wanted, BTreeMap<String, (String, appstore::StoreDownload)>)> {
if let Err(e) = migrate::adopt_retired(&cfg.store_wanted, store) {
log::warn!("store: adding the replacements of the old factory apps: {e:#}");
}
let wanted = match appstore::read_wanted(&cfg.store_wanted) {
Ok(w) => w,
Err(e) => {

View File

@@ -0,0 +1,99 @@
//! Official apps that became store apps (`sf_ipc::manifest::RETIRED`): on a
//! TV that has the old app, its store replacement is added to store.toml
//! once, with the permissions the old app already had, and the Fennec
//! catalog as a source. The launcher keeps showing the old app until the
//! replacement is installed, so nothing disappears in between.
//!
//! Done ids are remembered in `<root>/store/retired-adopted`: an app the user
//! uninstalls later is not added again.
use std::collections::BTreeSet;
use std::fs;
use std::io::Write;
use std::path::Path;
use anyhow::{Context, Result};
use sf_ipc::manifest::{FENNEC_CATALOG, RETIRED};
use sf_ipc::store::{Wanted, WantedApp};
use crate::appstore;
use crate::store::Store;
const DONE_FILE: &str = "retired-adopted";
pub fn adopt_retired(wanted_path: &Path, store: &Store) -> Result<()> {
let done_path = store.store_dir().join(DONE_FILE);
let mut done: BTreeSet<String> = fs::read_to_string(&done_path).unwrap_or_default().lines().map(str::to_string).collect();
let todo: Vec<_> = RETIRED.iter().filter(|r| !done.contains(r.id)).collect();
if todo.is_empty() {
return Ok(());
}
let mut wanted = appstore::read_wanted(wanted_path)?;
let changed = plan(&mut wanted, &todo, |id| store.installed(&format!("sf-app-{id}")).is_some());
if changed {
write_wanted(wanted_path, &wanted)?;
log::info!("store.toml: added the store apps that replace the old factory apps");
}
done.extend(todo.iter().map(|r| r.id.to_string()));
fs::create_dir_all(store.store_dir())?;
fs::write(&done_path, done.into_iter().map(|id| id + "\n").collect::<String>())?;
Ok(())
}
/// Adds the replacements of the retired apps the TV has. True if `wanted`
/// changed.
fn plan(wanted: &mut Wanted, todo: &[&sf_ipc::manifest::Retired], has_old: impl Fn(&str) -> bool) -> bool {
let mut changed = false;
for r in todo.iter().filter(|r| has_old(r.id)) {
if !wanted.apps.contains_key(r.replacement) {
wanted.apps.insert(r.replacement.to_string(), WantedApp { source: r.source.to_string(), permissions: r.permissions.to_vec() });
changed = true;
}
if !wanted.sources.iter().any(|s| appstore::canonical(s) == FENNEC_CATALOG) {
wanted.sources.push(FENNEC_CATALOG.to_string());
changed = true;
}
}
changed
}
/// Root writes into the TV user's folder: a new file (never through an
/// existing name, which the user could have made a symlink), renamed over
/// store.toml, owned like its folder.
fn write_wanted(path: &Path, wanted: &Wanted) -> Result<()> {
let dir = path.parent().context("store.toml has no folder")?;
let tmp = dir.join(format!(".store.toml.sf-update-{}", std::process::id()));
let _ = fs::remove_file(&tmp);
let mut f = fs::OpenOptions::new().write(true).create_new(true).open(&tmp).with_context(|| format!("creating {}", tmp.display()))?;
f.write_all(toml::to_string_pretty(wanted)?.as_bytes())?;
f.sync_all()?;
drop(f);
#[cfg(unix)]
{
use std::os::unix::fs::{MetadataExt, PermissionsExt};
let meta = fs::metadata(dir)?;
std::os::unix::fs::chown(&tmp, Some(meta.uid()), Some(meta.gid()))?;
fs::set_permissions(&tmp, fs::Permissions::from_mode(0o644))?;
}
fs::rename(&tmp, path).with_context(|| format!("writing {}", path.display()))?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn adds_replacements_of_old_apps_only() {
let todo: Vec<_> = RETIRED.iter().collect();
let mut w = Wanted::default();
assert!(plan(&mut w, &todo, |id| id == "youtube"));
assert_eq!(w.sources, [FENNEC_CATALOG]);
assert_eq!(w.apps.keys().collect::<Vec<_>>(), ["support.bluefox.youtube"]);
assert!(w.apps["support.bluefox.youtube"].permissions.contains(&sf_ipc::Permission::Dial));
// A new TV: store.toml has it all already.
assert!(!plan(&mut w, &todo, |id| id == "youtube"));
// No old apps: nothing to do.
assert!(!plan(&mut Wanted::default(), &todo, |_| false));
}
}

View File

@@ -18,9 +18,14 @@ pub const MAX_PACKAGE: u64 = 1024 * 1024 * 1024;
use crate::config::Config;
/// Official package names (from our registry).
/// Official package names (from our registry). Apps that became store apps
/// (`sf_ipc::manifest::RETIRED`) are no longer official packages: old
/// versions in the registry are not installed.
pub fn is_official(name: &str) -> bool {
name == "sf-shell" || name.strip_prefix("sf-app-").is_some_and(|id| !id.is_empty() && id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_'))
name == "sf-shell"
|| name.strip_prefix("sf-app-").is_some_and(|id| {
!id.is_empty() && id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_') && !sf_ipc::manifest::is_retired(id)
})
}
/// Store app id of a package name (`store-<id>`).
@@ -131,7 +136,8 @@ mod tests {
#[test]
fn names_and_versions() {
assert!(is_ours("sf-shell"));
assert!(is_ours("sf-app-youtube"));
assert!(is_ours("sf-app-airplay"));
assert!(!is_ours("sf-app-youtube"));
assert!(!is_ours("sf-app-"));
assert!(!is_ours("sf-app-../x"));
assert!(!is_ours("other"));