Add Store support and unsigned app releases
This commit is contained in:
78
crates/sf-ipc/src/paths.rs
Normal file
78
crates/sf-ipc/src/paths.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
//! Where the Fennec OS sockets and files live.
|
||||
|
||||
use std::path::{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") {
|
||||
return p.into();
|
||||
}
|
||||
let base = std::env::var_os("XDG_CONFIG_HOME")
|
||||
.map(PathBuf::from)
|
||||
.or_else(|| std::env::var_os("APPDATA").map(PathBuf::from))
|
||||
.or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".config")))
|
||||
.unwrap_or_else(|| PathBuf::from("."));
|
||||
base.join("smartfox").join("settings.toml")
|
||||
}
|
||||
|
||||
/// An app's private data folder; its `$HOME` inside the sandbox:
|
||||
/// `$XDG_DATA_HOME/smartfox/apps/<id>` (default `~/.local/share/...`).
|
||||
pub fn app_data_dir(id: &str) -> PathBuf {
|
||||
let base = std::env::var_os("XDG_DATA_HOME")
|
||||
.map(PathBuf::from)
|
||||
.or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".local").join("share")))
|
||||
.or_else(|| std::env::var_os("LOCALAPPDATA").map(PathBuf::from))
|
||||
.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