Skip to content

Commit

Permalink
add populate factory using toolboxes on machine
Browse files Browse the repository at this point in the history
  • Loading branch information
13hannes11 committed Apr 27, 2024
1 parent 92315c5 commit 308ad5c
Show file tree
Hide file tree
Showing 8 changed files with 470 additions and 30 deletions.
14 changes: 8 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -14,3 +14,5 @@ tracing = "0.1"
tracing-subscriber = "0.3"
relm4 = { version = "0.8.1", features = ["libadwaita", "gnome_45"] }
relm4-icons = { version = "0.8.1" }
serde = { version = "1.0.199", features = ["derive"] }
serde_json = "1.0.116"
7 changes: 4 additions & 3 deletions build-aux/org.kuchelmeister.ToolboxTuner.Devel.json
Expand Up @@ -9,13 +9,14 @@
],
"command": "toolbox-tuner",
"finish-args": [
"--share=ipc",
"--talk-name=org.freedesktop.Flatpak",
"--socket=fallback-x11",
"--socket=wayland",
"--device=dri",
"--env=RUST_LOG=toolbox_tuner=debug",
"--env=RUST_LOG=toolbxtuner=debug",
"--env=G_MESSAGES_DEBUG=none",
"--env=RUST_BACKTRACE=1"
"--env=RUST_BACKTRACE=1",
"--share=ipc"
],
"build-options": {
"append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm15/bin",
Expand Down
25 changes: 12 additions & 13 deletions src/app.rs
@@ -1,4 +1,5 @@
use crate::gtk::Align;
use crate::util::toolbox::ToolbxContainer;
use relm4::factory::FactoryHashMap;
use relm4::gtk::PolicyType;
use relm4::RelmWidgetExt;
Expand Down Expand Up @@ -39,6 +40,7 @@ relm4::new_action_group!(pub(super) WindowActionGroup, "win");
//relm4::new_stateless_action!(PreferencesAction, WindowActionGroup, "preferences");
relm4::new_stateless_action!(pub(super) ShortcutsAction, WindowActionGroup, "show-help-overlay");
relm4::new_stateless_action!(AboutAction, WindowActionGroup, "about");
use crate::factories::container_list::ContainerInit;

#[relm4::component(pub)]
impl Component for App {
Expand Down Expand Up @@ -130,20 +132,17 @@ impl Component for App {
UnsupportedDialogOutput::CloseApplication => AppMsg::Quit,
});

let toolboxes = ToolbxContainer::get_toolboxes();

let mut containers = FactoryHashMap::builder().launch_default().detach();
containers.insert("123".to_string(), 2);
containers.insert("abc".to_string(), 3);
containers.insert("45435".to_string(), 3);
containers.insert("1dsal;k1;23".to_string(), 3);
containers.insert("afdsaf".to_string(), 3);
containers.insert("5344".to_string(), 3);
containers.insert("1242344".to_string(), 3);
containers.insert("1265464".to_string(), 3);
containers.insert(
"126222222222222222222222222222222222222222233333333333333333333333333333333325464"
.to_string(),
3,
);
toolboxes.iter().for_each(|toolbox| {
&containers.insert(
toolbox.id.clone(),
ContainerInit {
name: toolbox.name.clone(),
},
);
});

let model = Self {
about_dialog,
Expand Down
23 changes: 15 additions & 8 deletions src/factories/container_list.rs
Expand Up @@ -10,17 +10,23 @@ use relm4_icons::icon_names;
#[derive(Debug)]
pub struct Container {
hash: String,
value: u8,
value: String,
}

#[derive(Debug)]
pub enum ContainerMsg {
Start,
Stop,
OpenTerminal,
}

pub struct ContainerInit {
pub name: String,
}

#[relm4::factory(pub)]
impl FactoryComponent for Container {
type Init = u8;
type Init = ContainerInit;
type Input = ContainerMsg;
type Output = ();
type CommandOutput = ();
Expand All @@ -31,7 +37,8 @@ impl FactoryComponent for Container {
view! {
root = adw::ActionRow {
#[watch]
set_title: format!{"{}: {}", self.hash, self.value.to_string()}.as_str(),
set_title: &self.value,
set_subtitle: &self.hash,

add_prefix = &gtk::Box{
gtk::AspectFrame{
Expand All @@ -58,7 +65,7 @@ impl FactoryComponent for Container {
set_margin_top: 10,
set_margin_bottom: 10,
set_css_classes: &["flat"],
connect_clicked => ContainerMsg::Start,
connect_clicked => ContainerMsg::OpenTerminal,
},
},
},
Expand All @@ -68,15 +75,15 @@ impl FactoryComponent for Container {
fn init_model(value: Self::Init, index: &Self::Index, _sender: FactorySender<Self>) -> Self {
Self {
hash: index.clone(),
value,
value: value.name.clone(),
}
}

fn update(&mut self, msg: Self::Input, _sender: FactorySender<Self>) {
match msg {
ContainerMsg::Start => {
self.value = self.value.wrapping_add(1);
}
ContainerMsg::Start => {}
ContainerMsg::Stop => {}
ContainerMsg::OpenTerminal => {}
}
}
}
1 change: 1 addition & 0 deletions src/main.rs
Expand Up @@ -2,6 +2,7 @@ mod app;
mod config;
mod factories;
mod modals;
mod util;

use crate::config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
use gettextrs::{gettext, LocaleCategory};
Expand Down
1 change: 1 addition & 0 deletions src/util.rs
@@ -0,0 +1 @@
pub mod toolbox;

0 comments on commit 308ad5c

Please sign in to comment.