move starting of terminal to main thread #4

This commit is contained in:
2022-06-06 00:21:42 +02:00
parent 77d09397aa
commit 3fec9bee21
2 changed files with 13 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
use std::process::Command;
use relm4::{AppUpdate, Sender}; use relm4::{AppUpdate, Sender};
use crate::{ use crate::{
@@ -62,14 +64,17 @@ impl AppUpdate for AppModel {
AppMsg::OpenToolbxTerminal(index) => { AppMsg::OpenToolbxTerminal(index) => {
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) { if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
components // TODO: support many terminals and check which are installed
.async_handler let output = Command::new("gnome-terminal")
.sender() .arg("--")
.blocking_send(AsyncHandlerMsg::OpenToolbxTerminal( .arg("toolbox")
index, .arg("enter")
toolbx_container.clone(), .arg(toolbx_container.toolbx_container.name.clone())
)) .output();
.expect("Receiver dropped");
println!("{:?}", output);
// TODO: update status
} }
} }
} }

View File

@@ -1,5 +1,3 @@
use std::process::Command;
use relm4::factory::DynamicIndex; use relm4::factory::DynamicIndex;
use relm4::{send, MessageHandler, Sender}; use relm4::{send, MessageHandler, Sender};
use tokio::runtime::{Builder, Runtime}; use tokio::runtime::{Builder, Runtime};
@@ -20,7 +18,6 @@ pub struct AsyncHandler {
pub enum AsyncHandlerMsg { pub enum AsyncHandlerMsg {
StopToolbx(DynamicIndex, ToolbxEntry), StopToolbx(DynamicIndex, ToolbxEntry),
StartToolbx(DynamicIndex, ToolbxEntry), StartToolbx(DynamicIndex, ToolbxEntry),
OpenToolbxTerminal(DynamicIndex, ToolbxEntry),
} }
impl MessageHandler<AppModel> for AsyncHandler { impl MessageHandler<AppModel> for AsyncHandler {
@@ -52,19 +49,6 @@ impl MessageHandler<AppModel> for AsyncHandler {
tbx.changing_status = false; tbx.changing_status = false;
send! {parent_sender, AppMsg::ToolbxContainerChanged(index, tbx)}; 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
}
} }
}); });
} }