From ebead58d614fbeb4bc848892e16235405a52391f Mon Sep 17 00:00:00 2001 From: Javier Feliz Date: Wed, 3 Sep 2025 21:39:14 -0400 Subject: [PATCH] Putting the UI away so I have to touch it less --- src/main.rs | 14 +++++++++----- src/ui/mod.rs | 34 ++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9ded1fa..a804294 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ -use gtk::prelude::*; use gtk::Application; -use waycast::ui::AppModel; +use gtk::prelude::*; +use waycast::plugins; +use waycast::ui::WaycastLauncher; fn main() { let app = Application::builder() @@ -8,9 +9,12 @@ fn main() { .build(); app.connect_activate(|app| { - let model = AppModel::new(app); - model.borrow().show(); + let launcher = WaycastLauncher::new() + .add_plugin(plugins::drun::DrunPlugin {}) + .initialize(app); + + launcher.borrow().show(); }); app.run(); -} \ No newline at end of file +} diff --git a/src/ui/mod.rs b/src/ui/mod.rs index a89a787..145e57e 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -10,15 +10,38 @@ use layerShell::LayerShell; use std::cell::RefCell; use std::path::PathBuf; use std::rc::Rc; -use crate::{LauncherListItem, LauncherPlugin, plugins}; +use crate::{LauncherListItem, LauncherPlugin}; -pub struct AppModel { +pub struct WaycastLauncher { pub window: ApplicationWindow, pub list_box: ListBox, pub entries: Vec>, pub plugins: Vec>, } +impl WaycastLauncher { + pub fn new() -> WaycastLauncherBuilder { + WaycastLauncherBuilder { + plugins: Vec::new(), + } + } +} + +pub struct WaycastLauncherBuilder { + plugins: Vec>, +} + +impl WaycastLauncherBuilder { + pub fn add_plugin(mut self, plugin: T) -> Self { + self.plugins.push(Box::new(plugin)); + self + } + + pub fn initialize(self, app: &Application) -> Rc> { + WaycastLauncher::create_with_plugins(app, self.plugins) + } +} + pub struct ListItem { text: String, icon: String, @@ -62,8 +85,8 @@ impl ListItem { } } -impl AppModel { - pub fn new(app: &Application) -> Rc> { +impl WaycastLauncher { + fn create_with_plugins(app: &Application, plugins: Vec>) -> Rc> { let window = ApplicationWindow::builder() .application(app) .title("Waycast") @@ -105,8 +128,7 @@ impl AppModel { window.set_layer(layerShell::Layer::Top); let entries: Vec> = Vec::new(); - let plugins: Vec> = vec![Box::from(plugins::drun::DrunPlugin {})]; - let model: Rc> = Rc::new(RefCell::new(AppModel { + let model: Rc> = Rc::new(RefCell::new(WaycastLauncher { window, list_box: list_box.clone(), entries,