Skip to content

Commit

Permalink
✨ add config options to enable / disable plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
friedow committed Feb 27, 2024
1 parent 3031533 commit f79475f
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 33 deletions.
102 changes: 83 additions & 19 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Centerpiece {
query: String,
active_entry_index: usize,
plugins: Vec<model::Plugin>,
settings: settings::Settings,
}

pub const SCROLLABLE_ID: &str = "scrollable";
Expand All @@ -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),
)
Expand Down Expand Up @@ -108,8 +110,8 @@ impl Application for Centerpiece {
}

fn subscription(&self) -> iced::Subscription<Self::Message> {
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: _,
Expand All @@ -122,24 +124,86 @@ impl Application for Centerpiece {
Some(Message::Event(event))
}
_ => None,
}),
crate::plugin::utils::spawn::<crate::plugin::windows::WindowsPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::applications::ApplicationsPlugin>(),
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::git_repositories::GitRepositoriesPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::brave::bookmarks::BookmarksPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::system::SystemPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::wifi::WifiPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::resource_monitor::battery::BatteryPlugin>(
),
crate::plugin::utils::spawn::<crate::plugin::resource_monitor::cpu::CpuPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::resource_monitor::memory::MemoryPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::resource_monitor::disks::DisksPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::clock::ClockPlugin>(),
crate::plugin::utils::spawn::<crate::plugin::brave::history::HistoryPlugin>(),
])
>());
}

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::<crate::plugin::wifi::WifiPlugin>());
}

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<Message> {
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/brave/bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct BookmarksPlugin {

impl Plugin for BookmarksPlugin {
fn id() -> &'static str {
"brave-bookmarks"
"brave_bookmarks"
}

fn priority() -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/brave/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct HistoryPlugin {

impl Plugin for HistoryPlugin {
fn id() -> &'static str {
"brave-history"
"brave_history"
}

fn priority() -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/brave/progressive_web_apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions client/src/plugin/git_repositories.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{plugin::utils::Plugin, settings::Settings};
use crate::plugin::utils::Plugin;
use anyhow::Context;

pub struct GitRepositoriesPlugin {
entries: Vec<crate::model::Entry>,
settings: Settings,
settings: crate::settings::Settings,
}

impl Plugin for GitRepositoriesPlugin {
Expand All @@ -26,7 +26,7 @@ impl Plugin for GitRepositoriesPlugin {
fn new() -> Self {
Self {
entries: vec![],
settings: Settings::new(),
settings: crate::settings::Settings::new(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/resource_monitor/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct BatteryPlugin {

impl Plugin for BatteryPlugin {
fn id() -> &'static str {
"battery"
"resource_monitor_battery"
}

fn priority() -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/resource_monitor/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct CpuPlugin {

impl Plugin for CpuPlugin {
fn id() -> &'static str {
"cpu"
"resource_monitor_cpu"
}

fn priority() -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/resource_monitor/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct DisksPlugin {

impl Plugin for DisksPlugin {
fn id() -> &'static str {
"disks"
"resource_monitor_disks"
}

fn priority() -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/resource_monitor/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct MemoryPlugin {

impl Plugin for MemoryPlugin {
fn id() -> &'static str {
"memory"
"resource_monitor_memory"
}

fn priority() -> u32 {
Expand Down
153 changes: 149 additions & 4 deletions client/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,70 @@
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct GitRepositoriesSettings {
pub struct ApplicationsPluginSettings {
pub enable: bool,
}

impl Default for ApplicationsPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct BraveBookmarksPluginSettings {
pub enable: bool,
}

impl Default for BraveBookmarksPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct BraveHistoryPluginSettings {
pub enable: bool,
}

impl Default for BraveHistoryPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct BraveProgressiveWebAppsSettings {
pub enable: bool,
}

impl Default for BraveProgressiveWebAppsSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct ClockPluginSettings {
pub enable: bool,
}

impl Default for ClockPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct GitRepositoriesPluginSettings {
pub enable: bool,
pub commands: Vec<Vec<String>>,
}

impl Default for GitRepositoriesSettings {
impl Default for GitRepositoriesPluginSettings {
fn default() -> Self {
Self {
enable: true,
commands: vec![
vec![
"alacritty".into(),
Expand All @@ -25,10 +82,98 @@ impl Default for GitRepositoriesSettings {
}
}

#[derive(Debug, Deserialize)]
pub struct ResourceMonitorBatteryPluginSettings {
pub enable: bool,
}

impl Default for ResourceMonitorBatteryPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct ResourceMonitorCpuPluginSettings {
pub enable: bool,
}

impl Default for ResourceMonitorCpuPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct ResourceMonitorDisksSettings {
pub enable: bool,
}

impl Default for ResourceMonitorDisksSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct ResourceMonitorMemoryPluginSettings {
pub enable: bool,
}

impl Default for ResourceMonitorMemoryPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct SystemPluginSettings {
pub enable: bool,
}

impl Default for SystemPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct WifiPluginSettings {
pub enable: bool,
}

impl Default for WifiPluginSettings {
fn default() -> Self {
Self { enable: true }
}
}

#[derive(Debug, Deserialize)]
pub struct WindowsPluginSettings {
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,
pub brave_bookmarks: BraveBookmarksPluginSettings,
pub brave_history: BraveHistoryPluginSettings,
pub brave_progressive_web_apps: BraveProgressiveWebAppsSettings,
pub clock: ClockPluginSettings,
pub git_repositories: GitRepositoriesPluginSettings,
pub resource_monitor_battery: ResourceMonitorBatteryPluginSettings,
pub resource_monitor_cpu: ResourceMonitorCpuPluginSettings,
pub resource_monitor_disks: ResourceMonitorDisksSettings,
pub resource_monitor_memory: ResourceMonitorMemoryPluginSettings,
pub system: SystemPluginSettings,
pub wifi: WifiPluginSettings,
pub windows: WindowsPluginSettings,
}

#[derive(Debug, Default, Deserialize)]
Expand Down
Loading

0 comments on commit f79475f

Please sign in to comment.