mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-14 17:12:58 +02:00
refactor(bar): inline defaults in schemars attrs
This commit is contained in:
+10
-22
@@ -13,24 +13,12 @@ use serde::Serialize;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod defaults {
|
|
||||||
pub const HEIGHT: f32 = 50.0;
|
|
||||||
pub const FONT_SIZE: f32 = 12.5;
|
|
||||||
pub const ICON_SCALE: f32 = 1.4;
|
|
||||||
pub const MAX_LABEL_WIDTH: f32 = 400.0;
|
|
||||||
pub const TRANSPARENCY_ALPHA: u8 = 200;
|
|
||||||
pub const WIDGET_SPACING: f32 = 10.0;
|
|
||||||
pub const SCROLL_THRESHOLD: f32 = 30.0;
|
|
||||||
pub const FOCUS_MONITOR_AT_CURSOR: bool = true;
|
|
||||||
pub const IGNORE_MOUSE_FOLLOWS_FOCUS: bool = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
/// The `komorebi.bar.json` configuration file reference for `v0.1.40`
|
/// The `komorebi.bar.json` configuration file reference for `v0.1.40`
|
||||||
pub struct KomobarConfig {
|
pub struct KomobarConfig {
|
||||||
/// Bar height
|
/// Bar height
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::HEIGHT)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 50)))]
|
||||||
pub height: Option<f32>,
|
pub height: Option<f32>,
|
||||||
/// Bar padding. Use one value for all sides or use a grouped padding for horizontal and/or
|
/// Bar padding. Use one value for all sides or use a grouped padding for horizontal and/or
|
||||||
/// vertical definition which can each take a single value for a symmetric padding or two
|
/// vertical definition which can each take a single value for a symmetric padding or two
|
||||||
@@ -92,21 +80,21 @@ pub struct KomobarConfig {
|
|||||||
/// Font family
|
/// Font family
|
||||||
pub font_family: Option<String>,
|
pub font_family: Option<String>,
|
||||||
/// Font size
|
/// Font size
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::FONT_SIZE)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 12.5)))]
|
||||||
pub font_size: Option<f32>,
|
pub font_size: Option<f32>,
|
||||||
/// Scale of the icons relative to the font_size [[1.0-2.0]]
|
/// Scale of the icons relative to the font_size [[1.0-2.0]]
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::ICON_SCALE)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 1.4)))]
|
||||||
pub icon_scale: Option<f32>,
|
pub icon_scale: Option<f32>,
|
||||||
/// Max label width before text truncation
|
/// Max label width before text truncation
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::MAX_LABEL_WIDTH)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 400.0)))]
|
||||||
pub max_label_width: Option<f32>,
|
pub max_label_width: Option<f32>,
|
||||||
/// Theme
|
/// Theme
|
||||||
pub theme: Option<KomobarTheme>,
|
pub theme: Option<KomobarTheme>,
|
||||||
/// Alpha value for the color transparency [[0-255]]
|
/// Alpha value for the color transparency [[0-255]]
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::TRANSPARENCY_ALPHA)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 200)))]
|
||||||
pub transparency_alpha: Option<u8>,
|
pub transparency_alpha: Option<u8>,
|
||||||
/// Spacing between widgets
|
/// Spacing between widgets
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::WIDGET_SPACING)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10.0)))]
|
||||||
pub widget_spacing: Option<f32>,
|
pub widget_spacing: Option<f32>,
|
||||||
/// Visual grouping for widgets
|
/// Visual grouping for widgets
|
||||||
pub grouping: Option<Grouping>,
|
pub grouping: Option<Grouping>,
|
||||||
@@ -419,10 +407,10 @@ pub enum MouseMessage {
|
|||||||
/// Komorebi socket mouse message
|
/// Komorebi socket mouse message
|
||||||
pub struct KomorebiMouseMessage {
|
pub struct KomorebiMouseMessage {
|
||||||
/// Send the FocusMonitorAtCursor message
|
/// Send the FocusMonitorAtCursor message
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::FOCUS_MONITOR_AT_CURSOR)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = true)))]
|
||||||
pub focus_monitor_at_cursor: Option<bool>,
|
pub focus_monitor_at_cursor: Option<bool>,
|
||||||
/// Wrap the {message} with a MouseFollowsFocus(false) and MouseFollowsFocus({original.value}) message
|
/// Wrap the {message} with a MouseFollowsFocus(false) and MouseFollowsFocus({original.value}) message
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::IGNORE_MOUSE_FOLLOWS_FOCUS)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = true)))]
|
||||||
pub ignore_mouse_follows_focus: Option<bool>,
|
pub ignore_mouse_follows_focus: Option<bool>,
|
||||||
/// The message to send to the komorebi client
|
/// The message to send to the komorebi client
|
||||||
pub message: komorebi_client::SocketMessage,
|
pub message: komorebi_client::SocketMessage,
|
||||||
@@ -444,7 +432,7 @@ pub struct MouseConfig {
|
|||||||
pub on_extra2_click: Option<MouseMessage>,
|
pub on_extra2_click: Option<MouseMessage>,
|
||||||
|
|
||||||
/// Defines how many points a user needs to scroll vertically to make a "tick" on a mouse/touchpad/touchscreen
|
/// Defines how many points a user needs to scroll vertically to make a "tick" on a mouse/touchpad/touchscreen
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::SCROLL_THRESHOLD)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 30.0)))]
|
||||||
pub vertical_scroll_threshold: Option<f32>,
|
pub vertical_scroll_threshold: Option<f32>,
|
||||||
/// Command to send on scrolling up (every tick)
|
/// Command to send on scrolling up (every tick)
|
||||||
pub on_scroll_up: Option<MouseMessage>,
|
pub on_scroll_up: Option<MouseMessage>,
|
||||||
@@ -452,7 +440,7 @@ pub struct MouseConfig {
|
|||||||
pub on_scroll_down: Option<MouseMessage>,
|
pub on_scroll_down: Option<MouseMessage>,
|
||||||
|
|
||||||
/// Defines how many points a user needs to scroll horizontally to make a "tick" on a mouse/touchpad/touchscreen
|
/// Defines how many points a user needs to scroll horizontally to make a "tick" on a mouse/touchpad/touchscreen
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::SCROLL_THRESHOLD)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 30.0)))]
|
||||||
pub horizontal_scroll_threshold: Option<f32>,
|
pub horizontal_scroll_threshold: Option<f32>,
|
||||||
/// Command to send on scrolling left (every tick)
|
/// Command to send on scrolling left (every tick)
|
||||||
pub on_scroll_left: Option<MouseMessage>,
|
pub on_scroll_left: Option<MouseMessage>,
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ use std::process::Command;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
mod defaults {
|
|
||||||
pub const DATA_REFRESH_INTERVAL: u64 = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
/// Battery widget configuration
|
/// Battery widget configuration
|
||||||
@@ -30,7 +26,7 @@ pub struct BatteryConfig {
|
|||||||
/// Hide the widget if the battery is at full charge
|
/// Hide the widget if the battery is at full charge
|
||||||
pub hide_on_full_charge: Option<bool>,
|
pub hide_on_full_charge: Option<bool>,
|
||||||
/// Data refresh interval in seconds
|
/// Data refresh interval in seconds
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
/// Display label prefix
|
/// Display label prefix
|
||||||
pub label_prefix: Option<LabelPrefix>,
|
pub label_prefix: Option<LabelPrefix>,
|
||||||
@@ -40,9 +36,7 @@ pub struct BatteryConfig {
|
|||||||
|
|
||||||
impl From<BatteryConfig> for Battery {
|
impl From<BatteryConfig> for Battery {
|
||||||
fn from(value: BatteryConfig) -> Self {
|
fn from(value: BatteryConfig) -> Self {
|
||||||
let data_refresh_interval = value
|
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
|
||||||
.data_refresh_interval
|
|
||||||
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
enable: value.enable,
|
enable: value.enable,
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ use std::time::Instant;
|
|||||||
use sysinfo::RefreshKind;
|
use sysinfo::RefreshKind;
|
||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
|
|
||||||
mod defaults {
|
|
||||||
pub const DATA_REFRESH_INTERVAL: u64 = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
/// CPU widget configuration
|
/// CPU widget configuration
|
||||||
@@ -27,7 +23,7 @@ pub struct CpuConfig {
|
|||||||
/// Enable the Cpu widget
|
/// Enable the Cpu widget
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
/// Data refresh interval in seconds
|
/// Data refresh interval in seconds
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
/// Display label prefix
|
/// Display label prefix
|
||||||
pub label_prefix: Option<LabelPrefix>,
|
pub label_prefix: Option<LabelPrefix>,
|
||||||
@@ -37,9 +33,7 @@ pub struct CpuConfig {
|
|||||||
|
|
||||||
impl From<CpuConfig> for Cpu {
|
impl From<CpuConfig> for Cpu {
|
||||||
fn from(value: CpuConfig) -> Self {
|
fn from(value: CpuConfig) -> Self {
|
||||||
let data_refresh_interval = value
|
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
|
||||||
.data_refresh_interval
|
|
||||||
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
enable: value.enable,
|
enable: value.enable,
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ use windows::Win32::UI::Input::KeyboardAndMouse::GetKeyboardLayout;
|
|||||||
use windows::Win32::UI::WindowsAndMessaging::GetForegroundWindow;
|
use windows::Win32::UI::WindowsAndMessaging::GetForegroundWindow;
|
||||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
|
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
|
||||||
|
|
||||||
mod defaults {
|
const ERROR_TEXT: &str = "Error";
|
||||||
pub const DATA_REFRESH_INTERVAL: u64 = 10;
|
|
||||||
pub const ERROR_TEXT: &str = "Error";
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
@@ -33,7 +30,7 @@ pub struct KeyboardConfig {
|
|||||||
/// Enable the Input widget
|
/// Enable the Input widget
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
/// Data refresh interval
|
/// Data refresh interval
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
/// Display label prefix
|
/// Display label prefix
|
||||||
pub label_prefix: Option<LabelPrefix>,
|
pub label_prefix: Option<LabelPrefix>,
|
||||||
@@ -41,9 +38,7 @@ pub struct KeyboardConfig {
|
|||||||
|
|
||||||
impl From<KeyboardConfig> for Keyboard {
|
impl From<KeyboardConfig> for Keyboard {
|
||||||
fn from(value: KeyboardConfig) -> Self {
|
fn from(value: KeyboardConfig) -> Self {
|
||||||
let data_refresh_interval = value
|
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
|
||||||
.data_refresh_interval
|
|
||||||
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
enable: value.enable,
|
enable: value.enable,
|
||||||
@@ -128,7 +123,7 @@ fn get_active_keyboard_layout() -> eyre::Result<String, ()> {
|
|||||||
fn get_lang() -> String {
|
fn get_lang() -> String {
|
||||||
get_active_keyboard_layout()
|
get_active_keyboard_layout()
|
||||||
.map(|l| l.trim_end_matches('\0').to_string())
|
.map(|l| l.trim_end_matches('\0').to_string())
|
||||||
.unwrap_or_else(|_| defaults::ERROR_TEXT.to_string())
|
.unwrap_or_else(|_| ERROR_TEXT.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keyboard {
|
impl Keyboard {
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ use std::time::Instant;
|
|||||||
use sysinfo::RefreshKind;
|
use sysinfo::RefreshKind;
|
||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
|
|
||||||
mod defaults {
|
|
||||||
pub const DATA_REFRESH_INTERVAL: u64 = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
/// Memory widget configuration
|
/// Memory widget configuration
|
||||||
@@ -27,7 +23,7 @@ pub struct MemoryConfig {
|
|||||||
/// Enable the Memory widget
|
/// Enable the Memory widget
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
/// Data refresh interval in seconds
|
/// Data refresh interval in seconds
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
/// Display label prefix
|
/// Display label prefix
|
||||||
pub label_prefix: Option<LabelPrefix>,
|
pub label_prefix: Option<LabelPrefix>,
|
||||||
@@ -37,9 +33,7 @@ pub struct MemoryConfig {
|
|||||||
|
|
||||||
impl From<MemoryConfig> for Memory {
|
impl From<MemoryConfig> for Memory {
|
||||||
fn from(value: MemoryConfig) -> Self {
|
fn from(value: MemoryConfig) -> Self {
|
||||||
let data_refresh_interval = value
|
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
|
||||||
.data_refresh_interval
|
|
||||||
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
enable: value.enable,
|
enable: value.enable,
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ use std::time::Duration;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use sysinfo::Networks;
|
use sysinfo::Networks;
|
||||||
|
|
||||||
mod defaults {
|
|
||||||
pub const DATA_REFRESH_INTERVAL: u64 = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
/// Network widget configuration
|
/// Network widget configuration
|
||||||
@@ -46,7 +42,7 @@ pub struct NetworkConfig {
|
|||||||
#[serde(alias = "network_activity_fill_characters")]
|
#[serde(alias = "network_activity_fill_characters")]
|
||||||
pub activity_left_padding: Option<usize>,
|
pub activity_left_padding: Option<usize>,
|
||||||
/// Data refresh interval in seconds
|
/// Data refresh interval in seconds
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
/// Display label prefix
|
/// Display label prefix
|
||||||
pub label_prefix: Option<LabelPrefix>,
|
pub label_prefix: Option<LabelPrefix>,
|
||||||
@@ -73,7 +69,7 @@ impl From<NetworkConfig> for Network {
|
|||||||
let default_refresh_interval = 10;
|
let default_refresh_interval = 10;
|
||||||
let data_refresh_interval = value
|
let data_refresh_interval = value
|
||||||
.data_refresh_interval
|
.data_refresh_interval
|
||||||
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
|
.unwrap_or(default_refresh_interval);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
enable: value.enable,
|
enable: value.enable,
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ use std::time::Duration;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use sysinfo::Disks;
|
use sysinfo::Disks;
|
||||||
|
|
||||||
mod defaults {
|
|
||||||
pub const DATA_REFRESH_INTERVAL: u64 = 10;
|
|
||||||
pub const SHOW_READ_ONLY_DISKS: bool = false;
|
|
||||||
pub const SHOW_REMOVABLE_DISKS: bool = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
/// Storage widget configuration
|
/// Storage widget configuration
|
||||||
@@ -29,15 +23,15 @@ pub struct StorageConfig {
|
|||||||
/// Enable the Storage widget
|
/// Enable the Storage widget
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
/// Data refresh interval in seconds
|
/// Data refresh interval in seconds
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
/// Display label prefix
|
/// Display label prefix
|
||||||
pub label_prefix: Option<LabelPrefix>,
|
pub label_prefix: Option<LabelPrefix>,
|
||||||
/// Show disks that are read only
|
/// Show disks that are read only
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::SHOW_READ_ONLY_DISKS)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = false)))]
|
||||||
pub show_read_only_disks: Option<bool>,
|
pub show_read_only_disks: Option<bool>,
|
||||||
/// Show removable disks
|
/// Show removable disks
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::SHOW_REMOVABLE_DISKS)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = true)))]
|
||||||
pub show_removable_disks: Option<bool>,
|
pub show_removable_disks: Option<bool>,
|
||||||
/// Select when the current percentage is over this value [[1-100]]
|
/// Select when the current percentage is over this value [[1-100]]
|
||||||
pub auto_select_over: Option<u8>,
|
pub auto_select_over: Option<u8>,
|
||||||
@@ -50,16 +44,10 @@ impl From<StorageConfig> for Storage {
|
|||||||
Self {
|
Self {
|
||||||
enable: value.enable,
|
enable: value.enable,
|
||||||
disks: Disks::new_with_refreshed_list(),
|
disks: Disks::new_with_refreshed_list(),
|
||||||
data_refresh_interval: value
|
data_refresh_interval: value.data_refresh_interval.unwrap_or(10),
|
||||||
.data_refresh_interval
|
|
||||||
.unwrap_or(defaults::DATA_REFRESH_INTERVAL),
|
|
||||||
label_prefix: value.label_prefix.unwrap_or(LabelPrefix::IconAndText),
|
label_prefix: value.label_prefix.unwrap_or(LabelPrefix::IconAndText),
|
||||||
show_read_only_disks: value
|
show_read_only_disks: value.show_read_only_disks.unwrap_or(false),
|
||||||
.show_read_only_disks
|
show_removable_disks: value.show_removable_disks.unwrap_or(true),
|
||||||
.unwrap_or(defaults::SHOW_READ_ONLY_DISKS),
|
|
||||||
show_removable_disks: value
|
|
||||||
.show_removable_disks
|
|
||||||
.unwrap_or(defaults::SHOW_REMOVABLE_DISKS),
|
|
||||||
auto_select_over: value.auto_select_over.map(|o| o.clamp(1, 100)),
|
auto_select_over: value.auto_select_over.map(|o| o.clamp(1, 100)),
|
||||||
auto_hide_under: value.auto_hide_under.map(|o| o.clamp(1, 100)),
|
auto_hide_under: value.auto_hide_under.map(|o| o.clamp(1, 100)),
|
||||||
last_updated: Instant::now(),
|
last_updated: Instant::now(),
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ use std::process::Command;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
mod defaults {
|
|
||||||
pub const DATA_REFRESH_INTERVAL: u64 = 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
/// Update widget configuration
|
/// Update widget configuration
|
||||||
@@ -25,7 +21,7 @@ pub struct UpdateConfig {
|
|||||||
/// Enable the Update widget
|
/// Enable the Update widget
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
/// Data refresh interval in hours
|
/// Data refresh interval in hours
|
||||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
|
#[cfg_attr(feature = "schemars", schemars(extend("default" = 12)))]
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
/// Display label prefix
|
/// Display label prefix
|
||||||
pub label_prefix: Option<LabelPrefix>,
|
pub label_prefix: Option<LabelPrefix>,
|
||||||
@@ -33,9 +29,7 @@ pub struct UpdateConfig {
|
|||||||
|
|
||||||
impl From<UpdateConfig> for Update {
|
impl From<UpdateConfig> for Update {
|
||||||
fn from(value: UpdateConfig) -> Self {
|
fn from(value: UpdateConfig) -> Self {
|
||||||
let data_refresh_interval = value
|
let data_refresh_interval = value.data_refresh_interval.unwrap_or(12);
|
||||||
.data_refresh_interval
|
|
||||||
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
|
|
||||||
|
|
||||||
let mut latest_version = String::new();
|
let mut latest_version = String::new();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user