feat(os): port Ghostty's Linux OS helpers
Ports ZIG/src/os for Linux into ghostty-os: XDG dirs, home dir, hostname, env/PATH helpers, passwd lookup (via nix), shell detection, resources dir discovery, string encodings (printf-q, URL percent), systemd sd_notify, i18n via gettextrs, xdg-open, desktop/cgroup/kernel info, temp dirs, URI parsing (port of std.Uri incl. Ghostty's extra options), and a zbus-based Flatpak HostCommand implementation. The crate stays free of unsafe. Consequences, all tracked as TODO(integration) in docs/rewrite/notes/ghostty-os.md: - locale::ensure_locale is a no-op (setlocale/setenv are unsafe; GTK calls setlocale itself); setenv/unsetenv are not exposed. - passwd's Flatpak branch needs the termio pty and falls back to the sandbox entry for now. - FlatpakHostCommand's D-Bus path is untested (no portal here). Intentional fix: a leading '@' in NOTIFY_SOCKET is treated as an abstract socket. macOS/Windows/WASM modules are out of scope. Test Plan: - cargo test -p ghostty-os (88 tests) - cargo clippy -p ghostty-os --all-targets -- -D warnings
This commit is contained in:
1 parent
04a6b7c97a
commit
b681241359
30 files changed
+3736
-1
No files matched your search
@@ -0,0 +1,36 @@
|
||||
/// Returns true if the program was launched by D-Bus activation.
|
||||
///
|
||||
/// On Linux GTK, this returns true if the program was launched using D-Bus
|
||||
/// activation. It will return false if Ghostty was launched any other way.
|
||||
pub fn launched_by_dbus_activation() -> bool {
|
||||
// On Linux, D-Bus activation sets `DBUS_STARTER_ADDRESS` and
|
||||
// `DBUS_STARTER_BUS_TYPE`. If these environment variables are present
|
||||
// (no matter the value) we were launched by D-Bus activation.
|
||||
std::env::var_os("DBUS_STARTER_ADDRESS").is_some()
|
||||
&& std::env::var_os("DBUS_STARTER_BUS_TYPE").is_some()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::testutil::with_env_lock;
|
||||
|
||||
#[test]
|
||||
fn dbus_activation_env() {
|
||||
temp_env::with_vars(
|
||||
[
|
||||
("DBUS_STARTER_ADDRESS", Some("x")),
|
||||
("DBUS_STARTER_BUS_TYPE", Some("session")),
|
||||
],
|
||||
|| assert!(launched_by_dbus_activation()),
|
||||
);
|
||||
temp_env::with_vars(
|
||||
[
|
||||
("DBUS_STARTER_ADDRESS", Some("x")),
|
||||
("DBUS_STARTER_BUS_TYPE", None),
|
||||
],
|
||||
|| assert!(!launched_by_dbus_activation()),
|
||||
);
|
||||
with_env_lock(|| {});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user