diff --git a/Cargo.lock b/Cargo.lock index 1b30132..ea6ba20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -293,7 +293,6 @@ dependencies = [ "hex", "image 0.25.4", "libadwaita", - "once_cell", "oo7", "percent-encoding", "prost", diff --git a/Cargo.toml b/Cargo.toml index 8ab355d..e817f29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "authenticator" -rust-version = "1.70" +rust-version = "1.80" [profile.release] debug = true @@ -29,7 +29,6 @@ gettext-rs = {version = "0.7", features = ["gettext-system"]} gtk = {package = "gtk4", version = "0.9", features = ["v4_10"]} hex = {version = "0.4.3", features = ["serde"]} image = {version = "0.25", default-features = false, features = ["png"]} -once_cell = "1.9" oo7 = {version = "0.3", default-features = false, features = ["tokio", "native_crypto", "tracing"]} percent-encoding = "2.1" prost = "0.13" diff --git a/favicon-scrapper/src/favicon.rs b/favicon-scrapper/src/favicon.rs index df8b62d..cdc416f 100644 --- a/favicon-scrapper/src/favicon.rs +++ b/favicon-scrapper/src/favicon.rs @@ -1,6 +1,6 @@ use std::{fmt, io::Cursor, path::PathBuf}; -use image::io::Reader as ImageReader; +use image::ImageReader; use tokio::{io::AsyncWriteExt, sync::Mutex}; use url::Url; diff --git a/src/backup/google.rs b/src/backup/google.rs index 8e20ab8..a31a441 100644 --- a/src/backup/google.rs +++ b/src/backup/google.rs @@ -90,9 +90,7 @@ impl Restorable for Google { secret: { let string = data_encoding::BASE32_NOPAD.encode(&otp.secret); - string - .trim_end_matches(|c| c == '\0' || c == '=') - .to_owned() + string.trim_end_matches(['\0', '=']).to_owned() }, label: otp.name.clone(), issuer: otp.issuer.clone(), diff --git a/src/models/account.rs b/src/models/account.rs index 8f9175d..4906996 100644 --- a/src/models/account.rs +++ b/src/models/account.rs @@ -34,10 +34,12 @@ pub struct DieselAccount { #[doc(hidden)] mod imp { - use std::cell::{Cell, OnceCell, RefCell}; + use std::{ + cell::{Cell, OnceCell, RefCell}, + sync::LazyLock, + }; use glib::ParamSpecObject; - use once_cell::sync::Lazy; use super::*; @@ -79,7 +81,7 @@ mod imp { impl ObjectImpl for Account { fn properties() -> &'static [glib::ParamSpec] { - static PROPERTIES: Lazy> = Lazy::new(|| { + static PROPERTIES: LazyLock> = LazyLock::new(|| { let mut props = Account::derived_properties().to_vec(); props.push(ParamSpecObject::builder::("provider").build()); props diff --git a/src/models/database.rs b/src/models/database.rs index da4e1f6..784d3f0 100644 --- a/src/models/database.rs +++ b/src/models/database.rs @@ -1,14 +1,14 @@ -use std::{fs, fs::File, path::PathBuf}; +use std::{fs, fs::File, path::PathBuf, sync::LazyLock}; use anyhow::Result; use diesel::{prelude::*, r2d2, r2d2::ConnectionManager}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; -use once_cell::sync::Lazy; type Pool = r2d2::Pool>; -static DB_PATH: Lazy = Lazy::new(|| gtk::glib::user_data_dir().join("authenticator")); -static POOL: Lazy = Lazy::new(|| init_pool().expect("Failed to create a pool")); +static DB_PATH: LazyLock = + LazyLock::new(|| gtk::glib::user_data_dir().join("authenticator")); +static POOL: LazyLock = LazyLock::new(|| init_pool().expect("Failed to create a pool")); pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations/"); diff --git a/src/models/keyring.rs b/src/models/keyring.rs index c7979f3..65a129a 100644 --- a/src/models/keyring.rs +++ b/src/models/keyring.rs @@ -1,11 +1,10 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::OnceLock}; -use once_cell::sync::OnceCell; use rand::RngCore; use crate::config; -pub static SECRET_SERVICE: OnceCell = OnceCell::new(); +pub static SECRET_SERVICE: OnceLock = OnceLock::new(); fn token_attributes(token_id: &str) -> HashMap<&str, &str> { HashMap::from([ diff --git a/src/models/mod.rs b/src/models/mod.rs index ce87d42..44e27e5 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1,4 +1,4 @@ -use once_cell::sync::Lazy; +use std::sync::LazyLock; mod account; mod accounts; @@ -13,10 +13,10 @@ mod providers; mod search_provider; mod settings; -pub static RUNTIME: Lazy = - Lazy::new(|| tokio::runtime::Runtime::new().unwrap()); -pub static SETTINGS: Lazy = Lazy::new(Settings::default); -pub static FAVICONS_PATH: Lazy = Lazy::new(|| { +pub static RUNTIME: LazyLock = + LazyLock::new(|| tokio::runtime::Runtime::new().unwrap()); +pub static SETTINGS: LazyLock = LazyLock::new(Settings::default); +pub static FAVICONS_PATH: LazyLock = LazyLock::new(|| { gtk::glib::user_cache_dir() .join("authenticator") .join("favicons") diff --git a/src/models/provider.rs b/src/models/provider.rs index b6c75c0..01a3bb1 100644 --- a/src/models/provider.rs +++ b/src/models/provider.rs @@ -206,10 +206,9 @@ impl Provider { .load::(&mut conn)? .into_iter() .map(From::from) - .map(|p: Provider| { - let accounts = Account::load(&p).unwrap().collect::>(); + .inspect(|p: &Provider| { + let accounts = Account::load(p).unwrap().collect::>(); p.add_accounts(&accounts); - p }); Ok(results) } diff --git a/src/widgets/accounts/add.rs b/src/widgets/accounts/add.rs index 73a9d90..44fa4c8 100644 --- a/src/widgets/accounts/add.rs +++ b/src/widgets/accounts/add.rs @@ -13,10 +13,12 @@ use crate::{ }; mod imp { - use std::cell::{OnceCell, RefCell}; + use std::{ + cell::{OnceCell, RefCell}, + sync::LazyLock, + }; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -118,8 +120,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for AccountAddDialog { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("added").action().build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("added").action().build()]); SIGNALS.as_ref() } diff --git a/src/widgets/accounts/details.rs b/src/widgets/accounts/details.rs index bd8aea3..37932b7 100644 --- a/src/widgets/accounts/details.rs +++ b/src/widgets/accounts/details.rs @@ -12,10 +12,12 @@ use crate::{ widgets::UrlRow, }; mod imp { - use std::cell::{OnceCell, RefCell}; + use std::{ + cell::{OnceCell, RefCell}, + sync::LazyLock, + }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -87,7 +89,7 @@ mod imp { impl ObjectImpl for AccountDetailsPage { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ Signal::builder("removed") .param_types([Account::static_type()]) diff --git a/src/widgets/camera.rs b/src/widgets/camera.rs index e1d55cb..5badbc4 100644 --- a/src/widgets/camera.rs +++ b/src/widgets/camera.rs @@ -1,4 +1,8 @@ -use std::{cell::OnceCell, os::fd::OwnedFd, sync::Once}; +use std::{ + cell::OnceCell, + os::fd::OwnedFd, + sync::{LazyLock, Once}, +}; use adw::subclass::prelude::*; use anyhow::Result; @@ -9,7 +13,6 @@ use gtk::{ prelude::*, }; use image::GenericImageView; -use once_cell::sync::Lazy; use super::CameraRow; use crate::utils::spawn_tokio; @@ -99,7 +102,7 @@ mod imp { impl ObjectImpl for Camera { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ Signal::builder("close").action().build(), Signal::builder("code-detected") diff --git a/src/widgets/preferences/window.rs b/src/widgets/preferences/window.rs index b4f2bf0..68d310b 100644 --- a/src/widgets/preferences/window.rs +++ b/src/widgets/preferences/window.rs @@ -22,11 +22,11 @@ mod imp { use std::{ cell::{Cell, OnceCell, RefCell}, collections::HashMap, + sync::LazyLock, }; use adw::subclass::prelude::*; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -97,8 +97,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for PreferencesWindow { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("restore-completed").action().build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("restore-completed").action().build()]); SIGNALS.as_ref() } diff --git a/src/widgets/providers/dialog.rs b/src/widgets/providers/dialog.rs index 7032d66..3d73dd5 100644 --- a/src/widgets/providers/dialog.rs +++ b/src/widgets/providers/dialog.rs @@ -12,10 +12,9 @@ enum View { } mod imp { - use std::cell::OnceCell; + use std::{cell::OnceCell, sync::LazyLock}; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; use crate::config; @@ -82,8 +81,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for ProvidersDialog { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("changed").build()]); SIGNALS.as_ref() } diff --git a/src/widgets/providers/list.rs b/src/widgets/providers/list.rs index d53fead..03bcb17 100644 --- a/src/widgets/providers/list.rs +++ b/src/widgets/providers/list.rs @@ -15,6 +15,8 @@ pub enum ProvidersListView { } mod imp { + use std::sync::LazyLock; + use glib::subclass::Signal; use super::*; @@ -52,8 +54,7 @@ mod imp { } fn signals() -> &'static [Signal] { - use once_cell::sync::Lazy; - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![Signal::builder("shared") .param_types([Account::static_type()]) .action() diff --git a/src/widgets/providers/page.rs b/src/widgets/providers/page.rs index 8c86b6f..747b341 100644 --- a/src/widgets/providers/page.rs +++ b/src/widgets/providers/page.rs @@ -14,7 +14,7 @@ use crate::{ }; mod imp { - use std::cell::RefCell; + use std::{cell::RefCell, sync::LazyLock}; use glib::subclass::Signal; @@ -114,8 +114,7 @@ mod imp { impl ObjectImpl for ProviderPage { fn signals() -> &'static [Signal] { - use once_cell::sync::Lazy; - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ Signal::builder("created") .param_types([Provider::static_type()]) diff --git a/src/widgets/providers/row.rs b/src/widgets/providers/row.rs index 18347f9..1f7bd50 100644 --- a/src/widgets/providers/row.rs +++ b/src/widgets/providers/row.rs @@ -12,10 +12,9 @@ use crate::{ }; mod imp { - use std::cell::OnceCell; + use std::{cell::OnceCell, sync::LazyLock}; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -53,7 +52,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for ProviderRow { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ Signal::builder("changed").action().build(), Signal::builder("shared")