Fennec SDK: split from the Fennec OS repository
All checks were successful
ci / test (push) Successful in 17m21s
All checks were successful
ci / test (push) Successful in 17m21s
The app-facing parts of Fennec OS move here, so apps build without the OS sources: - sf-app: the app contract (manifest, permissions, store rules, sandbox, launch), from sf-ipc; the OS depends on it by tag. - sf-ui (+ gallery), sf-pack, templates/rust-app, docs. Store apps may now register for DIAL: a [dial] section implies the new `dial` permission, which the user approves like any other. The templates no longer mention signing: store releases are unsigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
14
sf-app/src/lib.rs
Normal file
14
sf-app/src/lib.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
//! The Fennec OS app contract, shared by the OS (launcher, sf-core,
|
||||
//! sf-update) and the developer tools (sf-pack):
|
||||
//! - `manifest`: what an app is (`app.toml`), its permissions, the store rules;
|
||||
//! - `launch` and `sandbox`: how the TV starts it, and what it can reach;
|
||||
//! - `paths`, `settings`: where its data lives, `${settings.<key>}` values.
|
||||
|
||||
pub mod launch;
|
||||
pub mod manifest;
|
||||
pub mod paths;
|
||||
pub mod sandbox;
|
||||
pub mod settings;
|
||||
|
||||
pub use manifest::{AppKind, AppManifest, Origin, Permission, load_apps};
|
||||
pub use settings::Settings;
|
||||
@@ -55,10 +55,13 @@ pub enum Permission {
|
||||
DbusSystem,
|
||||
/// Every device in /dev.
|
||||
Devices,
|
||||
/// Phones may start the app by casting to the TV (DIAL, e.g. the YouTube
|
||||
/// app's cast button). Implied by a `[dial]` section.
|
||||
Dial,
|
||||
}
|
||||
|
||||
impl Permission {
|
||||
pub const ALL: [Permission; 7] = [
|
||||
pub const ALL: [Permission; 8] = [
|
||||
Permission::Network,
|
||||
Permission::Gpu,
|
||||
Permission::Audio,
|
||||
@@ -66,6 +69,7 @@ impl Permission {
|
||||
Permission::DbusSession,
|
||||
Permission::DbusSystem,
|
||||
Permission::Devices,
|
||||
Permission::Dial,
|
||||
];
|
||||
|
||||
/// Name used in app.toml and store.toml.
|
||||
@@ -78,6 +82,7 @@ impl Permission {
|
||||
Permission::DbusSession => "dbus-session",
|
||||
Permission::DbusSystem => "dbus-system",
|
||||
Permission::Devices => "devices",
|
||||
Permission::Dial => "dial",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +100,7 @@ impl Permission {
|
||||
Permission::DbusSession => "Munkamenet D-Bus",
|
||||
Permission::DbusSystem => "Rendszer D-Bus",
|
||||
Permission::Devices => "Minden eszköz (/dev)",
|
||||
Permission::Dial => "Castolás telefonról (DIAL)",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,12 +239,15 @@ impl AppManifest {
|
||||
}
|
||||
|
||||
/// What the app may reach from its sandbox. Web apps always get what a
|
||||
/// browser needs.
|
||||
/// browser needs; a `[dial]` section asks for `dial`.
|
||||
pub fn permissions(&self) -> Vec<Permission> {
|
||||
let mut p = self.sandbox.permissions.clone();
|
||||
if self.kind == AppKind::Web {
|
||||
p.extend([Permission::Network, Permission::Gpu, Permission::Audio]);
|
||||
}
|
||||
if self.dial.is_some() {
|
||||
p.push(Permission::Dial);
|
||||
}
|
||||
p.sort();
|
||||
p.dedup();
|
||||
p
|
||||
@@ -269,7 +278,9 @@ impl AppManifest {
|
||||
anyhow::ensure!(is_store_id(&self.id), "store app id {:?} must be a reverse domain name (io.github.user.app)", self.id);
|
||||
anyhow::ensure!(self.kind != AppKind::Builtin, "store apps can't be built-in");
|
||||
anyhow::ensure!(!self.service, "store apps can't be background services");
|
||||
anyhow::ensure!(self.dial.is_none(), "store apps can't register for DIAL");
|
||||
if let Some(d) = &self.dial {
|
||||
anyhow::ensure!(!d.name.trim().is_empty() && d.name.len() <= 64, "dial.name must be 1-64 characters");
|
||||
}
|
||||
anyhow::ensure!(self.sandbox.enabled != Some(false), "store apps can't turn off the sandbox");
|
||||
match self.kind {
|
||||
AppKind::Exec => anyhow::ensure!(!self.resolved_exec(Path::new("/app")).is_empty(), "exec is missing"),
|
||||
@@ -451,6 +462,20 @@ mod tests {
|
||||
bad.id = "youtube".into();
|
||||
assert!(bad.check_store_rules().is_err());
|
||||
|
||||
// DIAL: allowed for store apps, and it shows up as a permission.
|
||||
let cast: AppManifest = toml::from_str(
|
||||
"id = 'io.github.fox.tube'
|
||||
name = 'Tube'
|
||||
kind = 'web'
|
||||
url = 'https://example.com/tv'
|
||||
[dial]
|
||||
name = 'YouTube'
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
cast.check_store_rules().unwrap();
|
||||
assert!(cast.permissions().contains(&Permission::Dial));
|
||||
|
||||
let web: AppManifest = toml::from_str("id = 'a'\nname = 'A'\nkind = 'web'\nurl = 'https://x'\n").unwrap();
|
||||
assert_eq!(web.permissions(), [Permission::Network, Permission::Gpu, Permission::Audio]);
|
||||
let path: AppManifest = toml::from_str("id = 'a'\nname = 'A'\nkind = 'exec'\nexec = ['uxplay', '-n']\n").unwrap();
|
||||
|
||||
@@ -1,34 +1,12 @@
|
||||
//! Where the Fennec OS sockets and files live.
|
||||
//! Where an app's files live on the TV (and on a developer machine).
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// `$XDG_RUNTIME_DIR`, or the temp dir.
|
||||
pub fn runtime_dir() -> PathBuf {
|
||||
std::env::var_os("XDG_RUNTIME_DIR").map(PathBuf::from).unwrap_or_else(std::env::temp_dir)
|
||||
}
|
||||
|
||||
fn from_env(var: &str, default: &str) -> PathBuf {
|
||||
match std::env::var_os(var) {
|
||||
Some(p) => p.into(),
|
||||
None => runtime_dir().join(default),
|
||||
}
|
||||
}
|
||||
|
||||
/// Launcher command socket (`home`, `remote <state>`, `power`, `wake`).
|
||||
pub fn launcher_socket() -> PathBuf {
|
||||
from_env("SMARTFOX_SOCKET", "smartfox.sock")
|
||||
}
|
||||
|
||||
/// sf-core: app lifecycle (JSON lines, see `message`).
|
||||
pub fn core_socket() -> PathBuf {
|
||||
from_env("SMARTFOX_CORE_SOCKET", "smartfox-core.sock")
|
||||
}
|
||||
|
||||
/// sf-compositor control socket (`focus launcher`, `focus <app-id>`).
|
||||
pub fn wm_socket() -> PathBuf {
|
||||
from_env("SMARTFOX_WM_SOCKET", "smartfox-wm.sock")
|
||||
}
|
||||
|
||||
/// The settings file: `$SMARTFOX_SETTINGS`, else `<config>/smartfox/settings.toml`.
|
||||
pub fn settings_file() -> PathBuf {
|
||||
if let Ok(p) = std::env::var("SMARTFOX_SETTINGS") {
|
||||
@@ -52,27 +30,3 @@ pub fn app_data_dir(id: &str) -> PathBuf {
|
||||
.unwrap_or_else(|| PathBuf::from("."));
|
||||
base.join("smartfox").join("apps").join(id)
|
||||
}
|
||||
|
||||
/// Installed store apps (`/var/lib/sf-pkg/store/apps/<id>`), written by sf-update.
|
||||
pub const STORE_APPS: &str = "/var/lib/sf-pkg/store/apps";
|
||||
|
||||
/// Looks for an `apps` folder next to the binary or above the cwd (dev
|
||||
/// checkout), else the installed one.
|
||||
pub fn apps_dir() -> PathBuf {
|
||||
let mut starts = vec![];
|
||||
if let Ok(cwd) = std::env::current_dir() {
|
||||
starts.push(cwd);
|
||||
}
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
starts.extend(exe.parent().map(Path::to_path_buf));
|
||||
}
|
||||
for start in starts {
|
||||
for dir in start.ancestors() {
|
||||
let candidate = dir.join("apps");
|
||||
if candidate.join("netflex").is_dir() {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
PathBuf::from("/usr/share/smartfox/apps")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user