From 7fa2c5e25ffc3057020afd4900d7d49ff4f3efdd Mon Sep 17 00:00:00 2001 From: Marcus Behrendt Date: Sat, 25 Nov 2023 21:22:38 +0100 Subject: [PATCH 1/2] fix(container-terminal): Close processes on exit I remember this used to work, but it must have regressed somehow. --- src/view/container_terminal.rs | 33 ++++++++++++++++++++++++----- src/view/container_terminal_page.rs | 2 ++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/view/container_terminal.rs b/src/view/container_terminal.rs index 89f15413..dcba8ba3 100644 --- a/src/view/container_terminal.rs +++ b/src/view/container_terminal.rs @@ -1,3 +1,4 @@ +use std::cell::Cell; use std::cell::RefCell; use std::sync::OnceLock; @@ -33,6 +34,7 @@ const ACTION_PASTE: &str = "container-terminal.paste"; enum ExecInput { Data(Vec), Resize { columns: usize, rows: usize }, + Terminate, } mod imp { @@ -43,7 +45,8 @@ mod imp { #[template(resource = "/com/github/marhkb/Pods/ui/view/container_terminal.ui")] pub(crate) struct ContainerTerminal { pub(super) settings: utils::PodsSettings, - pub(super) tx_tokio: RefCell>>, + pub(super) tx_input: RefCell>>, + pub(super) keep_alive_on_next_unroot: Cell, #[property(get, set, nullable)] pub(super) container: glib::WeakRef, #[template_child] @@ -229,13 +232,23 @@ mod imp { fn size_allocate(&self, width: i32, height: i32, baseline: i32) { self.stack.allocate(width, height, baseline, None); - if let Some(tx_tokio) = &*self.tx_tokio.borrow() { + if let Some(tx_tokio) = &*self.tx_input.borrow() { _ = tx_tokio.send(ExecInput::Resize { columns: self.terminal.column_count() as usize, rows: self.terminal.row_count() as usize, }); } } + + fn unroot(&self) { + if !self.keep_alive_on_next_unroot.get() { + if let Some(tx_input) = &*self.tx_input.borrow() { + _ = tx_input.send(ExecInput::Terminate); + } + } + self.keep_alive_on_next_unroot.set(false); + self.parent_unroot(); + } } #[gtk::template_callbacks] @@ -352,6 +365,10 @@ glib::wrapper! { } impl ContainerTerminal { + pub(crate) fn keep_alive_on_next_unroot(&self) { + self.imp().keep_alive_on_next_unroot.set(true); + } + pub(crate) fn font_scale(&self) -> f64 { self.imp().terminal.font_scale() } @@ -377,7 +394,7 @@ impl ContainerTerminal { })); let (tx_input, mut rx_input) = tokio::sync::mpsc::unbounded_channel::(); - imp.tx_tokio.replace(Some(tx_input.clone())); + imp.tx_input.replace(Some(tx_input.clone())); imp.terminal.connect_commit(move |_, data, _| { _ = tx_input.send(ExecInput::Data(data.as_bytes().to_vec())); }); @@ -406,7 +423,7 @@ impl ContainerTerminal { loop { match future::select(Box::pin(rx_input.recv()), reader.next()).await { future::Either::Left((buf, _)) => match buf { - Some(buf) => match buf { + Some(input) => match input { ExecInput::Data(buf) => { if let Err(e) = writer.write_all(&buf).await { log::error!("Error on writing to terminal: {e}"); @@ -419,6 +436,7 @@ impl ContainerTerminal { break; } } + ExecInput::Terminate => break, }, None => break, }, @@ -437,7 +455,12 @@ impl ContainerTerminal { } } - // Close all processes. + // Close remaining processes. + log::info!( + "Closing remaining processes of container {} for exec {}.", + container.id(), + exec.id() + ); while writer.write_all(&[3]).await.is_ok() && writer.write_all(&[4]).await.is_ok() { } diff --git a/src/view/container_terminal_page.rs b/src/view/container_terminal_page.rs index c17d2990..742d9482 100644 --- a/src/view/container_terminal_page.rs +++ b/src/view/container_terminal_page.rs @@ -165,6 +165,8 @@ impl From<&model::Container> for ContainerTerminalPage { impl ContainerTerminalPage { pub(crate) fn pip_out(&self) { if let Some(navigation_view) = utils::try_navigation_view(self.upcast_ref()) { + self.imp().terminal.keep_alive_on_next_unroot(); + self.action_set_enabled(ACTION_PIP_OUT, false); let animate_transitions = navigation_view.is_animate_transitions(); From 6107aa7f81f01f9e951552d6f3dc97f39bc3603d Mon Sep 17 00:00:00 2001 From: Marcus Behrendt Date: Sat, 25 Nov 2023 21:25:15 +0100 Subject: [PATCH 2/2] docs(appdata): Update changelog --- data/com.github.marhkb.Pods.metainfo.xml.in.in | 1 + 1 file changed, 1 insertion(+) diff --git a/data/com.github.marhkb.Pods.metainfo.xml.in.in b/data/com.github.marhkb.Pods.metainfo.xml.in.in index 374ff215..cd21d6a3 100644 --- a/data/com.github.marhkb.Pods.metainfo.xml.in.in +++ b/data/com.github.marhkb.Pods.metainfo.xml.in.in @@ -47,6 +47,7 @@

Pods 2.1.0 contains the following changes:

  • Build about dialog from appdata. (#743)
  • +
  • Close all remaining processes after container terminal exits. (#744)