From f9d5d9a8a8c448f5605d132e8e5b0287f6391051 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Mon, 28 Sep 2026 09:42:34 +0100 Subject: [PATCH] Polish authentication dialog colors and agent registration --- Cargo.lock | 1 + shell/ferese-polkit-agent/Cargo.toml | 1 + shell/ferese-polkit-agent/src/main.rs | 32 ++++++++++------ shell/ferese-polkit-agent/src/prompt.rs | 51 ++++++++++++------------- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c77d7d..0c02cff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1726,6 +1726,7 @@ name = "ferese-polkit-agent" version = "0.1.0" dependencies = [ "ferese-config", + "ferese-theme", "glib", "libc", "libcosmic", diff --git a/shell/ferese-polkit-agent/Cargo.toml b/shell/ferese-polkit-agent/Cargo.toml index 0b11284..139d72d 100644 --- a/shell/ferese-polkit-agent/Cargo.toml +++ b/shell/ferese-polkit-agent/Cargo.toml @@ -7,6 +7,7 @@ rust-version = "1.95" [dependencies] ferese-config = { path = "../../crates/ferese-config" } +ferese-theme = { path = "../../crates/ferese-theme" } glib = "0.21.5" libc.workspace = true libcosmic = { workspace = true, features = ["wgpu"] } diff --git a/shell/ferese-polkit-agent/src/main.rs b/shell/ferese-polkit-agent/src/main.rs index 09158fa..5b3d113 100644 --- a/shell/ferese-polkit-agent/src/main.rs +++ b/shell/ferese-polkit-agent/src/main.rs @@ -14,6 +14,7 @@ use zbus::zvariant::{OwnedValue, Value}; const AGENT_PATH: &str = "/dev/ferese/PolkitAgent"; const AUTHORITY: &str = "org.freedesktop.PolicyKit1"; const AUTHORITY_PATH: &str = "/org/freedesktop/PolicyKit1/Authority"; +const AUTHORITY_INTERFACE: &str = "org.freedesktop.PolicyKit1.Authority"; #[derive(Debug, Serialize, Deserialize)] #[serde(tag = "type", rename_all = "snake_case")] @@ -102,17 +103,25 @@ fn choose_identity(identities: &[Identity]) -> Option { } fn session_subject() -> Result<(String, HashMap>), String> { - let id = std::env::var("XDG_SESSION_ID") - .map_err(|_| "XDG_SESSION_ID is required for polkit registration".to_owned())?; - - if id.is_empty() { - return Err("XDG_SESSION_ID is empty".into()); - } - + let stat = std::fs::read_to_string("/proc/self/stat").map_err(|error| error.to_string())?; + let suffix = stat + .rsplit_once(") ") + .map(|(_, suffix)| suffix) + .ok_or("Invalid /proc/self/stat")?; + let started = suffix + .split_whitespace() + .nth(19) + .ok_or("Missing process start time")? + .parse::() + .map_err(|error| error.to_string())?; let mut details = HashMap::new(); - details.insert("session-id".to_owned(), Value::from(id)); - - Ok(("unix-session".into(), details)) + details.insert("pid".to_owned(), Value::from(std::process::id())); + details.insert( + "uid".to_owned(), + Value::from(unsafe { libc::geteuid() } as i32), + ); + details.insert("start-time".to_owned(), Value::from(started)); + Ok(("unix-process".into(), details)) } async fn run_agent() -> Result<(), Box> { @@ -121,7 +130,8 @@ async fn run_agent() -> Result<(), Box> { .serve_at(AGENT_PATH, Agent::default())? .build() .await?; - let authority = zbus::Proxy::new(&connection, AUTHORITY, AUTHORITY_PATH, AUTHORITY).await?; + let authority = + zbus::Proxy::new(&connection, AUTHORITY, AUTHORITY_PATH, AUTHORITY_INTERFACE).await?; let locale = std::env::var("LANG").unwrap_or_default(); authority diff --git a/shell/ferese-polkit-agent/src/prompt.rs b/shell/ferese-polkit-agent/src/prompt.rs index 363200e..20f3c8e 100644 --- a/shell/ferese-polkit-agent/src/prompt.rs +++ b/shell/ferese-polkit-agent/src/prompt.rs @@ -17,7 +17,6 @@ use zeroize::{Zeroize, Zeroizing}; #[derive(Clone)] struct Appearance { surface: Color, - translucent: bool, text: Color, muted: Color, accent: Color, @@ -48,12 +47,12 @@ impl Appearance { .and_then(|value| value.as_f64()) .unwrap_or(ferese_config::DEFAULT_MATERIAL_OPACITY) .clamp(0., 1.) as f32; + let mut surface = color("theme.colors.surface_base", "#111821"); surface.a = if translucent { shell_opacity } else { 1. }; Self { surface, - translucent, text: color("theme.colors.text_primary", "#F4F7FB"), muted: color("theme.colors.text_muted", "#8793A2"), accent: color("theme.colors.accent", "#3D7BE6"), @@ -74,6 +73,10 @@ impl Appearance { use cosmic::cosmic_theme::{ThemeBuilder, palette::Srgba}; let rgba = |color: Color| Srgba::new(color.r, color.g, color.b, color.a); + let opaque_surface = Color { + a: 1., + ..self.surface + }; let builder = if self.surface.r + self.surface.g + self.surface.b > 1.5 { ThemeBuilder::light() } else { @@ -87,18 +90,15 @@ impl Appearance { corners.radius_l = [self.radius; 4]; corners.radius_xl = [self.radius; 4]; - cosmic::Theme::custom(Arc::new( - builder - .corner_radii(corners) - .bg_color(rgba(Color { - a: if self.translucent { 0. } else { 1. }, - ..self.surface - })) - .primary_container_bg(rgba(self.surface)) - .text_tint(rgba(self.text).color) - .accent(rgba(self.accent).color) - .build(), - )) + let mut native = builder + .corner_radii(corners) + .bg_color(rgba(opaque_surface)) + .primary_container_bg(rgba(opaque_surface)) + .text_tint(rgba(self.text).color) + .accent(ferese_theme::accent_color(self.accent, opaque_surface)) + .build(); + ferese_theme::apply(&mut native, self.text); + cosmic::Theme::custom(Arc::new(native)) } } @@ -272,11 +272,21 @@ impl cosmic::Application for Prompt { &mut self.core } + fn style(&self) -> Option { + Some(cosmic::iced::theme::Style { + background_color: self.appearance.surface, + text_color: self.appearance.text, + icon_color: self.appearance.text, + }) + } + fn init( mut core: Core, (incoming, description, user, appearance): Self::Flags, ) -> (Self, Task) { core.window.show_headerbar = false; + core.window.border_padding = Some(0); + core.window.content_container = false; let height = content_height(&description, None); let bounds = core .main_window_id() @@ -375,7 +385,7 @@ impl cosmic::Application for Prompt { }); } let action = button::custom(text("Authenticate").font(palette.font).size(13)) - .class(theme::Button::Suggested) + .class(ferese_theme::accent_button()) .height(Length::Fixed(36.)) .padding([8, 16]) .on_press_maybe((!self.waiting && !self.answer.is_empty()).then_some(Message::Submit)); @@ -460,17 +470,6 @@ impl cosmic::Application for Prompt { .padding(20) .width(Length::Fill) .height(Length::Fill) - .class(theme::Container::custom(move |_| { - widget::container::Style { - background: Some(Background::Color(palette.surface)), - text_color: Some(palette.text), - border: Border { - radius: palette.radius.into(), - ..Default::default() - }, - ..Default::default() - } - })) .into() } }