commit 34d61801db7a3e9e50c2603b9ef86114e9699ca2
parent 64112aa7fea60507f2934484e9b840d1e65d4766
Author: Divan Visagie <me@divanv.com>
Date: Sat, 28 Nov 2026 00:38:46 +0100
greeter: the first-run setup becomes steps, and the first new one asks for the time zone (ADR-0019)
What the user will see: a machine fresh from the install now opens on "Choose your time zone, so the
clock is right." A search box and a list of the zones (the one the machine is on is highlighted and
in view); typing narrows the list, and any words of the name will do, so "stock" finds
Europe/Stockholm and "new york" finds America/New_York. Continue sets it; Skip leaves it alone;
Enter is Continue. Then the account form, as before, now marked "Step 2 of 2" with a Back link.
Why: a machine installed from the ISO came up on UTC, an hour out for the owner in Stockholm, and
there was nowhere during the install to say where you are.
How:
- A Step enum (Clock, Account) with next/previous, and Screen::Setup stays one screen that draws
the current step. The existing account form is moved into draw_account unchanged.
- The Backend trait gets timezones(), timezone() and set_timezone(): the real one asks timedated
over D-Bus (ListTimezones, the Timezone property, SetTimezone); the mock knows a dozen zones.
- The account stays the last step on purpose: the polkit rule that lets the greeter manage accounts
only holds until the first account can log in, so everything else is changed before it (the
rule for the zone is in the previous commit).
- The zone list rows are drawn by hand (zone_row): egui's selectable button drew the chosen zone's
text but no highlight once its frame was off, so the zone in use was invisible. Found from the
screenshots, not the tests.
Tests: 28 pass (7 new): the search finds by any words, with case and spaces for underscores;
continuing sets the zone and goes to the account; an unchanged zone asks nothing of the system; a zone
the system refuses is shown and the step stays; Skip and Back change nothing; typing in the search
does not reach the account fields. The four account-form tests now start on the account step.
Clippy and fmt are clean. Not tried on the real machine yet.
Diffstat:
5 files changed, 465 insertions(+), 26 deletions(-)
diff --git a/docs/adr/0019-the-first-run-setup-is-several-steps.md b/docs/adr/0019-the-first-run-setup-is-several-steps.md
@@ -67,6 +67,14 @@ The layout that localed writes has to reach two compositors, and today neither w
3. Wi-Fi.
4. Later: the keyboard layout, with the two compositors' side.
+## Done so far
+
+- **The framework and the Clock step** (2026-11-28): the setup is a list of steps with Skip and Back
+ and "Step n of m", the account last; the Clock step searches timedated's zone list (by any words of the
+ name, so `stock` finds Europe/Stockholm), starts on the zone the machine is on, and sets the zone
+ when Continue is pressed (nothing is asked of the system if it is unchanged). Its polkit rule is in
+ the rules file. Seen in the greeter's mock; not yet on the real machine.
+
## Open questions
- Whether the clock should offer a guess when there is a network by then (Wi-Fi comes first).
diff --git a/greeter/src/app.rs b/greeter/src/app.rs
@@ -31,6 +31,47 @@ pub enum Screen {
Setup,
}
+/// The first-run setup's steps, in order (ADR-0019). The account is last: the polkit rule that lets
+/// the greeter manage accounts only holds until the first one can log in, so whatever else the
+/// setup changes on the system is changed in the steps before it.
+#[derive(Clone, Copy, PartialEq, Debug)]
+pub enum Step {
+ Clock,
+ Account,
+}
+
+impl Step {
+ const ALL: [Step; 2] = [Step::Clock, Step::Account];
+
+ fn index(self) -> usize {
+ Self::ALL.iter().position(|s| *s == self).unwrap_or(0)
+ }
+
+ fn next(self) -> Option<Step> {
+ Self::ALL.get(self.index() + 1).copied()
+ }
+
+ fn previous(self) -> Option<Step> {
+ self.index().checked_sub(1).map(|i| Self::ALL[i])
+ }
+}
+
+/// The zones whose name has every word of `query` in it, in the order given. `stock` finds
+/// `Europe/Stockholm`; `new york` finds `America/New_York`; nothing typed finds them all.
+fn zones_matching<'a>(zones: &'a [String], query: &str) -> Vec<&'a String> {
+ let words: Vec<String> = query
+ .split_whitespace()
+ .map(|w| w.replace('_', " ").to_lowercase())
+ .collect();
+ zones
+ .iter()
+ .filter(|zone| {
+ let name = zone.replace('_', " ").to_lowercase();
+ words.iter().all(|w| name.contains(w.as_str()))
+ })
+ .collect()
+}
+
#[derive(Clone, PartialEq, Debug)]
pub enum Status {
Typing,
@@ -59,6 +100,7 @@ const SLOTS: [Slot; 4] = [
enum Done {
Login(Result<(), LoginError>),
Created(Result<(), String>),
+ Zone(Result<(), String>),
}
struct Screenshot {
@@ -84,6 +126,13 @@ pub struct App {
rx: Receiver<Done>,
/// The new account's user name, between making it and logging it in.
new_user: Option<String>,
+ step: Step,
+ /// The clock step: every zone, the one chosen, what is typed to search, and whether the list
+ /// has been scrolled to the chosen one yet.
+ zones: Vec<String>,
+ zone: String,
+ zone_filter: String,
+ zone_scrolled: bool,
screenshot: Option<Screenshot>,
finished: bool,
}
@@ -117,6 +166,11 @@ impl App {
tx,
rx,
new_user: None,
+ step: Step::Clock,
+ zones: Vec::new(),
+ zone: String::new(),
+ zone_filter: String::new(),
+ zone_scrolled: false,
screenshot: None,
finished: false,
};
@@ -129,6 +183,10 @@ impl App {
self.users = self.backend.users();
self.selected = self.selected.min(self.users.len().saturating_sub(1));
self.screen = if self.backend.first_run() {
+ if self.zones.is_empty() {
+ self.zones = self.backend.timezones();
+ self.zone = self.backend.timezone();
+ }
Screen::Setup
} else {
Screen::Login
@@ -155,7 +213,12 @@ impl App {
self.login.text.clear();
self.status = Status::Wrong;
}
+ (Screen::Setup, "clock") => {
+ self.zone_filter = "stock".into();
+ self.zone = "Europe/Stockholm".into();
+ }
(Screen::Setup, "filled") => {
+ self.step = Step::Account;
self.fields[0].text = "Alice Example".into();
self.fields[1].text = "alice".into();
self.fields[2].text = "correct horse".into();
@@ -164,6 +227,7 @@ impl App {
self.focus = Slot::Confirm;
}
(Screen::Setup, "problem") => {
+ self.step = Step::Account;
self.fields[0].text = "Alice Example".into();
self.fields[1].text = "alice".into();
self.fields[2].text = "correct horse".into();
@@ -219,6 +283,37 @@ impl App {
}
}
+ /// Sets the zone chosen and goes on; with nothing changed there is nothing to ask the system.
+ fn submit_clock(&mut self) {
+ if self.status == Status::Checking || self.zone.is_empty() {
+ return;
+ }
+ if self.zone == self.backend.timezone() {
+ return self.go_on();
+ }
+ self.status = Status::Checking;
+ let zone = self.zone.clone();
+ self.spawn(move |backend| Done::Zone(backend.set_timezone(&zone)));
+ }
+
+ /// To the next step, with nothing left over from this one.
+ fn go_on(&mut self) {
+ self.status = Status::Typing;
+ if let Some(next) = self.step.next() {
+ self.step = next;
+ }
+ }
+
+ fn go_back(&mut self) {
+ if self.status == Status::Checking {
+ return;
+ }
+ self.status = Status::Typing;
+ if let Some(previous) = self.step.previous() {
+ self.step = previous;
+ }
+ }
+
fn submit_setup(&mut self) {
if self.status == Status::Checking {
return;
@@ -263,6 +358,8 @@ impl App {
self.new_user = None;
self.status = Status::Problem(e);
}
+ Done::Zone(Ok(())) => self.go_on(),
+ Done::Zone(Err(e)) => self.status = Status::Problem(e),
}
}
}
@@ -307,6 +404,19 @@ impl App {
}
fn setup_event(&mut self, event: &egui::Event) {
+ if self.step != Step::Account {
+ // The other steps are drawn with egui's own widgets, which take what is typed;
+ // Enter is Continue.
+ if let egui::Event::Key {
+ key: egui::Key::Enter,
+ pressed: true,
+ ..
+ } = event
+ {
+ self.submit_clock();
+ }
+ return;
+ }
if let egui::Event::Key {
key,
pressed: true,
@@ -477,7 +587,6 @@ impl App {
fn draw_setup(&mut self, ui: &mut Ui) {
let rect = ui.max_rect();
- let checking = self.status == Status::Checking;
ui.vertical_centered(|ui| {
ui.add_space(rect.height() * 0.14);
ui.label(
@@ -486,33 +595,154 @@ impl App {
.strong(),
);
ui.add_space(4.0);
+ let subtitle = match self.step {
+ Step::Clock => "Choose your time zone, so the clock is right.",
+ Step::Account => "Let's set up this computer.",
+ };
ui.label(
- RichText::new("Let's set up this computer.")
+ RichText::new(subtitle)
.size(18.0)
.color(ui.visuals().weak_text_color()),
);
ui.add_space(28.0);
- for (i, slot) in SLOTS.iter().enumerate() {
- let tone = if checking { Tone::Busy } else { Tone::Normal };
- if self.fields[i]
- .show(ui, field::SIZE, self.focus == *slot && !checking, tone, 0.0)
- .clicked()
- && !checking
- {
- self.focus = *slot;
- }
- ui.add_space(10.0);
+ match self.step {
+ Step::Clock => self.draw_clock(ui),
+ Step::Account => self.draw_account(ui),
}
- ui.add_space(4.0);
- let problem = self.form().problem();
- let ready = problem.is_none() && !checking;
- let create = wide_button(ui, "Create account", ready, checking);
- if create.clicked() && ready {
- self.submit_setup();
+ ui.add_space(12.0);
+ self.draw_steps(ui);
+ });
+ }
+
+ /// The last step: the first account (ADR-0012).
+ fn draw_account(&mut self, ui: &mut Ui) {
+ let checking = self.status == Status::Checking;
+ for (i, slot) in SLOTS.iter().enumerate() {
+ let tone = if checking { Tone::Busy } else { Tone::Normal };
+ if self.fields[i]
+ .show(ui, field::SIZE, self.focus == *slot && !checking, tone, 0.0)
+ .clicked()
+ && !checking
+ {
+ self.focus = *slot;
}
ui.add_space(10.0);
- self.status_line(ui, problem.unwrap_or(""));
- });
+ }
+ ui.add_space(4.0);
+ let problem = self.form().problem();
+ let ready = problem.is_none() && !checking;
+ let create = wide_button(ui, "Create account", ready, checking);
+ if create.clicked() && ready {
+ self.submit_setup();
+ }
+ ui.add_space(10.0);
+ self.status_line(ui, problem.unwrap_or(""));
+ }
+
+ /// The time zone (ADR-0019): a search over the zones, the list, and Continue.
+ fn draw_clock(&mut self, ui: &mut Ui) {
+ let checking = self.status == Status::Checking;
+ let search = ui.add_enabled(
+ !checking,
+ egui::TextEdit::singleline(&mut self.zone_filter)
+ .hint_text("Search for a city or region")
+ .desired_width(field::SIZE.x)
+ .margin(egui::Margin::symmetric(14, 10)),
+ );
+ if !self.zone_scrolled {
+ search.request_focus();
+ }
+ ui.add_space(8.0);
+ let shown: Vec<String> = zones_matching(&self.zones, &self.zone_filter)
+ .into_iter()
+ .cloned()
+ .collect();
+ // A block as wide as the field, so it sits in the middle like the rest.
+ ui.allocate_ui_with_layout(
+ vec2(field::SIZE.x, 240.0),
+ egui::Layout::top_down(egui::Align::Min),
+ |ui| {
+ egui::ScrollArea::vertical()
+ .max_height(240.0)
+ .auto_shrink([false, false])
+ .show(ui, |ui| {
+ if shown.is_empty() {
+ ui.label(
+ RichText::new("No time zone matches that")
+ .color(ui.visuals().weak_text_color()),
+ );
+ }
+ for zone in &shown {
+ let chosen = *zone == self.zone;
+ let row = zone_row(ui, &zone.replace('_', " "), chosen);
+ if row.clicked() && !checking {
+ self.zone = zone.clone();
+ self.status = Status::Typing;
+ }
+ // Once, on the unfiltered list: put the zone in use in view.
+ if chosen && !self.zone_scrolled && self.zone_filter.is_empty() {
+ row.scroll_to_me_animation(
+ Some(egui::Align::Center),
+ egui::style::ScrollAnimation::none(),
+ );
+ }
+ }
+ });
+ },
+ );
+ self.zone_scrolled = true;
+ ui.add_space(14.0);
+ let ready = !self.zone.is_empty() && !checking;
+ if wide_button(ui, "Continue", ready, checking).clicked() && ready {
+ self.submit_clock();
+ }
+ ui.add_space(10.0);
+ let hint = if self.zone.is_empty() {
+ String::new()
+ } else {
+ format!("Time zone: {}", self.zone.replace('_', " "))
+ };
+ self.status_line(ui, &hint);
+ }
+
+ /// Under every step: where this one is among them, Back, and Skip (the account cannot be
+ /// skipped: it is what the setup is for).
+ fn draw_steps(&mut self, ui: &mut Ui) {
+ let weak = ui.visuals().weak_text_color();
+ ui.label(
+ RichText::new(format!(
+ "Step {} of {}",
+ self.step.index() + 1,
+ Step::ALL.len()
+ ))
+ .color(weak),
+ );
+ ui.add_space(6.0);
+ let (mut back, mut skip) = (false, false);
+ ui.allocate_ui_with_layout(
+ vec2(field::SIZE.x, 28.0),
+ egui::Layout::left_to_right(egui::Align::Center),
+ |ui| {
+ if self.step.previous().is_some()
+ && ui.add(egui::Button::new("Back").frame(false)).clicked()
+ {
+ back = true;
+ }
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ if self.step != Step::Account
+ && ui.add(egui::Button::new("Skip").frame(false)).clicked()
+ {
+ skip = true;
+ }
+ });
+ },
+ );
+ if back {
+ self.go_back();
+ }
+ if skip && self.status != Status::Checking {
+ self.go_on();
+ }
}
/// The line under the form: what is happening, what went wrong, or what to do next.
@@ -635,6 +865,39 @@ fn avatar(ui: &mut Ui, name: &str, side: f32, chosen: bool) -> egui::Response {
response
}
+/// One time zone in the list: the chosen one on the accent, the one under the pointer lightly.
+fn zone_row(ui: &mut Ui, text: &str, chosen: bool) -> egui::Response {
+ let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 30.0), Sense::click());
+ let v = ui.visuals().clone();
+ if response.hovered() {
+ ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);
+ }
+ let fill = if chosen {
+ Some(v.selection.bg_fill)
+ } else if response.hovered() {
+ Some(v.widgets.hovered.weak_bg_fill)
+ } else {
+ None
+ };
+ let painter = ui.painter();
+ if let Some(fill) = fill {
+ painter.rect_filled(rect, egui::CornerRadius::same(8), fill);
+ }
+ let ink = if chosen {
+ v.selection.stroke.color
+ } else {
+ v.text_color()
+ };
+ painter.text(
+ rect.center(),
+ Align2::CENTER_CENTER,
+ text,
+ FontId::proportional(15.0),
+ ink,
+ );
+ response
+}
+
/// The setup's button, as big as the fields above it: a pill in the accent, as the login's arrow
/// sits in its pill. It breaks Patina's button size on purpose (the user's choice, ADR-0013):
/// those are 24 px high, for rows in dialogs, and beside 46 px fields they look lost. Restart
@@ -732,6 +995,13 @@ mod tests {
app(Mock::new(users, Duration::ZERO))
}
+ /// A fresh machine, on the setup's last step: the account form.
+ fn at_account() -> App {
+ let mut a = quick(&[]);
+ a.step = Step::Account;
+ a
+ }
+
fn typed(text: &str) -> egui::Event {
egui::Event::Text(text.into())
}
@@ -815,7 +1085,7 @@ mod tests {
#[test]
fn the_setup_suggests_a_user_name_until_one_is_typed() {
- let mut a = quick(&[]);
+ let mut a = at_account();
a.handle_keys(&[typed("Alice Example")]);
assert_eq!(a.fields[1].text, "alice");
a.handle_keys(&[key(egui::Key::Tab, false), typed("x")]);
@@ -832,7 +1102,7 @@ mod tests {
#[test]
fn tab_and_enter_walk_the_fields_and_wrap() {
- let mut a = quick(&[]);
+ let mut a = at_account();
assert_eq!(a.focus, Slot::FullName);
a.handle_keys(&[key(egui::Key::Tab, false)]);
assert_eq!(a.focus, Slot::Username);
@@ -848,7 +1118,7 @@ mod tests {
#[test]
fn the_setup_will_not_submit_a_form_with_a_problem() {
- let mut a = quick(&[]);
+ let mut a = at_account();
a.handle_keys(&[
typed("Alice Example"),
key(egui::Key::Tab, false),
@@ -871,7 +1141,7 @@ mod tests {
#[test]
fn the_first_run_makes_the_account_and_logs_it_in() {
- let mut a = quick(&[]);
+ let mut a = at_account();
a.handle_keys(&[typed("Alice Example")]);
a.handle_keys(&[
key(egui::Key::Tab, false),
@@ -903,12 +1173,101 @@ mod tests {
}
#[test]
+ fn a_fresh_machine_starts_on_the_clock_with_the_zone_it_is_on() {
+ let a = quick(&[]);
+ assert_eq!((a.screen, a.step), (Screen::Setup, Step::Clock));
+ assert_eq!(
+ a.zone, "UTC",
+ "what the machine is on is chosen to begin with"
+ );
+ assert!(a.zones.iter().any(|z| z == "Europe/Stockholm"));
+ }
+
+ #[test]
+ fn searching_the_zones_finds_a_city_by_any_words_of_it() {
+ let a = quick(&[]);
+ let find =
+ |q: &str| -> Vec<String> { zones_matching(&a.zones, q).into_iter().cloned().collect() };
+ assert_eq!(find("stock"), ["Europe/Stockholm"]);
+ assert_eq!(
+ find("NEW york"),
+ ["America/New_York"],
+ "case and spaces for underscores"
+ );
+ assert_eq!(find("europe").len(), 3);
+ assert_eq!(
+ find("").len(),
+ a.zones.len(),
+ "nothing typed shows them all"
+ );
+ assert!(find("atlantis").is_empty());
+ }
+
+ #[test]
+ fn continuing_sets_the_zone_and_goes_to_the_account() {
+ let mut a = quick(&[]);
+ a.zone = "Europe/Stockholm".into();
+ a.handle_keys(&[key(egui::Key::Enter, false)]);
+ assert_eq!(a.status, Status::Checking);
+ settle(&mut a);
+ assert_eq!(a.step, Step::Account);
+ assert_eq!(a.status, Status::Typing);
+ assert_eq!(
+ a.backend.timezone(),
+ "Europe/Stockholm",
+ "the machine's zone changed"
+ );
+ }
+
+ #[test]
+ fn continuing_with_the_zone_unchanged_asks_nothing_of_the_system() {
+ let mut a = quick(&[]);
+ a.submit_clock();
+ assert_eq!(a.status, Status::Typing, "no worker was started");
+ assert_eq!(a.step, Step::Account);
+ }
+
+ #[test]
+ fn a_zone_the_system_refuses_is_shown_and_the_step_stays() {
+ let mut a = quick(&[]);
+ a.zone = "Mars/Olympus_Mons".into();
+ a.submit_clock();
+ settle(&mut a);
+ assert_eq!(a.step, Step::Clock);
+ assert!(matches!(&a.status, Status::Problem(e) if e.contains("Mars/Olympus_Mons")));
+ assert_eq!(a.backend.timezone(), "UTC");
+ }
+
+ #[test]
+ fn skip_and_back_walk_the_steps_without_changing_anything() {
+ let mut a = quick(&[]);
+ a.go_on();
+ assert_eq!(a.step, Step::Account);
+ assert_eq!(a.backend.timezone(), "UTC");
+ a.go_back();
+ assert_eq!(a.step, Step::Clock);
+ a.go_back();
+ assert_eq!(
+ a.step,
+ Step::Clock,
+ "there is nothing before the first step"
+ );
+ }
+
+ #[test]
+ fn typing_in_the_search_does_not_reach_the_account_fields() {
+ let mut a = quick(&[]);
+ a.handle_keys(&[typed("sto")]);
+ assert!(a.fields.iter().all(|f| f.text.is_empty()));
+ }
+
+ #[test]
fn both_screens_draw_without_trouble() {
for users in [&[("alice", "Alice Example"), ("bob", "Bob")][..], &[][..]] {
let mut a = quick(users);
let ctx = a.ctx.clone();
egui_extras::install_image_loaders(&ctx);
- for what in ["", "typing", "wrong", "problem", "filled"] {
+ for what in ["", "typing", "wrong", "problem", "filled", "clock"] {
a.demo(what);
let _ = ctx.run_ui(egui::RawInput::default(), |ui| a.draw(ui));
}
diff --git a/greeter/src/backend.rs b/greeter/src/backend.rs
@@ -43,6 +43,12 @@ pub trait Backend: Send + Sync {
password: &str,
) -> Result<(), String>;
fn power(&self, action: Power) -> Result<(), String>;
+ /// The time zones there are, as `Europe/Stockholm`, in order (ADR-0019, the setup's clock).
+ fn timezones(&self) -> Vec<String>;
+ /// The one this machine is on now.
+ fn timezone(&self) -> String;
+ /// Sets it, through timedated, which polkit lets the greeter do only on the first run.
+ fn set_timezone(&self, zone: &str) -> Result<(), String>;
}
/// A backend with accounts in memory, for the screens and the tests. The password that works is
@@ -50,8 +56,25 @@ pub trait Backend: Send + Sync {
pub struct Mock {
users: Mutex<Vec<User>>,
delay: Duration,
+ zone: Mutex<String>,
}
+/// The zones the mock knows, as a few of the real ones.
+pub const MOCK_ZONES: &[&str] = &[
+ "Africa/Cairo",
+ "America/Los_Angeles",
+ "America/New_York",
+ "America/Sao_Paulo",
+ "Asia/Kolkata",
+ "Asia/Tokyo",
+ "Australia/Sydney",
+ "Europe/Berlin",
+ "Europe/London",
+ "Europe/Stockholm",
+ "Pacific/Auckland",
+ "UTC",
+];
+
pub const MOCK_PASSWORD: &str = "sectorf";
/// A password that makes the mock fail the way a login service that is down does.
pub const MOCK_BROKEN: &str = "broken";
@@ -69,6 +92,7 @@ impl Mock {
.collect(),
),
delay,
+ zone: Mutex::new("UTC".into()),
}
}
@@ -129,6 +153,23 @@ impl Backend for Mock {
fn power(&self, _action: Power) -> Result<(), String> {
Ok(())
}
+
+ fn timezones(&self) -> Vec<String> {
+ MOCK_ZONES.iter().map(|z| (*z).to_string()).collect()
+ }
+
+ fn timezone(&self) -> String {
+ self.zone.lock().unwrap().clone()
+ }
+
+ fn set_timezone(&self, zone: &str) -> Result<(), String> {
+ std::thread::sleep(self.delay);
+ if !MOCK_ZONES.contains(&zone) {
+ return Err(format!("could not set the time zone: unknown zone {zone}"));
+ }
+ *self.zone.lock().unwrap() = zone.into();
+ Ok(())
+ }
}
#[cfg(test)]
diff --git a/greeter/src/main.rs b/greeter/src/main.rs
@@ -20,7 +20,7 @@ For trying the screens without greetd, on a mock whose password is `sectorf`:
PATINA_GREETER_MOCK=login a machine with accounts (alice and bob)
PATINA_GREETER_MOCK=setup a machine fresh from the install, with none
PATINA_GREETER_SIZE=1280x800 a window of that size, not full screen
- PATINA_GREETER_DEMO=... fills a screen in: login: typing, wrong, problem; setup: filled, problem
+ PATINA_GREETER_DEMO=... fills a screen in: login: typing, wrong, problem; setup: clock, filled, problem
PATINA_GREETER_SCREENSHOT=file.png saves the screen to a file and quits
PATINA_SKIN=name another skin";
diff --git a/greeter/src/system.rs b/greeter/src/system.rs
@@ -12,6 +12,8 @@ use crate::backend::{Backend, LoginError, Power, User};
const ACCOUNTS: &str = "org.freedesktop.Accounts";
const ACCOUNTS_PATH: &str = "/org/freedesktop/Accounts";
const LOGIND: &str = "org.freedesktop.login1";
+const TIMEDATE: &str = "org.freedesktop.timedate1";
+const TIMEDATE_PATH: &str = "/org/freedesktop/timedate1";
/// The first human uid, as in /etc/login.defs.
const FIRST_UID: u32 = 1000;
@@ -213,6 +215,35 @@ impl Backend for System {
.call::<_, _, ()>(method, &(false,))
.map_err(|e| e.to_string())
}
+
+ /// timedated's own list, so it is the zones this system has.
+ fn timezones(&self) -> Vec<String> {
+ let list = || -> Result<Vec<String>, String> {
+ let bus = Self::bus()?;
+ Self::proxy(&bus, TIMEDATE, TIMEDATE_PATH, TIMEDATE)?
+ .call::<_, _, Vec<String>>("ListTimezones", &())
+ .map_err(|e| e.to_string())
+ };
+ list().unwrap_or_default()
+ }
+
+ fn timezone(&self) -> String {
+ let get = || -> Result<String, String> {
+ let bus = Self::bus()?;
+ Self::proxy(&bus, TIMEDATE, TIMEDATE_PATH, TIMEDATE)?
+ .get_property::<String>("Timezone")
+ .map_err(|e| e.to_string())
+ };
+ get().unwrap_or_default()
+ }
+
+ fn set_timezone(&self, zone: &str) -> Result<(), String> {
+ let bus = Self::bus()?;
+ // The second argument is whether polkit may ask for a password: no one is there to give it.
+ Self::proxy(&bus, TIMEDATE, TIMEDATE_PATH, TIMEDATE)?
+ .call::<_, _, ()>("SetTimezone", &(zone, false))
+ .map_err(|e| format!("could not set the time zone: {e}"))
+ }
}
#[cfg(test)]