Putting the UI away so I have to touch it less
This commit is contained in:
parent
cf64f5dca0
commit
ebead58d61
12
src/main.rs
12
src/main.rs
@ -1,6 +1,7 @@
|
|||||||
use gtk::prelude::*;
|
|
||||||
use gtk::Application;
|
use gtk::Application;
|
||||||
use waycast::ui::AppModel;
|
use gtk::prelude::*;
|
||||||
|
use waycast::plugins;
|
||||||
|
use waycast::ui::WaycastLauncher;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = Application::builder()
|
let app = Application::builder()
|
||||||
@ -8,8 +9,11 @@ fn main() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
app.connect_activate(|app| {
|
app.connect_activate(|app| {
|
||||||
let model = AppModel::new(app);
|
let launcher = WaycastLauncher::new()
|
||||||
model.borrow().show();
|
.add_plugin(plugins::drun::DrunPlugin {})
|
||||||
|
.initialize(app);
|
||||||
|
|
||||||
|
launcher.borrow().show();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
|
@ -10,15 +10,38 @@ use layerShell::LayerShell;
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::{LauncherListItem, LauncherPlugin, plugins};
|
use crate::{LauncherListItem, LauncherPlugin};
|
||||||
|
|
||||||
pub struct AppModel {
|
pub struct WaycastLauncher {
|
||||||
pub window: ApplicationWindow,
|
pub window: ApplicationWindow,
|
||||||
pub list_box: ListBox,
|
pub list_box: ListBox,
|
||||||
pub entries: Vec<Box<dyn LauncherListItem>>,
|
pub entries: Vec<Box<dyn LauncherListItem>>,
|
||||||
pub plugins: Vec<Box<dyn LauncherPlugin>>,
|
pub plugins: Vec<Box<dyn LauncherPlugin>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WaycastLauncher {
|
||||||
|
pub fn new() -> WaycastLauncherBuilder {
|
||||||
|
WaycastLauncherBuilder {
|
||||||
|
plugins: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WaycastLauncherBuilder {
|
||||||
|
plugins: Vec<Box<dyn LauncherPlugin>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WaycastLauncherBuilder {
|
||||||
|
pub fn add_plugin<T: LauncherPlugin + 'static>(mut self, plugin: T) -> Self {
|
||||||
|
self.plugins.push(Box::new(plugin));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initialize(self, app: &Application) -> Rc<RefCell<WaycastLauncher>> {
|
||||||
|
WaycastLauncher::create_with_plugins(app, self.plugins)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ListItem {
|
pub struct ListItem {
|
||||||
text: String,
|
text: String,
|
||||||
icon: String,
|
icon: String,
|
||||||
@ -62,8 +85,8 @@ impl ListItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppModel {
|
impl WaycastLauncher {
|
||||||
pub fn new(app: &Application) -> Rc<RefCell<Self>> {
|
fn create_with_plugins(app: &Application, plugins: Vec<Box<dyn LauncherPlugin>>) -> Rc<RefCell<Self>> {
|
||||||
let window = ApplicationWindow::builder()
|
let window = ApplicationWindow::builder()
|
||||||
.application(app)
|
.application(app)
|
||||||
.title("Waycast")
|
.title("Waycast")
|
||||||
@ -105,8 +128,7 @@ impl AppModel {
|
|||||||
window.set_layer(layerShell::Layer::Top);
|
window.set_layer(layerShell::Layer::Top);
|
||||||
|
|
||||||
let entries: Vec<Box<dyn LauncherListItem>> = Vec::new();
|
let entries: Vec<Box<dyn LauncherListItem>> = Vec::new();
|
||||||
let plugins: Vec<Box<dyn LauncherPlugin>> = vec![Box::from(plugins::drun::DrunPlugin {})];
|
let model: Rc<RefCell<WaycastLauncher>> = Rc::new(RefCell::new(WaycastLauncher {
|
||||||
let model: Rc<RefCell<AppModel>> = Rc::new(RefCell::new(AppModel {
|
|
||||||
window,
|
window,
|
||||||
list_box: list_box.clone(),
|
list_box: list_box.clone(),
|
||||||
entries,
|
entries,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user