diff --git a/Cargo.lock b/Cargo.lock index ecee318..80f0f82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ab_glyph" @@ -1985,9 +1985,9 @@ dependencies = [ [[package]] name = "iced_layershell" -version = "0.9.6" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5929bd962a558f99c2c497fec97efcce7f14c272bc74558085d202ac241d2d1" +checksum = "6dd589c7ed28c3d7e2c65ae9d661417f8a24857dc57a1fce4a5cf47ff5f51c46" dependencies = [ "futures", "iced", @@ -2006,9 +2006,9 @@ dependencies = [ [[package]] name = "iced_layershell_macros" -version = "0.9.6" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626cf5cdf951895c9c4a5be55d39595913e41d28f9bb2a7490b78de59a65f0bf" +checksum = "563e2b7ae2256c825ba8caa0cf9416b5e2ae8973766b51e3b5cd5c350f269aa2" dependencies = [ "darling", "manyhow", @@ -2280,9 +2280,9 @@ dependencies = [ [[package]] name = "layershellev" -version = "0.9.6" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729858eb577a5aedadeb05dd91b61b1f4f09538896df0949b1a7ca46f73d76c1" +checksum = "ce7d1b9341f040e58a604d54f8e38a3e669125c665ff043d5b8ab6cd0662841c" dependencies = [ "bitflags 2.6.0", "calloop 0.14.1", @@ -4062,9 +4062,9 @@ checksum = "bc1ee6eef34f12f765cb94725905c6312b6610ab2b0940889cfe58dae7bc3c72" [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", @@ -4084,18 +4084,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -4542,9 +4542,9 @@ dependencies = [ [[package]] name = "waycrate_xkbkeycode" -version = "0.9.6" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ab4a8bbe75163bc3e24569ba6b81b1646f25a5c22db4e9b2fc50187dbe77e4" +checksum = "6f2fb462c0162d6787c41a324f9214b3ba7e5e2775b3c457d3bd2b8e9c14bae5" dependencies = [ "bitflags 2.6.0", "calloop 0.14.1", diff --git a/client/Cargo.toml b/client/Cargo.toml index 0209159..ec9f3cd 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -25,7 +25,7 @@ serde_yaml = "0.9.34" # application window iced = { version = "0.13.1", features = ["svg"] } -iced_layershell = "0.9.6" +iced_layershell = "0.12.0" hex_color = "3" diff --git a/client/src/main.rs b/client/src/main.rs index bf67c8b..3888d30 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -1,14 +1,13 @@ use clap::Parser; -use iced::Theme; use iced_layershell::to_layer_message; -use iced_layershell::Application; use iced_runtime::Action; mod cli; mod component; mod model; mod plugin; mod settings; +use iced_layershell::build_pattern::application; pub fn main() -> Result<(), iced_layershell::Error> { let args = crate::cli::CliArgs::parse(); @@ -18,7 +17,12 @@ pub fn main() -> Result<(), iced_layershell::Error> { }); simple_logger::init_with_level(log::Level::Info).unwrap(); - Centerpiece::run(settings()) + application(namespace, update, view) + .settings(settings()) + .subscription(subscription) + .theme(theme) + .style(style) + .run_with(Centerpiece::new) } #[to_layer_message] @@ -41,284 +45,280 @@ struct Centerpiece { pub const APP_ID: &str = "centerpiece"; -impl Application for Centerpiece { - type Executor = iced::executor::Default; - type Theme = Theme; - type Flags = (); - type Message = Message; - fn namespace(&self) -> String { - "centerpiece".to_string() - } - fn new(_flags: Self::Flags) -> (Self, iced::Task) { - Self::new() - } - fn update(&mut self, message: Message) -> iced::Task { - match message { - Message::Loaded => focus_search_input(), - - Message::Search(input) => self.search(input), - - Message::Event(event) => match event { - iced::Event::Keyboard(event) => match event { - iced::keyboard::Event::KeyPressed { key, modifiers, .. } => { - if let iced::keyboard::Modifiers::CTRL = modifiers { - return match key.as_ref() { - iced::keyboard::Key::Character("j") => self.select_next_entry(), - iced::keyboard::Key::Character("k") => self.select_previous_entry(), - iced::keyboard::Key::Character("n") => self.select_next_plugin(), - iced::keyboard::Key::Character("p") => { - self.select_previous_plugin() - } - _ => iced::Task::none(), - }; - } - match key.as_ref() { - iced::keyboard::Key::Named(iced::keyboard::key::Named::ArrowUp) => { - self.select_previous_entry() - } - iced::keyboard::Key::Named(iced::keyboard::key::Named::ArrowDown) => { - self.select_next_entry() +fn namespace(_: &Centerpiece) -> String { + "centerpiece".to_string() +} + +fn update(centerpiece: &mut Centerpiece, message: Message) -> iced::Task { + match message { + Message::Loaded => focus_search_input(), + + Message::Search(input) => centerpiece.search(input), + + Message::Event(event) => match event { + iced::Event::Keyboard(event) => match event { + iced::keyboard::Event::KeyPressed { key, modifiers, .. } => { + if let iced::keyboard::Modifiers::CTRL = modifiers { + return match key.as_ref() { + iced::keyboard::Key::Character("j") => centerpiece.select_next_entry(), + iced::keyboard::Key::Character("k") => { + centerpiece.select_previous_entry() } - iced::keyboard::Key::Named(iced::keyboard::key::Named::Enter) => { - self.activate_selected_entry().unwrap_or(iced::Task::none()) + iced::keyboard::Key::Character("n") => centerpiece.select_next_plugin(), + iced::keyboard::Key::Character("p") => { + centerpiece.select_previous_plugin() } _ => iced::Task::none(), - } + }; } - iced::keyboard::Event::KeyReleased { key, .. } => { - if key == iced::keyboard::Key::Named(iced::keyboard::key::Named::Escape) { - return iced_runtime::task::effect(Action::Exit); + match key.as_ref() { + iced::keyboard::Key::Named(iced::keyboard::key::Named::ArrowUp) => { + centerpiece.select_previous_entry() + } + iced::keyboard::Key::Named(iced::keyboard::key::Named::ArrowDown) => { + centerpiece.select_next_entry() } - iced::Task::none() + iced::keyboard::Key::Named(iced::keyboard::key::Named::Enter) => { + centerpiece + .activate_selected_entry() + .unwrap_or(iced::Task::none()) + } + _ => iced::Task::none(), } - - _ => iced::Task::none(), - }, - - iced::Event::Mouse(iced::mouse::Event::ButtonPressed( - iced::mouse::Button::Left, - )) => focus_search_input(), + } + iced::keyboard::Event::KeyReleased { key, .. } => { + if key == iced::keyboard::Key::Named(iced::keyboard::key::Named::Escape) { + return iced_runtime::task::effect(Action::Exit); + } + iced::Task::none() + } _ => iced::Task::none(), }, - Message::FontLoaded(_) => iced::Task::none(), + iced::Event::Mouse(iced::mouse::Event::ButtonPressed(iced::mouse::Button::Left)) => { + focus_search_input() + } + + _ => iced::Task::none(), + }, - Message::RegisterPlugin(plugin) => self.register_plugin(plugin), + Message::FontLoaded(_) => iced::Task::none(), - Message::UpdateEntries(plugin_id, entries) => self.update_entries(plugin_id, entries), + Message::RegisterPlugin(plugin) => centerpiece.register_plugin(plugin), - Message::Exit => iced_runtime::task::effect(Action::Exit), - _ => iced::Task::none(), + Message::UpdateEntries(plugin_id, entries) => { + centerpiece.update_entries(plugin_id, entries) } - } - fn view(&self) -> iced::Element { - let entries = self.entries(); + Message::Exit => iced_runtime::task::effect(Action::Exit), + _ => iced::Task::none(), + } +} - let mut lines = iced::widget::column![]; - let mut divider_added = true; - let mut header_added = false; - let mut next_entry_index_to_add = self.active_entry_index; +fn view(centerpice: &Centerpiece) -> iced::Element { + let entries = centerpice.entries(); - for lines_added in 0..11 { - if next_entry_index_to_add >= entries.len() { - break; - } + let mut lines = iced::widget::column![]; + let mut divider_added = true; + let mut header_added = false; + let mut next_entry_index_to_add = centerpice.active_entry_index; - let mut plugin_to_add = None; - let mut last_plugin_start_index = 0; - for plugin in self.plugins.iter() { - if last_plugin_start_index == next_entry_index_to_add { - plugin_to_add = Some(plugin); - } - last_plugin_start_index += plugin.entries.len(); - } + for lines_added in 0..11 { + if next_entry_index_to_add >= entries.len() { + break; + } - if !divider_added && plugin_to_add.is_some() { - lines = lines.push(component::divider::view()); - divider_added = true; - continue; + let mut plugin_to_add = None; + let mut last_plugin_start_index = 0; + for plugin in centerpice.plugins.iter() { + if last_plugin_start_index == next_entry_index_to_add { + plugin_to_add = Some(plugin); } + last_plugin_start_index += plugin.entries.len(); + } - if !header_added && plugin_to_add.is_some() { - lines = lines.push(component::plugin_header::view(plugin_to_add.unwrap())); - header_added = true; - continue; - } else if lines_added == 0 { - lines = lines.push(component::entry::view( - entries[next_entry_index_to_add - 1], - false, - )); - } + if !divider_added && plugin_to_add.is_some() { + lines = lines.push(component::divider::view()); + divider_added = true; + continue; + } + if !header_added && plugin_to_add.is_some() { + lines = lines.push(component::plugin_header::view(plugin_to_add.unwrap())); + header_added = true; + continue; + } else if lines_added == 0 { lines = lines.push(component::entry::view( - entries[next_entry_index_to_add], - next_entry_index_to_add == self.active_entry_index, + entries[next_entry_index_to_add - 1], + false, )); - divider_added = false; - header_added = false; - next_entry_index_to_add += 1; } - iced::widget::container(iced::widget::column![ - component::query_input::view(&self.query, !entries.is_empty()), - lines - ]) - .style(|theme: &iced::Theme| { - let palette = theme.extended_palette(); - - iced::widget::container::Style { - background: Some(iced::Background::Color(palette.background.base.color)), - border: iced::Border::default().rounded(0.25 * crate::REM), - ..Default::default() - } - }) - .padding(iced::padding::bottom(0.75 * crate::REM)) - .into() + lines = lines.push(component::entry::view( + entries[next_entry_index_to_add], + next_entry_index_to_add == centerpice.active_entry_index, + )); + divider_added = false; + header_added = false; + next_entry_index_to_add += 1; } - fn subscription(&self) -> iced::Subscription { - let mut subscriptions = vec![iced::event::listen_with( - |event, _status, _id| match event { - iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { .. }) => { - Some(Message::Event(event)) - } - iced::Event::Keyboard(iced::keyboard::Event::KeyReleased { .. }) => { - Some(Message::Event(event)) - } - iced::Event::Mouse(iced::mouse::Event::ButtonPressed(_)) => { - Some(Message::Event(event)) - } - _ => None, - }, - )]; - - let settings = crate::settings::Settings::get_or_init(); + iced::widget::container(iced::widget::column![ + component::query_input::view(¢erpice.query, !entries.is_empty()), + lines + ]) + .style(|theme: &iced::Theme| { + let palette = theme.extended_palette(); - if settings.plugin.applications.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::applications::ApplicationsPlugin, - >()); + iced::widget::container::Style { + background: Some(iced::Background::Color(palette.background.base.color)), + border: iced::Border::default().rounded(0.25 * crate::REM), + ..Default::default() } + }) + .padding(iced::padding::bottom(0.75 * crate::REM)) + .into() +} - if settings.plugin.brave_bookmarks.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::brave::bookmarks::BookmarksPlugin, - >()); - } +fn subscription(_: &Centerpiece) -> iced::Subscription { + let mut subscriptions = vec![iced::event::listen_with( + |event, _status, _id| match event { + iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { .. }) => { + Some(Message::Event(event)) + } + iced::Event::Keyboard(iced::keyboard::Event::KeyReleased { .. }) => { + Some(Message::Event(event)) + } + iced::Event::Mouse(iced::mouse::Event::ButtonPressed(_)) => Some(Message::Event(event)), + _ => None, + }, + )]; - if settings.plugin.brave_progressive_web_apps.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::brave::progressive_web_apps::ProgressiveWebAppsPlugin, - >()); - } + let settings = crate::settings::Settings::get_or_init(); - if settings.plugin.brave_history.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::brave::history::HistoryPlugin, - >()); - } + if settings.plugin.applications.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::applications::ApplicationsPlugin, + >()); + } - if settings.plugin.clock.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::clock::ClockPlugin, - >()); - } + if settings.plugin.brave_bookmarks.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::brave::bookmarks::BookmarksPlugin, + >()); + } - if settings.plugin.firefox_bookmarks.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::firefox::bookmarks::BookmarksPlugin, - >()); - } + if settings.plugin.brave_progressive_web_apps.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::brave::progressive_web_apps::ProgressiveWebAppsPlugin, + >()); + } - if settings.plugin.firefox_history.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::firefox::history::HistoryPlugin, - >()); - } + if settings.plugin.brave_history.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::brave::history::HistoryPlugin, + >()); + } - if settings.plugin.git_repositories.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::git_repositories::GitRepositoriesPlugin, - >()); - } + if settings.plugin.clock.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::clock::ClockPlugin, + >()); + } - if settings.plugin.gitmoji.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::gitmoji::GitmojiPlugin, - >()); - } + if settings.plugin.firefox_bookmarks.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::firefox::bookmarks::BookmarksPlugin, + >()); + } - if settings.plugin.resource_monitor_battery.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::resource_monitor::battery::BatteryPlugin, - >()); - } + if settings.plugin.firefox_history.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::firefox::history::HistoryPlugin, + >()); + } - if settings.plugin.resource_monitor_cpu.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::resource_monitor::cpu::CpuPlugin, - >()); - } + if settings.plugin.git_repositories.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::git_repositories::GitRepositoriesPlugin, + >()); + } - if settings.plugin.resource_monitor_disks.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::resource_monitor::disks::DisksPlugin, - >()); - } + if settings.plugin.gitmoji.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::gitmoji::GitmojiPlugin, + >()); + } - if settings.plugin.resource_monitor_memory.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::resource_monitor::memory::MemoryPlugin, - >()); - } + if settings.plugin.resource_monitor_battery.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::battery::BatteryPlugin, + >()); + } - if settings.plugin.system.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::system::SystemPlugin, - >()); - } + if settings.plugin.resource_monitor_cpu.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::cpu::CpuPlugin, + >()); + } - if settings.plugin.wifi.enable { - subscriptions.push(crate::plugin::utils::spawn::()); - } + if settings.plugin.resource_monitor_disks.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::disks::DisksPlugin, + >()); + } - if settings.plugin.sway_windows.enable { - subscriptions.push(crate::plugin::utils::spawn::< - crate::plugin::sway_windows::SwayWindowsPlugin, - >()); - } + if settings.plugin.resource_monitor_memory.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::resource_monitor::memory::MemoryPlugin, + >()); + } - iced::Subscription::batch(subscriptions) + if settings.plugin.system.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::system::SystemPlugin, + >()); } - fn theme(&self) -> iced::Theme { - let settings = crate::settings::Settings::get_or_init(); - iced::Theme::custom( - "centerpiece theme".to_string(), - iced::theme::Palette { - background: crate::settings::hexcolor(&settings.color.background), - text: crate::settings::hexcolor(&settings.color.text), - primary: crate::settings::hexcolor(&settings.color.text), - success: crate::settings::hexcolor(&settings.color.text), - danger: crate::settings::hexcolor(&settings.color.text), - }, - ) + if settings.plugin.wifi.enable { + subscriptions.push(crate::plugin::utils::spawn::()); } - fn style(&self, _theme: &iced::Theme) -> iced_layershell::Appearance { - let color_settings = crate::settings::Settings::get_or_init(); + if settings.plugin.sway_windows.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::sway_windows::SwayWindowsPlugin, + >()); + } - iced_layershell::Appearance { - background_color: iced::Color::TRANSPARENT, - text_color: settings::hexcolor(&color_settings.color.text), - } + iced::Subscription::batch(subscriptions) +} + +fn theme(_: &Centerpiece) -> iced::Theme { + let settings = crate::settings::Settings::get_or_init(); + iced::Theme::custom( + "centerpiece theme".to_string(), + iced::theme::Palette { + background: crate::settings::hexcolor(&settings.color.background), + text: crate::settings::hexcolor(&settings.color.text), + primary: crate::settings::hexcolor(&settings.color.text), + success: crate::settings::hexcolor(&settings.color.text), + danger: crate::settings::hexcolor(&settings.color.text), + }, + ) +} + +fn style(_: &Centerpiece, _theme: &iced::Theme) -> iced_layershell::Appearance { + let color_settings = crate::settings::Settings::get_or_init(); + + iced_layershell::Appearance { + background_color: iced::Color::TRANSPARENT, + text_color: settings::hexcolor(&color_settings.color.text), } } -fn settings() -> iced_layershell::settings::Settings<()> { - iced_layershell::settings::Settings { +fn settings() -> iced_layershell::build_pattern::MainSettings { + iced_layershell::build_pattern::MainSettings { id: Some(APP_ID.into()), default_font: iced::Font { family: iced::font::Family::Name("FiraCode Nerd Font"),