chore: cargo fmt & geoclue docs
This commit is contained in:
parent
c83767c7e5
commit
8b9767f6ce
7 changed files with 199 additions and 191 deletions
|
|
@ -9,48 +9,48 @@ const CHOICES: &[&str] = &["no", "yes"];
|
|||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> zbus::Result<()> {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
let proxy = timedate_zbus::TimeDateProxy::new(&connection).await?;
|
||||
let connection = zbus::Connection::system().await?;
|
||||
let proxy = timedate_zbus::TimeDateProxy::new(&connection).await?;
|
||||
|
||||
let ntp_service = if proxy.ntp().await? {
|
||||
"active"
|
||||
} else {
|
||||
"inactive"
|
||||
};
|
||||
let ntp_service = if proxy.ntp().await? {
|
||||
"active"
|
||||
} else {
|
||||
"inactive"
|
||||
};
|
||||
|
||||
let rtc_in_local = proxy.local_rtc().await?;
|
||||
let rtc_time_usecs = proxy.rtctime_usec().await?;
|
||||
let time_usecs = proxy.time_usec().await?;
|
||||
let timezone = proxy.timezone().await?;
|
||||
let rtc_in_local = proxy.local_rtc().await?;
|
||||
let rtc_time_usecs = proxy.rtctime_usec().await?;
|
||||
let time_usecs = proxy.time_usec().await?;
|
||||
let timezone = proxy.timezone().await?;
|
||||
|
||||
let tz: chrono_tz::Tz = timezone.parse().unwrap();
|
||||
let tz: chrono_tz::Tz = timezone.parse().unwrap();
|
||||
|
||||
let datetime = tz.timestamp_millis_opt((time_usecs / 1000) as i64).unwrap();
|
||||
let datetime = tz.timestamp_millis_opt((time_usecs / 1000) as i64).unwrap();
|
||||
|
||||
let rtc_millis = (rtc_time_usecs / 1000) as i64;
|
||||
let rtc_time = (if rtc_in_local {
|
||||
tz.timestamp_millis_opt(rtc_millis).unwrap()
|
||||
} else {
|
||||
chrono_tz::UTC.timestamp_millis_opt(rtc_millis).unwrap()
|
||||
})
|
||||
.format(RTC_FORMAT);
|
||||
let rtc_millis = (rtc_time_usecs / 1000) as i64;
|
||||
let rtc_time = (if rtc_in_local {
|
||||
tz.timestamp_millis_opt(rtc_millis).unwrap()
|
||||
} else {
|
||||
chrono_tz::UTC.timestamp_millis_opt(rtc_millis).unwrap()
|
||||
})
|
||||
.format(RTC_FORMAT);
|
||||
|
||||
let local = datetime.format(TZ_FORMAT);
|
||||
let universal = datetime.with_timezone(&chrono_tz::UTC).format(TZ_FORMAT);
|
||||
let tz_string = datetime.format("%Z, %z");
|
||||
let local = datetime.format(TZ_FORMAT);
|
||||
let universal = datetime.with_timezone(&chrono_tz::UTC).format(TZ_FORMAT);
|
||||
let tz_string = datetime.format("%Z, %z");
|
||||
|
||||
let rtc_in_local = CHOICES[usize::from(rtc_in_local)];
|
||||
let synchronized = CHOICES[usize::from(proxy.ntp_synchronized().await.unwrap_or_default())];
|
||||
let rtc_in_local = CHOICES[usize::from(rtc_in_local)];
|
||||
let synchronized = CHOICES[usize::from(proxy.ntp_synchronized().await.unwrap_or_default())];
|
||||
|
||||
println!(
|
||||
" Local time: {local}
|
||||
println!(
|
||||
" Local time: {local}
|
||||
Universal time: {universal}
|
||||
RTC time: {rtc_time}
|
||||
Time zone: {timezone} ({tz_string})
|
||||
System clock synchronized: {synchronized}
|
||||
NTP Service: {ntp_service}
|
||||
RTC in local TZ: {rtc_in_local}"
|
||||
);
|
||||
);
|
||||
|
||||
Ok(())
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,58 +18,58 @@
|
|||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.freedesktop.timedate1",
|
||||
default_service = "org.freedesktop.timedate1",
|
||||
default_path = "/org/freedesktop/timedate1"
|
||||
interface = "org.freedesktop.timedate1",
|
||||
default_service = "org.freedesktop.timedate1",
|
||||
default_path = "/org/freedesktop/timedate1"
|
||||
)]
|
||||
trait TimeDate {
|
||||
/// A list of time zones known on the local system as an array of names.
|
||||
fn list_timezones(&self) -> zbus::Result<Vec<String>>;
|
||||
/// A list of time zones known on the local system as an array of names.
|
||||
fn list_timezones(&self) -> zbus::Result<Vec<String>>;
|
||||
|
||||
/// Control whether the RTC is in local time zone or UTC.
|
||||
#[dbus_proxy(name = "SetLocalRTC")]
|
||||
fn set_local_rtc(
|
||||
&self,
|
||||
local_rtc: bool,
|
||||
fix_system: bool,
|
||||
interactive: bool,
|
||||
) -> zbus::Result<()>;
|
||||
/// Control whether the RTC is in local time zone or UTC.
|
||||
#[dbus_proxy(name = "SetLocalRTC")]
|
||||
fn set_local_rtc(
|
||||
&self,
|
||||
local_rtc: bool,
|
||||
fix_system: bool,
|
||||
interactive: bool,
|
||||
) -> zbus::Result<()>;
|
||||
|
||||
/// Control whether the system clock is synchronized with the network using `systemd-timesyncd`.
|
||||
#[dbus_proxy(name = "SetNTP")]
|
||||
fn set_ntp(&self, use_ntp: bool, interactive: bool) -> zbus::Result<()>;
|
||||
/// Control whether the system clock is synchronized with the network using `systemd-timesyncd`.
|
||||
#[dbus_proxy(name = "SetNTP")]
|
||||
fn set_ntp(&self, use_ntp: bool, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Change the system clock.
|
||||
fn set_time(&self, usec_utc: i64, relative: bool, interactive: bool) -> zbus::Result<()>;
|
||||
/// Change the system clock.
|
||||
fn set_time(&self, usec_utc: i64, relative: bool, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Set the system time zone.
|
||||
fn set_timezone(&self, timezone: &str, interactive: bool) -> zbus::Result<()>;
|
||||
/// Set the system time zone.
|
||||
fn set_timezone(&self, timezone: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Shows whether a service to perform time synchronization over network is available.
|
||||
#[dbus_proxy(property, name = "CanNTP")]
|
||||
fn can_ntp(&self) -> zbus::Result<bool>;
|
||||
/// Shows whether a service to perform time synchronization over network is available.
|
||||
#[dbus_proxy(property, name = "CanNTP")]
|
||||
fn can_ntp(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Shows whether the RTC is configured to use UTC or the local time zone.
|
||||
#[dbus_proxy(property, name = "LocalRTC")]
|
||||
fn local_rtc(&self) -> zbus::Result<bool>;
|
||||
/// Shows whether the RTC is configured to use UTC or the local time zone.
|
||||
#[dbus_proxy(property, name = "LocalRTC")]
|
||||
fn local_rtc(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Shows whether the NTP service is enabled.
|
||||
#[dbus_proxy(property, name = "NTP")]
|
||||
fn ntp(&self) -> zbus::Result<bool>;
|
||||
/// Shows whether the NTP service is enabled.
|
||||
#[dbus_proxy(property, name = "NTP")]
|
||||
fn ntp(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Shows whether the kernel reports the time as synchronized.
|
||||
#[dbus_proxy(property, name = "NTPSynchronized")]
|
||||
fn ntp_synchronized(&self) -> zbus::Result<bool>;
|
||||
/// Shows whether the kernel reports the time as synchronized.
|
||||
#[dbus_proxy(property, name = "NTPSynchronized")]
|
||||
fn ntp_synchronized(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Shows the current time in RTC.
|
||||
#[dbus_proxy(property, name = "RTCTimeUSec")]
|
||||
fn rtctime_usec(&self) -> zbus::Result<u64>;
|
||||
/// Shows the current time in RTC.
|
||||
#[dbus_proxy(property, name = "RTCTimeUSec")]
|
||||
fn rtctime_usec(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// Shows the current time.
|
||||
#[dbus_proxy(property, name = "TimeUSec")]
|
||||
fn time_usec(&self) -> zbus::Result<u64>;
|
||||
/// Shows the current time.
|
||||
#[dbus_proxy(property, name = "TimeUSec")]
|
||||
fn time_usec(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// Shows the currently-configured time zone.
|
||||
#[dbus_proxy(property)]
|
||||
fn timezone(&self) -> zbus::Result<String>;
|
||||
/// Shows the currently-configured time zone.
|
||||
#[dbus_proxy(property)]
|
||||
fn timezone(&self) -> zbus::Result<String>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue