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",
"png",
] }
lazy_static = "1.5.0"
libc = { version = "0.2.175", optional = true }
license = { version = "3.7.0", optional = true }
mime = { version = "0.3.17", optional = true }

View file

@ -1,7 +1,7 @@
[package]
name = "cosmic-config"
version = "0.1.0"
edition = "2021"
edition = "2024"
[features]
default = ["macro", "subscription"]
@ -20,7 +20,6 @@ serde = "1.0.219"
cosmic-config-derive = { path = "../cosmic-config-derive/", optional = true }
iced = { path = "../iced/", 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 }
dirs.workspace = true
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 futures_util::SinkExt;
use iced_futures::{
futures::{self, future::pending, Stream, StreamExt},
stream, Subscription,
Subscription,
futures::{self, Stream, StreamExt, future::pending},
stream,
};
pub async fn settings_daemon_proxy() -> zbus::Result<CosmicSettingsDaemonProxy<'static>> {

View file

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

View file

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

View file

@ -1,7 +1,7 @@
[package]
name = "cosmic-theme"
version = "0.1.0"
edition = "2021"
edition = "2024"
# 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",
] }
ron = "0.11.0"
lazy_static = "1.5.0"
csscolorparser = { version = "0.7.2", features = ["serde"] }
cosmic-config = { path = "../cosmic-config/", default-features = false, features = [
"subscription",

View file

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

View file

@ -1,12 +1,12 @@
use crate::{
Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, DARK_PALETTE,
LIGHT_PALETTE, NAME, Spacing, ThemeMode,
composite::over,
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 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 std::num::NonZeroUsize;

View file

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

View file

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

View file

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
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
#[derive(Debug, Clone, Serialize, Deserialize)]

View file

@ -1,7 +1,7 @@
use std::num::NonZeroUsize;
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
/// over the full range of lightness.

View file

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

View file

@ -119,22 +119,14 @@ where
macro_rules! icon {
($name:expr, $on_press:expr) => {{
#[cfg(target_os = "linux")]
let icon = {
icon::from_name($name)
.apply(button::icon)
};
let icon = { icon::from_name($name).apply(button::icon) };
#[cfg(not(target_os = "linux"))]
let icon = {
icon::from_svg_bytes(include_bytes!(concat!(
"../../res/icons/",
$name,
".svg"
)))
.symbolic(true)
.apply(button::icon)
icon::from_svg_bytes(include_bytes!(concat!("../../res/icons/", $name, ".svg")))
.symbolic(true)
.apply(button::icon)
};
icon.padding([0, 12])
.on_press($on_press)
icon.padding([0, 12]).on_press($on_press)
}};
}
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::iter;
use std::rc::Rc;
use std::sync::LazyLock;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant};
@ -26,7 +27,6 @@ use iced_core::{
use iced_widget::slider::HandleShape;
use iced_widget::{Row, canvas, column, horizontal_space, row, scrollable, vertical_space};
use lazy_static::lazy_static;
use palette::{FromColor, RgbHue};
use super::divider::horizontal;
@ -38,17 +38,17 @@ use super::{Icon, button, segmented_control, text, text_input, tooltip};
pub use ColorPickerModel as Model;
// TODO is this going to look correct enough?
lazy_static! {
pub static ref HSV_RAINBOW: Vec<iced::Color> = (0u16..8)
.map(
|h| iced::Color::from(palette::Srgba::from_color(palette::Hsv::new_srgb_const(
pub static HSV_RAINBOW: LazyLock<Vec<Color>> = LazyLock::new(|| {
(0u16..8)
.map(|h| {
Color::from(palette::Srgba::from_color(palette::Hsv::new_srgb_const(
RgbHue::new(f32::from(h) * 360.0 / 7.0),
1.0,
1.0
1.0,
)))
)
.collect();
}
})
.collect()
});
const MAX_RECENT: usize = 20;