diff --git a/client/src/main.rs b/client/src/main.rs index 66cef48..5d4ea94 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -28,6 +28,7 @@ struct Centerpiece { query: String, active_entry_index: usize, plugins: Vec, + settings: settings::Settings, } pub const SCROLLABLE_ID: &str = "scrollable"; @@ -52,6 +53,7 @@ impl Application for Centerpiece { query: String::from(""), active_entry_index: 0, plugins: vec![], + settings: settings::Settings::new(), }, iced::Command::perform(async {}, move |()| Message::Loaded), ) @@ -108,8 +110,8 @@ impl Application for Centerpiece { } fn subscription(&self) -> iced::Subscription { - iced::subscription::Subscription::batch(vec![ - iced::subscription::events_with(|event, _status| match event { + let mut subscriptions = vec![iced::subscription::events_with( + |event, _status| match event { iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { modifiers: _, key_code: _, @@ -122,24 +124,86 @@ impl Application for Centerpiece { Some(Message::Event(event)) } _ => None, - }), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::< + }, + )]; + + if self.settings.plugin.applications.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::applications::ApplicationsPlugin, + >()); + } + + if self.settings.plugin.brave_bookmarks.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::brave::bookmarks::BookmarksPlugin, + >()); + } + + if self.settings.plugin.brave_progressive_web_apps.enable { + subscriptions.push(crate::plugin::utils::spawn::< crate::plugin::brave::progressive_web_apps::ProgressiveWebAppsPlugin, - >(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::( - ), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - crate::plugin::utils::spawn::(), - ]) + >()); + } + + if self.settings.plugin.brave_history.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::brave::history::HistoryPlugin, + >()); + } + + if self.settings.plugin.clock.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::clock::ClockPlugin, + >()); + } + + if self.settings.plugin.git_repositories.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::git_repositories::GitRepositoriesPlugin, + >()); + } + + if self.settings.plugin.resource_monitor_battery.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::battery::BatteryPlugin, + >()); + } + + if self.settings.plugin.resource_monitor_cpu.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::cpu::CpuPlugin, + >()); + } + + if self.settings.plugin.resource_monitor_disks.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::disks::DisksPlugin, + >()); + } + + if self.settings.plugin.resource_monitor_memory.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::memory::MemoryPlugin, + >()); + } + + if self.settings.plugin.system.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::system::SystemPlugin, + >()); + } + + if self.settings.plugin.wifi.enable { + subscriptions.push(crate::plugin::utils::spawn::()); + } + + if self.settings.plugin.windows.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::windows::WindowsPlugin, + >()); + } + + iced::subscription::Subscription::batch(subscriptions) } fn view(&self) -> iced::Element { diff --git a/client/src/plugin/brave/bookmarks.rs b/client/src/plugin/brave/bookmarks.rs index ca46d28..fc4f376 100644 --- a/client/src/plugin/brave/bookmarks.rs +++ b/client/src/plugin/brave/bookmarks.rs @@ -7,7 +7,7 @@ pub struct BookmarksPlugin { impl Plugin for BookmarksPlugin { fn id() -> &'static str { - "brave-bookmarks" + "brave_bookmarks" } fn priority() -> u32 { diff --git a/client/src/plugin/brave/history.rs b/client/src/plugin/brave/history.rs index 6f99b4a..2815aa7 100644 --- a/client/src/plugin/brave/history.rs +++ b/client/src/plugin/brave/history.rs @@ -7,7 +7,7 @@ pub struct HistoryPlugin { impl Plugin for HistoryPlugin { fn id() -> &'static str { - "brave-history" + "brave_history" } fn priority() -> u32 { diff --git a/client/src/plugin/brave/progressive_web_apps.rs b/client/src/plugin/brave/progressive_web_apps.rs index 771b7fe..b1c1ad9 100644 --- a/client/src/plugin/brave/progressive_web_apps.rs +++ b/client/src/plugin/brave/progressive_web_apps.rs @@ -7,7 +7,7 @@ pub struct ProgressiveWebAppsPlugin { impl Plugin for ProgressiveWebAppsPlugin { fn id() -> &'static str { - "brave-progressive-web-apps" + "brave_progressive_web_apps" } fn priority() -> u32 { diff --git a/client/src/plugin/git_repositories.rs b/client/src/plugin/git_repositories.rs index c3eb5c2..efd4096 100644 --- a/client/src/plugin/git_repositories.rs +++ b/client/src/plugin/git_repositories.rs @@ -1,9 +1,9 @@ -use crate::{plugin::utils::Plugin, settings::Settings}; +use crate::plugin::utils::Plugin; use anyhow::Context; pub struct GitRepositoriesPlugin { entries: Vec, - settings: Settings, + settings: crate::settings::Settings, } impl Plugin for GitRepositoriesPlugin { @@ -26,7 +26,7 @@ impl Plugin for GitRepositoriesPlugin { fn new() -> Self { Self { entries: vec![], - settings: Settings::new(), + settings: crate::settings::Settings::new(), } } diff --git a/client/src/plugin/resource_monitor/battery.rs b/client/src/plugin/resource_monitor/battery.rs index 12c3c10..1c4b5ef 100644 --- a/client/src/plugin/resource_monitor/battery.rs +++ b/client/src/plugin/resource_monitor/battery.rs @@ -8,7 +8,7 @@ pub struct BatteryPlugin { impl Plugin for BatteryPlugin { fn id() -> &'static str { - "battery" + "resource_monitor_battery" } fn priority() -> u32 { diff --git a/client/src/plugin/resource_monitor/cpu.rs b/client/src/plugin/resource_monitor/cpu.rs index 607e82f..f76fde8 100644 --- a/client/src/plugin/resource_monitor/cpu.rs +++ b/client/src/plugin/resource_monitor/cpu.rs @@ -7,7 +7,7 @@ pub struct CpuPlugin { impl Plugin for CpuPlugin { fn id() -> &'static str { - "cpu" + "resource_monitor_cpu" } fn priority() -> u32 { diff --git a/client/src/plugin/resource_monitor/disks.rs b/client/src/plugin/resource_monitor/disks.rs index 0d0fd02..e33317a 100644 --- a/client/src/plugin/resource_monitor/disks.rs +++ b/client/src/plugin/resource_monitor/disks.rs @@ -8,7 +8,7 @@ pub struct DisksPlugin { impl Plugin for DisksPlugin { fn id() -> &'static str { - "disks" + "resource_monitor_disks" } fn priority() -> u32 { diff --git a/client/src/plugin/resource_monitor/memory.rs b/client/src/plugin/resource_monitor/memory.rs index 793db15..34d1a1e 100644 --- a/client/src/plugin/resource_monitor/memory.rs +++ b/client/src/plugin/resource_monitor/memory.rs @@ -7,7 +7,7 @@ pub struct MemoryPlugin { impl Plugin for MemoryPlugin { fn id() -> &'static str { - "memory" + "resource_monitor_memory" } fn priority() -> u32 { diff --git a/client/src/settings.rs b/client/src/settings.rs index 9f4d97e..c151b04 100644 --- a/client/src/settings.rs +++ b/client/src/settings.rs @@ -1,34 +1,214 @@ use serde::Deserialize; +fn default_true() -> bool { + true +} + +#[derive(Debug, Deserialize)] +pub struct ApplicationsPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for ApplicationsPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct BraveBookmarksPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for BraveBookmarksPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct BraveHistoryPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for BraveHistoryPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct BraveProgressiveWebAppsSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for BraveProgressiveWebAppsSettings { + fn default() -> Self { + Self { enable: true } + } +} + #[derive(Debug, Deserialize)] -pub struct GitRepositoriesSettings { +pub struct ClockPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for ClockPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct GitRepositoriesPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, + #[serde(default = "default_commands")] pub commands: Vec>, } -impl Default for GitRepositoriesSettings { +fn default_commands() -> Vec> { + vec![ + vec![ + "alacritty".into(), + "--command".into(), + "nvim".into(), + "$GIT_DIRECTORY".into(), + ], + vec![ + "alacritty".into(), + "--working-directory".into(), + "$GIT_DIRECTORY".into(), + ], + ] +} + +impl Default for GitRepositoriesPluginSettings { fn default() -> Self { Self { - commands: vec![ - vec![ - "alacritty".into(), - "--command".into(), - "nvim".into(), - "$GIT_DIRECTORY".into(), - ], - vec![ - "alacritty".into(), - "--working-directory".into(), - "$GIT_DIRECTORY".into(), - ], - ], + enable: true, + commands: default_commands(), } } } +#[derive(Debug, Deserialize)] +pub struct ResourceMonitorBatteryPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for ResourceMonitorBatteryPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct ResourceMonitorCpuPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for ResourceMonitorCpuPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct ResourceMonitorDisksSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for ResourceMonitorDisksSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct ResourceMonitorMemoryPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for ResourceMonitorMemoryPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct SystemPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for SystemPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct WifiPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for WifiPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + +#[derive(Debug, Deserialize)] +pub struct WindowsPluginSettings { + #[serde(default = "default_true")] + pub enable: bool, +} + +impl Default for WindowsPluginSettings { + fn default() -> Self { + Self { enable: true } + } +} + #[derive(Debug, Default, Deserialize)] pub struct PluginSettings { #[serde(default)] - pub git_repositories: GitRepositoriesSettings, + pub applications: ApplicationsPluginSettings, + #[serde(default)] + pub brave_bookmarks: BraveBookmarksPluginSettings, + #[serde(default)] + pub brave_history: BraveHistoryPluginSettings, + #[serde(default)] + pub brave_progressive_web_apps: BraveProgressiveWebAppsSettings, + #[serde(default)] + pub clock: ClockPluginSettings, + #[serde(default)] + pub git_repositories: GitRepositoriesPluginSettings, + #[serde(default)] + pub resource_monitor_battery: ResourceMonitorBatteryPluginSettings, + #[serde(default)] + pub resource_monitor_cpu: ResourceMonitorCpuPluginSettings, + #[serde(default)] + pub resource_monitor_disks: ResourceMonitorDisksSettings, + #[serde(default)] + pub resource_monitor_memory: ResourceMonitorMemoryPluginSettings, + #[serde(default)] + pub system: SystemPluginSettings, + #[serde(default)] + pub wifi: WifiPluginSettings, + #[serde(default)] + pub windows: WindowsPluginSettings, } #[derive(Debug, Default, Deserialize)] diff --git a/config.yml b/config.yml index 405ae33..0fba588 100644 --- a/config.yml +++ b/config.yml @@ -1,5 +1,30 @@ plugin: + applications: + enable: true + brave_bookmarks: + enable: true + brave_history: + enable: true + brave_progressive_web_apps: + enable: true + clock: + enable: true git_repositories: + enable: true commands: - ["alacritty", "--command", "nvim", "$GIT_DIRECTORY"] - ["alacritty", "--working-directory", "$GIT_DIRECTORY"] + resource_monitor_battery: + enable: true + resource_monitor_cpu: + enable: true + resource_monitor_disks: + enable: true + resource_monitor_memory: + enable: true + system: + enable: true + wifi: + enable: true + windows: + enable: true diff --git a/home-manager-module.nix b/home-manager-module.nix index cd49d7f..2270f64 100644 --- a/home-manager-module.nix +++ b/home-manager-module.nix @@ -7,20 +7,123 @@ in { options.programs.centerpiece = { enable = lib.mkEnableOption (lib.mdDoc "Centerpiece"); - config.plugin.git_repositories = { - commands = lib.mkOption { - default = [ - [ "alacritty" "--command" "nvim" "$GIT_DIRECTORY" ] - [ "alacritty" "--working-directory" "$GIT_DIRECTORY" ] - ]; - type = lib.types.listOf (lib.types.listOf lib.types.str); - description = lib.mdDoc - "The commands to launch when an entry is selected. Use the $GIT_DIRECTORY variable to pass in the selected directory."; - example = [ - [ "code" "--new-window" "$GIT_DIRECTORY" ] - [ "alacritty" "--command" "lazygit" "--path" "$GIT_DIRECTORY" ] - [ "alacritty" "--working-directory" "$GIT_DIRECTORY" ] - ]; + config.plugin = { + applications = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + brave_bookmarks = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + brave_history = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + brave_progressive_web_apps = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + clock = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + git_repositories = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + commands = lib.mkOption { + default = [ + [ "alacritty" "--command" "nvim" "$GIT_DIRECTORY" ] + [ "alacritty" "--working-directory" "$GIT_DIRECTORY" ] + ]; + type = lib.types.listOf (lib.types.listOf lib.types.str); + description = lib.mdDoc + "The commands to launch when an entry is selected. Use the $GIT_DIRECTORY variable to pass in the selected directory."; + example = [ + [ "code" "--new-window" "$GIT_DIRECTORY" ] + [ "alacritty" "--command" "lazygit" "--path" "$GIT_DIRECTORY" ] + [ "alacritty" "--working-directory" "$GIT_DIRECTORY" ] + ]; + }; + }; + + resource_monitor_battery = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + resource_monitor_cpu = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + resource_monitor_disks = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + resource_monitor_memory = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + system = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + wifi = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; + }; + + windows = { + enable = lib.mkOption { + default = true; + type = lib.types.bool; + description = lib.mdDoc "Enable / disable the plugin."; + }; }; };