diff --git a/Cargo.toml b/Cargo.toml index fa9ad76..a9eb064 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,18 +12,17 @@ members = [ "locale1", "mpris2", "networkmanager", - "nm-secret-agent-manager", "switcheroo-control", "timedate", "upower", ] [workspace.dependencies] -futures-channel = "0.3.32" -futures-util = "0.3.32" +futures-channel = "0.3.31" +futures-util = "0.3.31" serde = { version = "1.0", features = ["derive"] } thiserror = "2.0" -jiff = "0.2" -tracing = "0.1.44" -zbus = { version = "5.14.0" } -zvariant = { version = "5.10.0" } +time = { version = "0.3", features = ["parsing"] } +tracing = "0.1.41" +zbus = { version = "5.11.0" } +zvariant = { version = "5.7.0" } diff --git a/bluez/Cargo.toml b/bluez/Cargo.toml index a1251b8..eb497aa 100644 --- a/bluez/Cargo.toml +++ b/bluez/Cargo.toml @@ -19,4 +19,4 @@ color-eyre = "0.6.5" eyre = "0.6.12" pico-args = "0.5.0" tokio = { version = "1", features = ["full"] } -tracing-subscriber = "0.3.23" +tracing-subscriber = "0.3.20" diff --git a/mpris2/Cargo.toml b/mpris2/Cargo.toml index 947f508..807064b 100644 --- a/mpris2/Cargo.toml +++ b/mpris2/Cargo.toml @@ -9,7 +9,7 @@ license = "MPL-2.0" futures-util.workspace = true serde.workspace = true thiserror.workspace = true -jiff.workspace = true +time.workspace = true zbus.workspace = true zvariant.workspace = true diff --git a/mpris2/examples/list.rs b/mpris2/examples/list.rs index 9c9b234..778ef83 100644 --- a/mpris2/examples/list.rs +++ b/mpris2/examples/list.rs @@ -43,7 +43,7 @@ async fn main() -> Result<()> { .await .into_diagnostic() .wrap_err_with(|| format!("Failed to get position for media player '{}'", name))? - .map(|s| format!("{} seconds", s.as_secs_f32())) + .map(|s| format!("{} seconds", s.as_seconds_f32())) .unwrap_or_else(|| "N/A".to_owned()); println!("\tPosition: {}", position); if !player diff --git a/mpris2/src/metadata.rs b/mpris2/src/metadata.rs index c9ef7b8..704054b 100644 --- a/mpris2/src/metadata.rs +++ b/mpris2/src/metadata.rs @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MPL-2.0 use crate::error::{Error, Result}; -use jiff::{SignedDuration, Timestamp}; use std::{ collections::HashMap, fmt, ops::{Deref, DerefMut}, }; +use time::{Duration, OffsetDateTime}; use zbus::zvariant::{OwnedObjectPath, Value as ZValue}; #[derive(Debug, Clone, PartialEq)] @@ -90,7 +90,7 @@ impl Metadata { } /// `xesam:contentCreated`: When the track was created. Usually only the year component will be useful. - pub fn created(&self) -> Option { + pub fn created(&self) -> Option { self.inner .get("xesam:contentCreated") .cloned() @@ -106,7 +106,7 @@ impl Metadata { } /// `xesam:firstUsed`: When the track was first played. - pub fn first_played(&self) -> Option { + pub fn first_played(&self) -> Option { self.inner .get("xesam:firstUsed") .cloned() @@ -128,7 +128,7 @@ impl Metadata { } /// `xesam:lastUsed`: When the track was last played. - pub fn last_played(&self) -> Option { + pub fn last_played(&self) -> Option { self.inner .get("xesam:lastUsed") .cloned() @@ -199,7 +199,7 @@ impl Metadata { } /// `mpris:length`: The length of the track in microseconds. - pub fn length(&self) -> Option { + pub fn length(&self) -> Option { self.inner .get("mpris:length") .cloned() @@ -209,7 +209,7 @@ impl Metadata { MetadataValue::Str(s) => s.parse().ok(), _ => None, }) - .map(SignedDuration::from_micros) + .map(Duration::microseconds) } /// `mpris:artUrl`: The location of an image representing the track or album. @@ -309,13 +309,17 @@ impl MetadataValue { /// Tries to extract a date/time from the variant, /// returning an error if the variant is not a date/time. - pub fn try_into_date(self) -> Result { + pub fn try_into_date(self) -> Result { let variant = self.variant(); match self { - MetadataValue::Str(s) => s.parse::().map_err(|_| Error::IncorrectVariant { - wanted: "String (DateTime)", - actual: variant, - }), + MetadataValue::Str(s) => { + OffsetDateTime::parse(&s, &time::format_description::well_known::Rfc3339).map_err( + |_| Error::IncorrectVariant { + wanted: "String (DateTime)", + actual: variant, + }, + ) + } _ => Err(Error::IncorrectVariant { wanted: "String (DateTime)", actual: variant, @@ -325,7 +329,7 @@ impl MetadataValue { /// Tries to extract a date/time from the variant, /// panicking if the variant is not a date/time. - pub fn into_date(self) -> Timestamp { + pub fn into_date(self) -> OffsetDateTime { self.try_into_date().unwrap_or_else(|err| panic!("{}", err)) } diff --git a/mpris2/src/player.rs b/mpris2/src/player.rs index f8e5755..eff6ab1 100644 --- a/mpris2/src/player.rs +++ b/mpris2/src/player.rs @@ -7,12 +7,12 @@ use crate::{ metadata::Metadata, track::TrackId, }; -use jiff::SignedDuration; use std::{ fmt::{self, Display}, ops::Deref, str::FromStr, }; +use time::Duration; use zbus::{Connection, names::OwnedBusName}; #[derive(Debug, Clone)] @@ -41,9 +41,11 @@ impl Player { } /// Seeks the specified duration. - pub async fn seek(&self, duration: SignedDuration) -> Result { + pub async fn seek(&self, duration: Duration) -> Result { if self.proxy.can_seek().await? { - self.proxy.seek(duration.as_micros() as i64).await?; + self.proxy + .seek(duration.whole_microseconds() as i64) + .await?; Ok(true) } else { Ok(false) @@ -53,9 +55,9 @@ impl Player { /// Sets the current track position. /// /// If `track` does not match the id of the currently-playing track, the call is ignored as "stale". - pub async fn set_position(&self, track: &TrackId, position: SignedDuration) -> Result<()> { + pub async fn set_position(&self, track: &TrackId, position: Duration) -> Result<()> { self.proxy - .set_position(track, position.as_micros() as i64) + .set_position(track, position.whole_microseconds() as i64) .await .map_err(Error::from) } @@ -63,8 +65,8 @@ impl Player { /// How far into the current track the player is. /// /// Not all players support this, and it will return None if this is the case. - pub async fn position(&self) -> Result> { - handle_optional(self.proxy.position().await.map(SignedDuration::from_micros)) + pub async fn position(&self) -> Result> { + handle_optional(self.proxy.position().await.map(Duration::microseconds)) } /// Gets the current playback status of the player. diff --git a/networkmanager/Cargo.toml b/networkmanager/Cargo.toml index d7db4d6..47a6938 100644 --- a/networkmanager/Cargo.toml +++ b/networkmanager/Cargo.toml @@ -5,9 +5,9 @@ edition = "2024" license = "MPL-2.0" [dependencies] -bitflags = "2.11" +bitflags = "2.9" derive_builder = "0.20.2" procfs = { version = "0.18", default-features = false } -jiff.workspace = true +time.workspace = true zvariant.workspace = true zbus.workspace = true diff --git a/networkmanager/src/access_point.rs b/networkmanager/src/access_point.rs index 4705ce6..8fc9de3 100644 --- a/networkmanager/src/access_point.rs +++ b/networkmanager/src/access_point.rs @@ -8,13 +8,14 @@ use crate::{ util::clock_boottime_to_time, }; use std::ops::Deref; +use time::OffsetDateTime; use zbus::Result; #[derive(Debug)] pub struct AccessPoint<'a>(AccessPointProxy<'a>); impl<'a> AccessPoint<'a> { - pub async fn last_seen(&self) -> Result> { + pub async fn last_seen(&self) -> Result> { Ok(clock_boottime_to_time(self.0.last_seen().await?)) } diff --git a/networkmanager/src/util.rs b/networkmanager/src/util.rs index 230e46e..0c60fee 100644 --- a/networkmanager/src/util.rs +++ b/networkmanager/src/util.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MPL-2.0 -use jiff::Timestamp; +use time::OffsetDateTime; -pub fn clock_boottime_to_time(time: i32) -> Option { +pub fn clock_boottime_to_time(time: i32) -> Option { let boot_time = procfs::boot_time_secs() .ok() .and_then(|boot_time| i64::try_from(boot_time).ok())?; - Timestamp::from_second(boot_time + time as i64).ok() + OffsetDateTime::from_unix_timestamp(boot_time + time as i64).ok() } diff --git a/nm-secret-agent-manager/Cargo.toml b/nm-secret-agent-manager/Cargo.toml deleted file mode 100644 index 4610f81..0000000 --- a/nm-secret-agent-manager/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "nm-secret-agent-manager" -version = "0.1.0" -edition = "2024" - -[dependencies] -zbus.workspace = true diff --git a/nm-secret-agent-manager/src/lib.rs b/nm-secret-agent-manager/src/lib.rs deleted file mode 100644 index c04411a..0000000 --- a/nm-secret-agent-manager/src/lib.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! # D-Bus interface proxy for: `org.freedesktop.NetworkManager.AgentManager` -//! -//! This code was generated by `zbus-xmlgen` `5.0.0` from D-Bus introspection data. -//! Source: `test.xml`. -//! -//! You may prefer to adapt it, instead of using it verbatim. -//! -//! More information can be found in the [Writing a client proxy] section of the zbus -//! documentation. -//! -//! -//! [Writing a client proxy]: https://dbus2.github.io/zbus/client.html -//! [D-Bus standard interfaces]: https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces, -use zbus::proxy; -#[proxy( - interface = "org.freedesktop.NetworkManager.AgentManager", - default_service = "org.freedesktop.NetworkManager", - default_path = "/org/freedesktop/NetworkManager/AgentManager", - assume_defaults = true -)] -pub trait AgentManager { - /// Register method - fn register(&self, identifier: &str) -> zbus::Result<()>; - - /// RegisterWithCapabilities method - fn register_with_capabilities(&self, identifier: &str, capabilities: u32) -> zbus::Result<()>; - - /// Unregister method - fn unregister(&self) -> zbus::Result<()>; -} diff --git a/switcheroo-control/src/lib.rs b/switcheroo-control/src/lib.rs index b4fb6f8..30d5c8b 100644 --- a/switcheroo-control/src/lib.rs +++ b/switcheroo-control/src/lib.rs @@ -99,20 +99,15 @@ impl TryFrom> for Gpu { .chunks_exact(2) .map(|chunk| (chunk[0].clone(), chunk[1].clone())) .collect(); - let default: bool = value + let default = value .get("Default") .ok_or(zvariant::Error::IncorrectType)? .try_into()?; - let discrete = value - .get("Discrete") - .and_then(|v| v.try_into().ok()) - .unwrap_or(!default); Ok(Self { name, environment, default, - discrete, }) } } @@ -130,5 +125,4 @@ pub struct Gpu { pub name: String, pub environment: HashMap, pub default: bool, - pub discrete: bool, } diff --git a/timedate/Cargo.toml b/timedate/Cargo.toml index ace5289..0f07694 100644 --- a/timedate/Cargo.toml +++ b/timedate/Cargo.toml @@ -15,10 +15,11 @@ all-features = true zbus.workspace = true [dev-dependencies] -jiff.workspace = true +chrono = "0.4.42" +chrono-tz = "0.10.4" zbus.workspace = true zbus.features = ["tokio"] [dev-dependencies.tokio] -version = "1.50.0" +version = "1.47.1" features = ["full"] diff --git a/timedate/examples/timedatectl.rs b/timedate/examples/timedatectl.rs index f0a709a..cfec9a0 100644 --- a/timedate/examples/timedatectl.rs +++ b/timedate/examples/timedatectl.rs @@ -1,7 +1,7 @@ // Copyright 2023 System76 // SPDX-License-Identifier: MPL-2.0 -use jiff::{Timestamp, tz::TimeZone}; +use chrono::TimeZone; const TZ_FORMAT: &str = "%a %Y-%m-%d %H:%M:%S %Z"; const RTC_FORMAT: &str = "%a %Y-%m-%d %H:%M:%S"; @@ -23,24 +23,21 @@ pub async fn main() -> zbus::Result<()> { let time_usecs = proxy.time_usec().await?; let timezone = proxy.timezone().await?; - let tz = TimeZone::get(&timezone).unwrap(); - let utc = TimeZone::UTC; + let tz: chrono_tz::Tz = timezone.parse().unwrap(); - let datetime = Timestamp::from_microsecond(time_usecs as i64) - .unwrap() - .to_zoned(tz.clone()); + let datetime = tz.timestamp_millis_opt((time_usecs / 1000) as i64).unwrap(); - let rtc_ts = Timestamp::from_microsecond(rtc_time_usecs as i64).unwrap(); + let rtc_millis = (rtc_time_usecs / 1000) as i64; let rtc_time = (if rtc_in_local { - rtc_ts.to_zoned(tz) + tz.timestamp_millis_opt(rtc_millis).unwrap() } else { - rtc_ts.to_zoned(utc.clone()) + chrono_tz::UTC.timestamp_millis_opt(rtc_millis).unwrap() }) - .strftime(RTC_FORMAT); + .format(RTC_FORMAT); - let local = datetime.strftime(TZ_FORMAT); - let universal = datetime.with_time_zone(utc).strftime(TZ_FORMAT); - let tz_string = datetime.strftime("%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())]; diff --git a/timedate/src/lib.rs b/timedate/src/lib.rs index 00d6467..2ffc671 100644 --- a/timedate/src/lib.rs +++ b/timedate/src/lib.rs @@ -46,7 +46,7 @@ pub trait TimeDate { fn set_timezone(&self, timezone: &str, interactive: bool) -> zbus::Result<()>; /// Shows whether a service to perform time synchronization over network is available. - #[zbus(property(emits_changed_signal = "false"), name = "CanNTP")] + #[zbus(property, name = "CanNTP")] fn can_ntp(&self) -> zbus::Result; /// Shows whether the RTC is configured to use UTC or the local time zone. @@ -58,15 +58,15 @@ pub trait TimeDate { fn ntp(&self) -> zbus::Result; /// Shows whether the kernel reports the time as synchronized. - #[zbus(property(emits_changed_signal = "false"), name = "NTPSynchronized")] + #[zbus(property, name = "NTPSynchronized")] fn ntp_synchronized(&self) -> zbus::Result; /// Shows the current time in RTC. - #[zbus(property(emits_changed_signal = "false"), name = "RTCTimeUSec")] + #[zbus(property, name = "RTCTimeUSec")] fn rtctime_usec(&self) -> zbus::Result; /// Shows the current time. - #[zbus(property(emits_changed_signal = "false"), name = "TimeUSec")] + #[zbus(property, name = "TimeUSec")] fn time_usec(&self) -> zbus::Result; /// Shows the currently-configured time zone. diff --git a/upower/Cargo.toml b/upower/Cargo.toml index dcce64e..62cb211 100644 --- a/upower/Cargo.toml +++ b/upower/Cargo.toml @@ -16,4 +16,4 @@ serde_repr = "0.1.20" zbus.workspace = true [dev-dependencies] -futures = "0.3.32" +futures = "0.3.31" diff --git a/upower/src/device.rs b/upower/src/device.rs index fb5010f..b889e2e 100644 --- a/upower/src/device.rs +++ b/upower/src/device.rs @@ -132,7 +132,7 @@ pub trait Device { #[zbus(property)] fn is_rechargeable(&self) -> zbus::Result; - #[deprecated(since = "0.3.2", note = "deprecated since 0.99.12")] + #[deprecated(since="0.3.2", note="deprecated since 0.99.12")] #[zbus(property)] fn luminosity(&self) -> zbus::Result; @@ -183,21 +183,16 @@ pub trait Device { #[zbus(property)] fn voltage_min_design(&self) -> zbus::Result; - #[zbus(property)] - fn voltage_max_design(&self) -> zbus::Result; - - fn get_history( - &self, - type_: String, - timespan: u32, - resolution: u32, - ) -> zbus::Result>; - - fn get_statistics(&self, type_: String) -> zbus::Result>; #[zbus(signal)] fn enable_charge_threshold(&self, message: bool) -> zbus::Result<()>; + #[zbus(signal)] + fn get_history(&self, type_: String, timespan: u32, resolution: u32) -> zbus::Result>; + + #[zbus(signal)] + fn get_statistics(&self, type_: String) -> zbus::Result<()>; + #[zbus(signal)] fn refresh(&self) -> zbus::Result<()>; }