add first hacky implementaion that opens terminal, #4

This commit is contained in:
2022-05-22 13:59:41 +02:00
parent 1487ad5bd3
commit 77d09397aa
4 changed files with 35 additions and 0 deletions

View File

@@ -6,5 +6,6 @@ pub enum AppMsg {
ShowToolboxSettingsRequest,
ShowToolboxAppsRequest,
ToolbxContainerToggleStartStop(DynamicIndex),
OpenToolbxTerminal(DynamicIndex),
ToolbxContainerChanged(DynamicIndex, ToolbxEntry),
}

View File

@@ -33,6 +33,8 @@ impl FactoryPrototype for ToolbxEntry {
type Msg = AppMsg;
fn init_view(&self, key: &DynamicIndex, sender: Sender<Self::Msg>) -> Self::Widgets {
let index = key.clone();
view! {
suffix_box = &gtk::Box{
append = &gtk::AspectFrame{
@@ -56,6 +58,9 @@ impl FactoryPrototype for ToolbxEntry {
set_margin_bottom: 10,
set_tooltip_text: Some(TERMINAL_TOOLTIP),
set_css_classes: &["flat"],
connect_clicked(sender) => move |btn| {
send!(sender, AppMsg::OpenToolbxTerminal(index.clone()));
},
}
},
append = &gtk::AspectFrame{

View File

@@ -59,6 +59,19 @@ impl AppUpdate for AppModel {
toolbx_container.update_entry(container);
}
}
AppMsg::OpenToolbxTerminal(index) => {
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
components
.async_handler
.sender()
.blocking_send(AsyncHandlerMsg::OpenToolbxTerminal(
index,
toolbx_container.clone(),
))
.expect("Receiver dropped");
}
}
}
true
}

View File

@@ -1,3 +1,5 @@
use std::process::Command;
use relm4::factory::DynamicIndex;
use relm4::{send, MessageHandler, Sender};
use tokio::runtime::{Builder, Runtime};
@@ -18,6 +20,7 @@ pub struct AsyncHandler {
pub enum AsyncHandlerMsg {
StopToolbx(DynamicIndex, ToolbxEntry),
StartToolbx(DynamicIndex, ToolbxEntry),
OpenToolbxTerminal(DynamicIndex, ToolbxEntry),
}
impl MessageHandler<AppModel> for AsyncHandler {
@@ -49,6 +52,19 @@ impl MessageHandler<AppModel> for AsyncHandler {
tbx.changing_status = false;
send! {parent_sender, AppMsg::ToolbxContainerChanged(index, tbx)};
}
AsyncHandlerMsg::OpenToolbxTerminal(index, mut tbx) => {
// TODO: support many terminals and check which are installed
let output = Command::new("gnome-terminal")
.arg("--")
.arg("toolbox")
.arg("enter")
.arg(tbx.toolbx_container.name.clone())
.output();
println!("{:?}", output);
// TODO: update status
}
}
});
}