SmartFox: launcher, Siri Remote driver, Debian image and installer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tamas Csikel
2026-10-24 09:06:06 +02:00
commit 7976a6d40a
2 changed files with 194 additions and 0 deletions

137
sf-app/src/manifest.rs Normal file
View File

@@ -0,0 +1,137 @@
//! App manifests: one `app.toml` per folder under the apps directory.
use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use crate::settings::Settings;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum AppKind {
/// Runs in the shared Chromium web runtime.
Web,
/// Any executable: AppImage, Rust binary, script.
Exec,
/// Built into the launcher (e.g. settings screen).
Builtin,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppManifest {
pub id: String,
pub name: String,
pub kind: AppKind,
/// Short label above the title in the hero ("Saját app", "Castolás"...).
#[serde(default)]
pub category: String,
#[serde(default)]
pub description: String,
/// Web apps: start URL. May contain `${settings.<key>}` placeholders.
#[serde(default)]
pub url: Option<String>,
/// Exec apps: command line.
#[serde(default)]
pub exec: Option<Vec<String>>,
/// Built-in icon name used by the launcher.
#[serde(default)]
pub icon: String,
/// Accent color (hex), used for focus glow and buttons.
#[serde(default = "default_accent")]
pub accent: String,
/// Three colors for the animated hero backdrop: highlight, mid, deep.
#[serde(default)]
pub palette: Vec<String>,
/// Sort order on the home row.
#[serde(default)]
pub order: i32,
#[serde(default)]
pub web: WebOptions,
#[serde(default)]
pub dial: Option<DialOptions>,
/// Folder the manifest was loaded from (not serialized).
#[serde(skip)]
pub dir: PathBuf,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WebOptions {
/// Full user agent override.
#[serde(default)]
pub user_agent: Option<String>,
/// Appended to the default user agent.
#[serde(default)]
pub user_agent_suffix: Option<String>,
/// Unpacked extensions to load (paths relative to the app folder).
#[serde(default)]
pub extensions: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DialOptions {
/// DIAL application name, e.g. "YouTube".
pub name: String,
}
fn default_accent() -> String {
"#ffffff".into()
}
impl AppManifest {
/// Start URL with `${settings.key}` placeholders filled in.
pub fn resolved_url(&self, settings: &Settings) -> Option<String> {
self.url.as_ref().map(|u| settings.expand(u))
}
}
/// Loads every `*/app.toml` under `dir`, sorted by `order` then name.
pub fn load_apps(dir: &Path) -> Result<Vec<AppManifest>> {
let mut apps = Vec::new();
let entries = std::fs::read_dir(dir).with_context(|| format!("reading {}", dir.display()))?;
for entry in entries.flatten() {
let path = entry.path().join("app.toml");
if !path.is_file() {
continue;
}
match load_one(&path) {
Ok(app) => apps.push(app),
Err(e) => log::warn!("skipping {}: {e:#}", path.display()),
}
}
apps.sort_by(|a, b| a.order.cmp(&b.order).then_with(|| a.name.cmp(&b.name)));
Ok(apps)
}
fn load_one(path: &Path) -> Result<AppManifest> {
let text = std::fs::read_to_string(path)?;
let mut app: AppManifest = toml::from_str(&text)?;
app.dir = path.parent().unwrap_or(Path::new(".")).to_path_buf();
Ok(app)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_web_manifest() {
let app: AppManifest = toml::from_str(
r##"
id = "netflex"
name = "Netflex"
kind = "web"
url = "${settings.netflex_server}/"
accent = "#E50914"
palette = ["#ff3b3b", "#7a0a10", "#0c0203"]
[web]
user_agent_suffix = "SMART-TV SmartFox/0.1"
"##,
)
.unwrap();
assert_eq!(app.kind, AppKind::Web);
let mut s = Settings::default();
s.values.insert("netflex_server".into(), "http://10.0.0.5:7880".into());
assert_eq!(app.resolved_url(&s).unwrap(), "http://10.0.0.5:7880/");
}
}