chore: use std::syncLazyLock

Also migrates workspace members to Rust 2024.
This commit is contained in:
Vukašin Vojinović 2025-09-03 20:22:06 +02:00 committed by Michael Murphy
parent b72b15d719
commit ea349aca82
15 changed files with 64 additions and 71 deletions

View file

@ -114,7 +114,6 @@ image = { version = "0.25.8", default-features = false, features = [
"jpeg", "jpeg",
"png", "png",
] } ] }
lazy_static = "1.5.0"
libc = { version = "0.2.175", optional = true } libc = { version = "0.2.175", optional = true }
license = { version = "3.7.0", optional = true } license = { version = "3.7.0", optional = true }
mime = { version = "0.3.17", optional = true } mime = { version = "0.3.17", optional = true }

View file

@ -1,7 +1,7 @@
[package] [package]
name = "cosmic-config" name = "cosmic-config"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2024"
[features] [features]
default = ["macro", "subscription"] default = ["macro", "subscription"]
@ -20,7 +20,6 @@ serde = "1.0.219"
cosmic-config-derive = { path = "../cosmic-config-derive/", optional = true } cosmic-config-derive = { path = "../cosmic-config-derive/", optional = true }
iced = { path = "../iced/", default-features = false, optional = true } iced = { path = "../iced/", default-features = false, optional = true }
iced_futures = { path = "../iced/futures/", default-features = false, optional = true } iced_futures = { path = "../iced/futures/", default-features = false, optional = true }
once_cell = "1.21.3"
futures-util = { version = "0.3", optional = true } futures-util = { version = "0.3", optional = true }
dirs.workspace = true dirs.workspace = true
tokio = { version = "1.47", optional = true, features = ["time"] } tokio = { version = "1.47", optional = true, features = ["time"] }

View file

@ -4,8 +4,9 @@ use crate::{CosmicConfigEntry, Update};
use cosmic_settings_daemon::{Changed, ConfigProxy, CosmicSettingsDaemonProxy}; use cosmic_settings_daemon::{Changed, ConfigProxy, CosmicSettingsDaemonProxy};
use futures_util::SinkExt; use futures_util::SinkExt;
use iced_futures::{ use iced_futures::{
futures::{self, future::pending, Stream, StreamExt}, Subscription,
stream, Subscription, futures::{self, Stream, StreamExt, future::pending},
stream,
}; };
pub async fn settings_daemon_proxy() -> zbus::Result<CosmicSettingsDaemonProxy<'static>> { pub async fn settings_daemon_proxy() -> zbus::Result<CosmicSettingsDaemonProxy<'static>> {

View file

@ -1,10 +1,10 @@
//! Integrations for cosmic-config — the cosmic configuration system. //! Integrations for cosmic-config — the cosmic configuration system.
use notify::{ use notify::{
event::{EventKind, ModifyKind, RenameMode},
RecommendedWatcher, Watcher, RecommendedWatcher, Watcher,
event::{EventKind, ModifyKind, RenameMode},
}; };
use serde::{de::DeserializeOwned, Serialize}; use serde::{Serialize, de::DeserializeOwned};
use std::{ use std::{
fmt, fs, fmt, fs,
io::Write, io::Write,

View file

@ -62,7 +62,7 @@ async fn start_listening<T: 'static + Send + Sync + PartialEq + Clone + CosmicCo
state: ConfigState<T>, state: ConfigState<T>,
output: &mut mpsc::Sender<crate::Update<T>>, output: &mut mpsc::Sender<crate::Update<T>>,
) -> ConfigState<T> { ) -> ConfigState<T> {
use iced_futures::futures::{future::pending, StreamExt}; use iced_futures::futures::{StreamExt, future::pending};
match state { match state {
ConfigState::Init(config_id, version, is_state) => { ConfigState::Init(config_id, version, is_state) => {

View file

@ -1,7 +1,7 @@
[package] [package]
name = "cosmic-theme" name = "cosmic-theme"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -22,7 +22,6 @@ serde_json = { version = "1.0.143", optional = true, features = [
"preserve_order", "preserve_order",
] } ] }
ron = "0.11.0" ron = "0.11.0"
lazy_static = "1.5.0"
csscolorparser = { version = "0.7.2", features = ["serde"] } csscolorparser = { version = "0.7.2", features = ["serde"] }
cosmic-config = { path = "../cosmic-config/", default-features = false, features = [ cosmic-config = { path = "../cosmic-config/", default-features = false, features = [
"subscription", "subscription",

View file

@ -1,15 +1,14 @@
use lazy_static::lazy_static;
use palette::Srgba; use palette::Srgba;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::LazyLock;
lazy_static! { /// built-in light palette
/// built in light palette pub static LIGHT_PALETTE: LazyLock<CosmicPalette> =
pub static ref LIGHT_PALETTE: CosmicPalette = LazyLock::new(|| ron::from_str(include_str!("light.ron")).unwrap());
ron::from_str(include_str!("light.ron")).unwrap();
/// built in dark palette /// built-in dark palette
pub static ref DARK_PALETTE: CosmicPalette = pub static DARK_PALETTE: LazyLock<CosmicPalette> =
ron::from_str(include_str!("dark.ron")).unwrap(); LazyLock::new(|| ron::from_str(include_str!("dark.ron")).unwrap());
}
/// Palette type /// Palette type
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]

View file

@ -1,12 +1,12 @@
use crate::{ use crate::{
Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, DARK_PALETTE,
LIGHT_PALETTE, NAME, Spacing, ThemeMode,
composite::over, composite::over,
steps::{color_index, get_small_widget_color, get_surface_color, get_text, steps}, steps::{color_index, get_small_widget_color, get_surface_color, get_text, steps},
Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, Spacing, ThemeMode,
DARK_PALETTE, LIGHT_PALETTE, NAME,
}; };
use cosmic_config::{Config, CosmicConfigEntry}; use cosmic_config::{Config, CosmicConfigEntry};
use palette::{ use palette::{
color_difference::Wcag21RelativeContrast, rgb::Rgb, IntoColor, Oklcha, Srgb, Srgba, WithAlpha, IntoColor, Oklcha, Srgb, Srgba, WithAlpha, color_difference::Wcag21RelativeContrast, rgb::Rgb,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::num::NonZeroUsize; use std::num::NonZeroUsize;

View file

@ -1,5 +1,5 @@
use crate::{composite::over, steps::steps, Component, Theme}; use crate::{Component, Theme, composite::over, steps::steps};
use palette::{rgb::Rgba, Darken, IntoColor, Lighten, Srgba, WithAlpha}; use palette::{Darken, IntoColor, Lighten, Srgba, WithAlpha, rgb::Rgba};
use std::{ use std::{
fs::{self, File}, fs::{self, File},
io::{self, Write}, io::{self, Write},
@ -7,7 +7,7 @@ use std::{
path::Path, path::Path,
}; };
use super::{to_rgba, OutputError}; use super::{OutputError, to_rgba};
impl Theme { impl Theme {
#[must_use] #[must_use]

View file

@ -1,4 +1,4 @@
use palette::{rgb::Rgba, Srgba}; use palette::{Srgba, rgb::Rgba};
use thiserror::Error; use thiserror::Error;
use crate::Theme; use crate::Theme;

View file

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::Theme; use crate::Theme;
use super::{to_hex, OutputError}; use super::{OutputError, to_hex};
/// Represents the workbench.colorCustomizations section of a VS Code settings.json file /// Represents the workbench.colorCustomizations section of a VS Code settings.json file
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]

View file

@ -1,7 +1,7 @@
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
use almost::equal; use almost::equal;
use palette::{convert::FromColorUnclamped, ClampAssign, FromColor, Lch, Oklcha, Srgb, Srgba}; use palette::{ClampAssign, FromColor, Lch, Oklcha, Srgb, Srgba, convert::FromColorUnclamped};
/// Get an array of 100 colors with a specific hue and chroma /// Get an array of 100 colors with a specific hue and chroma
/// over the full range of lightness. /// over the full range of lightness.

View file

@ -15,33 +15,37 @@ use cosmic_theme::Spacing;
use cosmic_theme::ThemeMode; use cosmic_theme::ThemeMode;
use iced_futures::Subscription; use iced_futures::Subscription;
use iced_runtime::{Appearance, DefaultStyle}; use iced_runtime::{Appearance, DefaultStyle};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, LazyLock, Mutex};
pub use style::*; pub use style::*;
pub type CosmicColor = ::palette::rgb::Srgba; pub type CosmicColor = ::palette::rgb::Srgba;
pub type CosmicComponent = cosmic_theme::Component; pub type CosmicComponent = cosmic_theme::Component;
pub type CosmicTheme = cosmic_theme::Theme; pub type CosmicTheme = cosmic_theme::Theme;
lazy_static::lazy_static! { pub static COSMIC_DARK: LazyLock<CosmicTheme> = LazyLock::new(|| CosmicTheme::dark_default());
pub static ref COSMIC_DARK: CosmicTheme = CosmicTheme::dark_default();
pub static ref COSMIC_HC_DARK: CosmicTheme = CosmicTheme::high_contrast_dark_default(); pub static COSMIC_HC_DARK: LazyLock<CosmicTheme> =
pub static ref COSMIC_LIGHT: CosmicTheme = CosmicTheme::light_default(); LazyLock::new(|| CosmicTheme::high_contrast_dark_default());
pub static ref COSMIC_HC_LIGHT: CosmicTheme = CosmicTheme::high_contrast_light_default();
pub static ref TRANSPARENT_COMPONENT: Component = Component { pub static COSMIC_LIGHT: LazyLock<CosmicTheme> = LazyLock::new(|| CosmicTheme::light_default());
base: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
hover: CosmicColor::new(0.0, 0.0, 0.0, 0.0), pub static COSMIC_HC_LIGHT: LazyLock<CosmicTheme> =
pressed: CosmicColor::new(0.0, 0.0, 0.0, 0.0), LazyLock::new(|| CosmicTheme::high_contrast_light_default());
selected: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
selected_text: CosmicColor::new(0.0, 0.0, 0.0, 0.0), pub static TRANSPARENT_COMPONENT: LazyLock<Component> = LazyLock::new(|| Component {
focus: CosmicColor::new(0.0, 0.0, 0.0, 0.0), base: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0), hover: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
on: CosmicColor::new(0.0, 0.0, 0.0, 0.0), pressed: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
on_disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0), selected: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
divider: CosmicColor::new(0.0, 0.0, 0.0, 0.0), selected_text: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
border: CosmicColor::new(0.0, 0.0, 0.0, 0.0), focus: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
disabled_border: CosmicColor::new(0.0, 0.0, 0.0, 0.0), disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
}; on: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
} on_disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
divider: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
border: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
disabled_border: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
});
pub(crate) static THEME: Mutex<Theme> = Mutex::new(Theme { pub(crate) static THEME: Mutex<Theme> = Mutex::new(Theme {
theme_type: ThemeType::Dark, theme_type: ThemeType::Dark,

View file

@ -119,22 +119,14 @@ where
macro_rules! icon { macro_rules! icon {
($name:expr, $on_press:expr) => {{ ($name:expr, $on_press:expr) => {{
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let icon = { let icon = { icon::from_name($name).apply(button::icon) };
icon::from_name($name)
.apply(button::icon)
};
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
let icon = { let icon = {
icon::from_svg_bytes(include_bytes!(concat!( icon::from_svg_bytes(include_bytes!(concat!("../../res/icons/", $name, ".svg")))
"../../res/icons/", .symbolic(true)
$name, .apply(button::icon)
".svg"
)))
.symbolic(true)
.apply(button::icon)
}; };
icon.padding([0, 12]) icon.padding([0, 12]).on_press($on_press)
.on_press($on_press)
}}; }};
} }
let date = text(this.model.visible.format("%B %Y").to_string()).size(18); let date = text(this.model.visible.format("%B %Y").to_string()).size(18);

View file

@ -6,6 +6,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::iter; use std::iter;
use std::rc::Rc; use std::rc::Rc;
use std::sync::LazyLock;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -26,7 +27,6 @@ use iced_core::{
use iced_widget::slider::HandleShape; use iced_widget::slider::HandleShape;
use iced_widget::{Row, canvas, column, horizontal_space, row, scrollable, vertical_space}; use iced_widget::{Row, canvas, column, horizontal_space, row, scrollable, vertical_space};
use lazy_static::lazy_static;
use palette::{FromColor, RgbHue}; use palette::{FromColor, RgbHue};
use super::divider::horizontal; use super::divider::horizontal;
@ -38,17 +38,17 @@ use super::{Icon, button, segmented_control, text, text_input, tooltip};
pub use ColorPickerModel as Model; pub use ColorPickerModel as Model;
// TODO is this going to look correct enough? // TODO is this going to look correct enough?
lazy_static! { pub static HSV_RAINBOW: LazyLock<Vec<Color>> = LazyLock::new(|| {
pub static ref HSV_RAINBOW: Vec<iced::Color> = (0u16..8) (0u16..8)
.map( .map(|h| {
|h| iced::Color::from(palette::Srgba::from_color(palette::Hsv::new_srgb_const( Color::from(palette::Srgba::from_color(palette::Hsv::new_srgb_const(
RgbHue::new(f32::from(h) * 360.0 / 7.0), RgbHue::new(f32::from(h) * 360.0 / 7.0),
1.0, 1.0,
1.0 1.0,
))) )))
) })
.collect(); .collect()
} });
const MAX_RECENT: usize = 20; const MAX_RECENT: usize = 20;