refactor: remove once_cell (#1361)

* refactor: remove once_cell

* some missing fixes
This commit is contained in:
Clement Tsang 2023-12-23 04:35:42 -05:00 committed by GitHub
parent 854f3aed95
commit a1168cac67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 289 additions and 283 deletions

1
Cargo.lock generated
View file

@ -176,7 +176,6 @@ dependencies = [
"log", "log",
"mach2", "mach2",
"nvml-wrapper", "nvml-wrapper",
"once_cell",
"predicates", "predicates",
"ratatui", "ratatui",
"regex", "regex",

View file

@ -93,10 +93,7 @@ indexmap = "2.1.0"
itertools = "0.12.0" itertools = "0.12.0"
kstring = { version = "2.0.0", features = ["arc"] } kstring = { version = "2.0.0", features = ["arc"] }
log = { version = "0.4.20", optional = true } log = { version = "0.4.20", optional = true }
nvml-wrapper = { version = "0.9.0", optional = true, features = [ nvml-wrapper = { version = "0.9.0", optional = true, features = ["legacy-functions"] }
"legacy-functions",
] }
once_cell = "1.18.0"
regex = "1.10.2" regex = "1.10.2"
serde = { version = "=1.0.193", features = ["derive"] } serde = { version = "=1.0.193", features = ["derive"] }
starship-battery = { version = "0.8.2", optional = true } starship-battery = { version = "0.8.2", optional = true }
@ -136,9 +133,7 @@ filedescriptor = "0.8.2"
[dev-dependencies] [dev-dependencies]
assert_cmd = "2.0.12" assert_cmd = "2.0.12"
cargo-husky = { version = "1.5.0", default-features = false, features = [ cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] }
"user-hooks",
] }
predicates = "3.0.3" predicates = "3.0.3"
[build-dependencies] [build-dependencies]

View file

@ -364,13 +364,12 @@ impl DataCollection {
let io_device = { let io_device = {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] { if #[cfg(target_os = "macos")] {
use once_cell::sync::Lazy; use std::sync::OnceLock;
use regex::Regex; use regex::Regex;
// Must trim one level further for macOS! // Must trim one level further for macOS!
static DISK_REGEX: Lazy<Regex> = static DISK_REGEX: OnceLock<Regex> = OnceLock::new();
Lazy::new(|| Regex::new(r"disk\d+").unwrap()); if let Some(new_name) = DISK_REGEX.get_or_init(|| Regex::new(r"disk\d+").unwrap()).find(checked_name) {
if let Some(new_name) = DISK_REGEX.find(checked_name) {
io.get(new_name.as_str()) io.get(new_name.as_str())
} else { } else {
None None

View file

@ -1,8 +1,9 @@
use std::sync::OnceLock;
use hashbrown::HashMap; use hashbrown::HashMap;
use nvml_wrapper::enum_wrappers::device::TemperatureSensor; use nvml_wrapper::enum_wrappers::device::TemperatureSensor;
use nvml_wrapper::enums::device::UsedGpuMemory; use nvml_wrapper::enums::device::UsedGpuMemory;
use nvml_wrapper::{error::NvmlError, Nvml}; use nvml_wrapper::{error::NvmlError, Nvml};
use once_cell::sync::Lazy;
use crate::app::Filter; use crate::app::Filter;
@ -10,7 +11,7 @@ use crate::app::layout_manager::UsedWidgets;
use crate::data_harvester::memory::MemHarvest; use crate::data_harvester::memory::MemHarvest;
use crate::data_harvester::temperature::{is_temp_filtered, TempHarvest, TemperatureType}; use crate::data_harvester::temperature::{is_temp_filtered, TempHarvest, TemperatureType};
pub static NVML_DATA: Lazy<Result<Nvml, NvmlError>> = Lazy::new(Nvml::init); pub static NVML_DATA: OnceLock<Result<Nvml, NvmlError>> = OnceLock::new();
pub struct GpusData { pub struct GpusData {
pub memory: Option<Vec<(String, MemHarvest)>>, pub memory: Option<Vec<(String, MemHarvest)>>,
@ -23,7 +24,7 @@ pub struct GpusData {
pub fn get_nvidia_vecs( pub fn get_nvidia_vecs(
temp_type: &TemperatureType, filter: &Option<Filter>, widgets_to_harvest: &UsedWidgets, temp_type: &TemperatureType, filter: &Option<Filter>, widgets_to_harvest: &UsedWidgets,
) -> Option<GpusData> { ) -> Option<GpusData> {
if let Ok(nvml) = &*NVML_DATA { if let Ok(nvml) = NVML_DATA.get_or_init(Nvml::init) {
if let Ok(num_gpu) = nvml.device_count() { if let Ok(num_gpu) = nvml.device_count() {
let mut temp_vec = Vec::with_capacity(num_gpu as usize); let mut temp_vec = Vec::with_capacity(num_gpu as usize);
let mut mem_vec = Vec::with_capacity(num_gpu as usize); let mut mem_vec = Vec::with_capacity(num_gpu as usize);

View file

@ -5,11 +5,11 @@ use std::{
fs::File, fs::File,
io::{self, BufRead, BufReader, Read}, io::{self, BufRead, BufReader, Read},
path::PathBuf, path::PathBuf,
sync::OnceLock,
}; };
use anyhow::anyhow; use anyhow::anyhow;
use libc::uid_t; use libc::uid_t;
use once_cell::sync::Lazy;
use rustix::{ use rustix::{
fd::OwnedFd, fd::OwnedFd,
fs::{Mode, OFlags}, fs::{Mode, OFlags},
@ -18,7 +18,7 @@ use rustix::{
use crate::Pid; use crate::Pid;
static PAGESIZE: Lazy<u64> = Lazy::new(|| rustix::param::page_size() as u64); static PAGESIZE: OnceLock<u64> = OnceLock::new();
#[inline] #[inline]
fn next_part<'a>(iter: &mut impl Iterator<Item = &'a str>) -> Result<&'a str, io::Error> { fn next_part<'a>(iter: &mut impl Iterator<Item = &'a str>) -> Result<&'a str, io::Error> {
@ -103,7 +103,7 @@ impl Stat {
/// Returns the Resident Set Size in bytes. /// Returns the Resident Set Size in bytes.
#[inline] #[inline]
pub fn rss_bytes(&self) -> u64 { pub fn rss_bytes(&self) -> u64 {
self.rss * *PAGESIZE self.rss * PAGESIZE.get_or_init(|| rustix::param::page_size() as u64)
} }
} }

View file

@ -132,19 +132,19 @@ impl CanvasStyling {
match colour_scheme { match colour_scheme {
ColourScheme::Default => {} ColourScheme::Default => {}
ColourScheme::DefaultLight => { ColourScheme::DefaultLight => {
canvas_colours.set_colours_from_palette(&DEFAULT_LIGHT_MODE_COLOUR_PALETTE)?; canvas_colours.set_colours_from_palette(&default_light_mode_colour_palette())?;
} }
ColourScheme::Gruvbox => { ColourScheme::Gruvbox => {
canvas_colours.set_colours_from_palette(&GRUVBOX_COLOUR_PALETTE)?; canvas_colours.set_colours_from_palette(&gruvbox_colour_palette())?;
} }
ColourScheme::GruvboxLight => { ColourScheme::GruvboxLight => {
canvas_colours.set_colours_from_palette(&GRUVBOX_LIGHT_COLOUR_PALETTE)?; canvas_colours.set_colours_from_palette(&gruvbox_light_colour_palette())?;
} }
ColourScheme::Nord => { ColourScheme::Nord => {
canvas_colours.set_colours_from_palette(&NORD_COLOUR_PALETTE)?; canvas_colours.set_colours_from_palette(&nord_colour_palette())?;
} }
ColourScheme::NordLight => { ColourScheme::NordLight => {
canvas_colours.set_colours_from_palette(&NORD_LIGHT_COLOUR_PALETTE)?; canvas_colours.set_colours_from_palette(&nord_light_colour_palette())?;
} }
ColourScheme::Custom => { ColourScheme::Custom => {
if let Some(colors) = &config.colors { if let Some(colors) = &config.colors {

View file

@ -1,4 +1,3 @@
use once_cell::sync::Lazy;
use tui::widgets::Borders; use tui::widgets::Borders;
use crate::options::ConfigColours; use crate::options::ConfigColours;
@ -23,253 +22,260 @@ pub const TIME_LABEL_HEIGHT_LIMIT: u16 = 7;
// Side borders // Side borders
pub const SIDE_BORDERS: Borders = Borders::LEFT.union(Borders::RIGHT); pub const SIDE_BORDERS: Borders = Borders::LEFT.union(Borders::RIGHT);
pub static DEFAULT_TEXT_STYLE: Lazy<tui::style::Style> =
Lazy::new(|| tui::style::Style::default().fg(tui::style::Color::Gray));
pub static DEFAULT_HEADER_STYLE: Lazy<tui::style::Style> =
Lazy::new(|| tui::style::Style::default().fg(tui::style::Color::LightBlue));
// Colour profiles // Colour profiles
pub static DEFAULT_LIGHT_MODE_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours { // TODO: Generate these with a macro or something...
text_color: Some("black".into()), pub fn default_light_mode_colour_palette() -> ConfigColours {
border_color: Some("black".into()), ConfigColours {
table_header_color: Some("black".into()), text_color: Some("black".into()),
widget_title_color: Some("black".into()), border_color: Some("black".into()),
selected_text_color: Some("white".into()), table_header_color: Some("black".into()),
graph_color: Some("black".into()), widget_title_color: Some("black".into()),
disabled_text_color: Some("gray".into()), selected_text_color: Some("white".into()),
ram_color: Some("blue".into()), graph_color: Some("black".into()),
#[cfg(not(target_os = "windows"))] disabled_text_color: Some("gray".into()),
cache_color: Some("LightRed".into()), ram_color: Some("blue".into()),
swap_color: Some("red".into()), #[cfg(not(target_os = "windows"))]
arc_color: Some("LightBlue".into()), cache_color: Some("LightRed".into()),
gpu_core_colors: Some(vec![ swap_color: Some("red".into()),
"LightGreen".into(), arc_color: Some("LightBlue".into()),
"LightCyan".into(), gpu_core_colors: Some(vec![
"LightRed".into(), "LightGreen".into(),
"Cyan".into(), "LightCyan".into(),
"Green".into(), "LightRed".into(),
"Blue".into(), "Cyan".into(),
"Red".into(), "Green".into(),
]), "Blue".into(),
rx_color: Some("blue".into()), "Red".into(),
tx_color: Some("red".into()), ]),
rx_total_color: Some("LightBlue".into()), rx_color: Some("blue".into()),
tx_total_color: Some("LightRed".into()), tx_color: Some("red".into()),
cpu_core_colors: Some(vec![ rx_total_color: Some("LightBlue".into()),
"LightMagenta".into(), tx_total_color: Some("LightRed".into()),
"LightBlue".into(), cpu_core_colors: Some(vec![
"LightRed".into(), "LightMagenta".into(),
"Cyan".into(), "LightBlue".into(),
"Green".into(), "LightRed".into(),
"Blue".into(), "Cyan".into(),
"Red".into(), "Green".into(),
]), "Blue".into(),
..ConfigColours::default() "Red".into(),
}); ]),
..ConfigColours::default()
}
}
pub static GRUVBOX_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours { pub fn gruvbox_colour_palette() -> ConfigColours {
table_header_color: Some("#83a598".into()), ConfigColours {
all_cpu_color: Some("#8ec07c".into()), table_header_color: Some("#83a598".into()),
avg_cpu_color: Some("#fb4934".into()), all_cpu_color: Some("#8ec07c".into()),
cpu_core_colors: Some(vec![ avg_cpu_color: Some("#fb4934".into()),
"#cc241d".into(), cpu_core_colors: Some(vec![
"#98971a".into(), "#cc241d".into(),
"#d79921".into(), "#98971a".into(),
"#458588".into(), "#d79921".into(),
"#b16286".into(), "#458588".into(),
"#689d6a".into(), "#b16286".into(),
"#fe8019".into(), "#689d6a".into(),
"#b8bb26".into(), "#fe8019".into(),
"#fabd2f".into(), "#b8bb26".into(),
"#83a598".into(), "#fabd2f".into(),
"#d3869b".into(), "#83a598".into(),
"#d65d0e".into(), "#d3869b".into(),
"#9d0006".into(), "#d65d0e".into(),
"#79740e".into(), "#9d0006".into(),
"#b57614".into(), "#79740e".into(),
"#076678".into(), "#b57614".into(),
"#8f3f71".into(), "#076678".into(),
"#427b58".into(), "#8f3f71".into(),
"#d65d03".into(), "#427b58".into(),
"#af3a03".into(), "#d65d03".into(),
]), "#af3a03".into(),
ram_color: Some("#8ec07c".into()), ]),
#[cfg(not(target_os = "windows"))] ram_color: Some("#8ec07c".into()),
cache_color: Some("#b16286".into()), #[cfg(not(target_os = "windows"))]
swap_color: Some("#fabd2f".into()), cache_color: Some("#b16286".into()),
arc_color: Some("#689d6a".into()), swap_color: Some("#fabd2f".into()),
gpu_core_colors: Some(vec![ arc_color: Some("#689d6a".into()),
"#d79921".into(), gpu_core_colors: Some(vec![
"#458588".into(), "#d79921".into(),
"#b16286".into(), "#458588".into(),
"#fe8019".into(), "#b16286".into(),
"#b8bb26".into(), "#fe8019".into(),
"#cc241d".into(), "#b8bb26".into(),
"#98971a".into(), "#cc241d".into(),
]), "#98971a".into(),
rx_color: Some("#8ec07c".into()), ]),
tx_color: Some("#fabd2f".into()), rx_color: Some("#8ec07c".into()),
rx_total_color: Some("#689d6a".into()), tx_color: Some("#fabd2f".into()),
tx_total_color: Some("#d79921".into()), rx_total_color: Some("#689d6a".into()),
border_color: Some("#ebdbb2".into()), tx_total_color: Some("#d79921".into()),
highlighted_border_color: Some("#fe8019".into()), border_color: Some("#ebdbb2".into()),
disabled_text_color: Some("#665c54".into()), highlighted_border_color: Some("#fe8019".into()),
text_color: Some("#ebdbb2".into()), disabled_text_color: Some("#665c54".into()),
selected_text_color: Some("#1d2021".into()), text_color: Some("#ebdbb2".into()),
selected_bg_color: Some("#ebdbb2".into()), selected_text_color: Some("#1d2021".into()),
widget_title_color: Some("#ebdbb2".into()), selected_bg_color: Some("#ebdbb2".into()),
graph_color: Some("#ebdbb2".into()), widget_title_color: Some("#ebdbb2".into()),
high_battery_color: Some("#98971a".into()), graph_color: Some("#ebdbb2".into()),
medium_battery_color: Some("#fabd2f".into()), high_battery_color: Some("#98971a".into()),
low_battery_color: Some("#fb4934".into()), medium_battery_color: Some("#fabd2f".into()),
}); low_battery_color: Some("#fb4934".into()),
}
}
pub static GRUVBOX_LIGHT_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours { pub fn gruvbox_light_colour_palette() -> ConfigColours {
table_header_color: Some("#076678".into()), ConfigColours {
all_cpu_color: Some("#8ec07c".into()), table_header_color: Some("#076678".into()),
avg_cpu_color: Some("#fb4934".into()), all_cpu_color: Some("#8ec07c".into()),
cpu_core_colors: Some(vec![ avg_cpu_color: Some("#fb4934".into()),
"#cc241d".into(), cpu_core_colors: Some(vec![
"#98971a".into(), "#cc241d".into(),
"#d79921".into(), "#98971a".into(),
"#458588".into(), "#d79921".into(),
"#b16286".into(), "#458588".into(),
"#689d6a".into(), "#b16286".into(),
"#fe8019".into(), "#689d6a".into(),
"#b8bb26".into(), "#fe8019".into(),
"#fabd2f".into(), "#b8bb26".into(),
"#83a598".into(), "#fabd2f".into(),
"#d3869b".into(), "#83a598".into(),
"#d65d0e".into(), "#d3869b".into(),
"#9d0006".into(), "#d65d0e".into(),
"#79740e".into(), "#9d0006".into(),
"#b57614".into(), "#79740e".into(),
"#076678".into(), "#b57614".into(),
"#8f3f71".into(), "#076678".into(),
"#427b58".into(), "#8f3f71".into(),
"#d65d03".into(), "#427b58".into(),
"#af3a03".into(), "#d65d03".into(),
]), "#af3a03".into(),
ram_color: Some("#427b58".into()), ]),
#[cfg(not(target_os = "windows"))] ram_color: Some("#427b58".into()),
cache_color: Some("#d79921".into()), #[cfg(not(target_os = "windows"))]
swap_color: Some("#cc241d".into()), cache_color: Some("#d79921".into()),
arc_color: Some("#689d6a".into()), swap_color: Some("#cc241d".into()),
gpu_core_colors: Some(vec![ arc_color: Some("#689d6a".into()),
"#9d0006".into(), gpu_core_colors: Some(vec![
"#98971a".into(), "#9d0006".into(),
"#d79921".into(), "#98971a".into(),
"#458588".into(), "#d79921".into(),
"#b16286".into(), "#458588".into(),
"#fe8019".into(), "#b16286".into(),
"#b8bb26".into(), "#fe8019".into(),
]), "#b8bb26".into(),
rx_color: Some("#427b58".into()), ]),
tx_color: Some("#cc241d".into()), rx_color: Some("#427b58".into()),
rx_total_color: Some("#689d6a".into()), tx_color: Some("#cc241d".into()),
tx_total_color: Some("#9d0006".into()), rx_total_color: Some("#689d6a".into()),
border_color: Some("#3c3836".into()), tx_total_color: Some("#9d0006".into()),
highlighted_border_color: Some("#af3a03".into()), border_color: Some("#3c3836".into()),
disabled_text_color: Some("#d5c4a1".into()), highlighted_border_color: Some("#af3a03".into()),
text_color: Some("#3c3836".into()), disabled_text_color: Some("#d5c4a1".into()),
selected_text_color: Some("#ebdbb2".into()), text_color: Some("#3c3836".into()),
selected_bg_color: Some("#3c3836".into()), selected_text_color: Some("#ebdbb2".into()),
widget_title_color: Some("#3c3836".into()), selected_bg_color: Some("#3c3836".into()),
graph_color: Some("#3c3836".into()), widget_title_color: Some("#3c3836".into()),
high_battery_color: Some("#98971a".into()), graph_color: Some("#3c3836".into()),
medium_battery_color: Some("#d79921".into()), high_battery_color: Some("#98971a".into()),
low_battery_color: Some("#cc241d".into()), medium_battery_color: Some("#d79921".into()),
}); low_battery_color: Some("#cc241d".into()),
}
}
pub static NORD_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours { pub fn nord_colour_palette() -> ConfigColours {
table_header_color: Some("#81a1c1".into()), ConfigColours {
all_cpu_color: Some("#88c0d0".into()), table_header_color: Some("#81a1c1".into()),
avg_cpu_color: Some("#8fbcbb".into()), all_cpu_color: Some("#88c0d0".into()),
cpu_core_colors: Some(vec![ avg_cpu_color: Some("#8fbcbb".into()),
"#5e81ac".into(), cpu_core_colors: Some(vec![
"#81a1c1".into(), "#5e81ac".into(),
"#d8dee9".into(), "#81a1c1".into(),
"#b48ead".into(), "#d8dee9".into(),
"#a3be8c".into(), "#b48ead".into(),
"#ebcb8b".into(), "#a3be8c".into(),
"#d08770".into(), "#ebcb8b".into(),
"#bf616a".into(), "#d08770".into(),
]), "#bf616a".into(),
ram_color: Some("#88c0d0".into()), ]),
#[cfg(not(target_os = "windows"))] ram_color: Some("#88c0d0".into()),
cache_color: Some("#d8dee9".into()), #[cfg(not(target_os = "windows"))]
swap_color: Some("#d08770".into()), cache_color: Some("#d8dee9".into()),
arc_color: Some("#5e81ac".into()), swap_color: Some("#d08770".into()),
gpu_core_colors: Some(vec![ arc_color: Some("#5e81ac".into()),
"#8fbcbb".into(), gpu_core_colors: Some(vec![
"#81a1c1".into(), "#8fbcbb".into(),
"#d8dee9".into(), "#81a1c1".into(),
"#b48ead".into(), "#d8dee9".into(),
"#a3be8c".into(), "#b48ead".into(),
"#ebcb8b".into(), "#a3be8c".into(),
"#bf616a".into(), "#ebcb8b".into(),
]), "#bf616a".into(),
rx_color: Some("#88c0d0".into()), ]),
tx_color: Some("#d08770".into()), rx_color: Some("#88c0d0".into()),
rx_total_color: Some("#5e81ac".into()), tx_color: Some("#d08770".into()),
tx_total_color: Some("#8fbcbb".into()), rx_total_color: Some("#5e81ac".into()),
border_color: Some("#88c0d0".into()), tx_total_color: Some("#8fbcbb".into()),
highlighted_border_color: Some("#5e81ac".into()), border_color: Some("#88c0d0".into()),
disabled_text_color: Some("#4c566a".into()), highlighted_border_color: Some("#5e81ac".into()),
text_color: Some("#e5e9f0".into()), disabled_text_color: Some("#4c566a".into()),
selected_text_color: Some("#2e3440".into()), text_color: Some("#e5e9f0".into()),
selected_bg_color: Some("#88c0d0".into()), selected_text_color: Some("#2e3440".into()),
widget_title_color: Some("#e5e9f0".into()), selected_bg_color: Some("#88c0d0".into()),
graph_color: Some("#e5e9f0".into()), widget_title_color: Some("#e5e9f0".into()),
high_battery_color: Some("#a3be8c".into()), graph_color: Some("#e5e9f0".into()),
medium_battery_color: Some("#ebcb8b".into()), high_battery_color: Some("#a3be8c".into()),
low_battery_color: Some("#bf616a".into()), medium_battery_color: Some("#ebcb8b".into()),
}); low_battery_color: Some("#bf616a".into()),
}
}
pub static NORD_LIGHT_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours { pub fn nord_light_colour_palette() -> ConfigColours {
table_header_color: Some("#5e81ac".into()), ConfigColours {
all_cpu_color: Some("#81a1c1".into()), table_header_color: Some("#5e81ac".into()),
avg_cpu_color: Some("#8fbcbb".into()), all_cpu_color: Some("#81a1c1".into()),
cpu_core_colors: Some(vec![ avg_cpu_color: Some("#8fbcbb".into()),
"#5e81ac".into(), cpu_core_colors: Some(vec![
"#88c0d0".into(), "#5e81ac".into(),
"#4c566a".into(), "#88c0d0".into(),
"#b48ead".into(), "#4c566a".into(),
"#a3be8c".into(), "#b48ead".into(),
"#ebcb8b".into(), "#a3be8c".into(),
"#d08770".into(), "#ebcb8b".into(),
"#bf616a".into(), "#d08770".into(),
]), "#bf616a".into(),
ram_color: Some("#81a1c1".into()), ]),
#[cfg(not(target_os = "windows"))] ram_color: Some("#81a1c1".into()),
cache_color: Some("#4c566a".into()), #[cfg(not(target_os = "windows"))]
swap_color: Some("#d08770".into()), cache_color: Some("#4c566a".into()),
arc_color: Some("#5e81ac".into()), swap_color: Some("#d08770".into()),
gpu_core_colors: Some(vec![ arc_color: Some("#5e81ac".into()),
"#8fbcbb".into(), gpu_core_colors: Some(vec![
"#88c0d0".into(), "#8fbcbb".into(),
"#4c566a".into(), "#88c0d0".into(),
"#b48ead".into(), "#4c566a".into(),
"#a3be8c".into(), "#b48ead".into(),
"#ebcb8b".into(), "#a3be8c".into(),
"#bf616a".into(), "#ebcb8b".into(),
]), "#bf616a".into(),
rx_color: Some("#81a1c1".into()), ]),
tx_color: Some("#d08770".into()), rx_color: Some("#81a1c1".into()),
rx_total_color: Some("#5e81ac".into()), tx_color: Some("#d08770".into()),
tx_total_color: Some("#8fbcbb".into()), rx_total_color: Some("#5e81ac".into()),
border_color: Some("#2e3440".into()), tx_total_color: Some("#8fbcbb".into()),
highlighted_border_color: Some("#5e81ac".into()), border_color: Some("#2e3440".into()),
disabled_text_color: Some("#d8dee9".into()), highlighted_border_color: Some("#5e81ac".into()),
text_color: Some("#2e3440".into()), disabled_text_color: Some("#d8dee9".into()),
selected_text_color: Some("#f5f5f5".into()), text_color: Some("#2e3440".into()),
selected_bg_color: Some("#5e81ac".into()), selected_text_color: Some("#f5f5f5".into()),
widget_title_color: Some("#2e3440".into()), selected_bg_color: Some("#5e81ac".into()),
graph_color: Some("#2e3440".into()), widget_title_color: Some("#2e3440".into()),
high_battery_color: Some("#a3be8c".into()), graph_color: Some("#2e3440".into()),
medium_battery_color: Some("#ebcb8b".into()), high_battery_color: Some("#a3be8c".into()),
low_battery_color: Some("#bf616a".into()), medium_battery_color: Some("#ebcb8b".into()),
}); low_battery_color: Some("#bf616a".into()),
}
}
// Help text // Help text
pub const HELP_CONTENTS_TEXT: [&str; 10] = [ pub const HELP_CONTENTS_TEXT: [&str; 10] = [

View file

@ -1,22 +1,8 @@
#[cfg(feature = "logging")] #[cfg(feature = "logging")]
pub static OFFSET: once_cell::sync::Lazy<time::UtcOffset> = once_cell::sync::Lazy::new(|| { use std::sync::OnceLock;
use time::util::local_offset::Soundness;
// SAFETY: We only invoke this once, quickly, and it should be invoked in a single-thread context. #[cfg(feature = "logging")]
// We also should only ever hit this logging at all in a debug context which is generally fine, pub static OFFSET: OnceLock<time::UtcOffset> = OnceLock::new();
// release builds should have this logging disabled entirely for now.
unsafe {
// XXX: If we ever DO add general logging as a release feature, evaluate this again and whether this is
// something we want enabled in release builds! What might be safe is falling back to the non-set-soundness
// mode when specifically using certain feature flags (e.g. dev-logging feature enables this behaviour).
time::util::local_offset::set_soundness(Soundness::Unsound);
let res = time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC);
time::util::local_offset::set_soundness(Soundness::Sound);
res
}
});
#[cfg(feature = "logging")] #[cfg(feature = "logging")]
pub fn init_logger( pub fn init_logger(
@ -24,9 +10,29 @@ pub fn init_logger(
) -> Result<(), fern::InitError> { ) -> Result<(), fern::InitError> {
let dispatch = fern::Dispatch::new() let dispatch = fern::Dispatch::new()
.format(|out, message, record| { .format(|out, message, record| {
let offset = OFFSET.get_or_init(|| {
use time::util::local_offset::Soundness;
// SAFETY: We only invoke this once, quickly, and it should be invoked in a single-thread context.
// We also should only ever hit this logging at all in a debug context which is generally fine,
// release builds should have this logging disabled entirely for now.
unsafe {
// XXX: If we ever DO add general logging as a release feature, evaluate this again and whether this is
// something we want enabled in release builds! What might be safe is falling back to the non-set-soundness
// mode when specifically using certain feature flags (e.g. dev-logging feature enables this behaviour).
time::util::local_offset::set_soundness(Soundness::Unsound);
let res =
time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC);
time::util::local_offset::set_soundness(Soundness::Sound);
res
}
});
let offset_time = { let offset_time = {
let utc = time::OffsetDateTime::now_utc(); let utc = time::OffsetDateTime::now_utc();
utc.checked_to_offset(*OFFSET).unwrap_or(utc) utc.checked_to_offset(*offset).unwrap_or(utc)
}; };
out.finish(format_args!( out.finish(format_args!(