Skip to content

Commit

Permalink
refactor UI
Browse files Browse the repository at this point in the history
  • Loading branch information
beac0n committed Nov 2, 2024
1 parent c186390 commit 18a36e6
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 250 deletions.
3 changes: 1 addition & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fn main() {
let config = slint_build::CompilerConfiguration::new().with_style("fluent".into());

slint_build::compile_with_config("src/ui/app-window.slint", config)
.expect("Slint build failed");
slint_build::compile_with_config("src/ui/app.slint", config).expect("Slint build failed");
}
34 changes: 18 additions & 16 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{env, fs};

slint::include_modules!();
pub fn run_ui() -> Result<(), Box<dyn Error>> {
let ui = AppWindow::new()?;
let app = App::new()?;

let public_pem_path = default_public_pem_path();
let private_pem_path = default_private_pem_path();
Expand All @@ -29,22 +29,23 @@ pub fn run_ui() -> Result<(), Box<dyn Error>> {
}

let commands_list = CommandsList::create(&get_conf_dir());
ui.set_commands_list(ModelRc::from(Rc::new(VecModel::from(commands_list.get()))));

ui.set_private_pem_path(SharedString::from(
let globals = app.global::<CommandLogic>();
globals.set_commands_list(ModelRc::from(Rc::new(VecModel::from(commands_list.get()))));
globals.set_private_pem_path(SharedString::from(
private_pem_path.to_str().ok_or("Could not convert path to string")?,
));
ui.set_public_key(fs::read_to_string(&public_pem_path)?.into());
globals.set_public_key(fs::read_to_string(&public_pem_path)?.into());
globals.set_command(SharedString::from(DEFAULT_COMMAND));
globals.set_deadline(DEFAULT_DEADLINE.to_string().into());
globals.set_ntp(SharedString::from(NTP_SYSTEM));

ui.set_command(SharedString::from(DEFAULT_COMMAND));
ui.set_deadline(DEFAULT_DEADLINE.to_string().into());
ui.set_ntp(SharedString::from(NTP_SYSTEM));

ui.on_add_command({
let ui_handle = ui.as_weak();
globals.on_add_command({
let app_handle = app.as_weak();
let mut persistent_commands_list = CommandsList::create(&get_conf_dir());
move |cmd| {
let commands_list_rc = ui_handle.unwrap().get_commands_list();
let binding = app_handle.unwrap();
let commands_list_rc = binding.global::<CommandLogic>().get_commands_list();
let commands_list: &VecModel<SharedString> = commands_list_rc
.as_any()
.downcast_ref()
Expand All @@ -56,11 +57,12 @@ pub fn run_ui() -> Result<(), Box<dyn Error>> {
}
});

ui.on_del_command({
let ui_handle = ui.as_weak();
globals.on_del_command({
let app_handle = app.as_weak();
let mut persistent_commands_list = CommandsList::create(&get_conf_dir());
move |cmd| {
let commands_list_rc = ui_handle.unwrap().get_commands_list();
let binding = app_handle.unwrap();
let commands_list_rc = binding.global::<CommandLogic>().get_commands_list();
let commands_list: &VecModel<SharedString> = commands_list_rc
.as_any()
.downcast_ref()
Expand All @@ -76,7 +78,7 @@ pub fn run_ui() -> Result<(), Box<dyn Error>> {
}
});

ui.on_exec_command(|cmd| {
globals.on_exec_command(|cmd| {
let cmd_str = cmd.to_string();
let mut cmd_vec: Vec<&str> = cmd_str.split(" ").collect();
cmd_vec.insert(0, "ruroco");
Expand All @@ -89,7 +91,7 @@ pub fn run_ui() -> Result<(), Box<dyn Error>> {
};
});

ui.run()?;
app.run()?;

Ok(())
}
123 changes: 0 additions & 123 deletions src/ui/app-window.slint

This file was deleted.

30 changes: 30 additions & 0 deletions src/ui/app.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { TabWidget } from "std-widgets.slint";
import { Create } from "create.slint";
import { CommandLogic } from "command-logic.slint";
import { PublicKey } from "public-key.slint";
import { Execute } from "execute.slint";

export component App inherits Window {
title: "ruroco";
preferred-height: 1200px;
preferred-width: 540px;

TabWidget {
Tab {
title: "Public PEM key";
PublicKey { }
}

Tab {
title: "Create";
Create { }
}

Tab {
title: "Execute";
Execute { }
}
}
}

export { CommandLogic }
11 changes: 11 additions & 0 deletions src/ui/command-logic.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export global CommandLogic {
in-out property <[string]> commands_list: [];
in-out property <string> public_key: "";
in-out property <string> private_pem_path: "";
in-out property <string> command: "";
in-out property <string> deadline: "";
in-out property <string> ntp: "";
callback add_command(string);
callback exec_command(string);
callback del_command(string);
}
109 changes: 0 additions & 109 deletions src/ui/commands-input.slint

This file was deleted.

Loading

0 comments on commit 18a36e6

Please sign in to comment.