diff --git a/src/async_process.rs b/src/async_process.rs index ba8d6bf..9bfa4ed 100644 --- a/src/async_process.rs +++ b/src/async_process.rs @@ -1,3 +1,4 @@ +use std::ffi::OsStr; use std::process::Stdio; use std::{collections::HashMap, os::unix::process::ExitStatusExt}; use tokio::process::Command; @@ -8,9 +9,9 @@ pub struct AsyncProcessOut { pub stderr: String, } -pub async fn async_process( - cmd: &str, - args: Option<&[&str]>, +pub async fn async_process, T: AsRef>( + cmd: S, + args: Option<&[T]>, env: Option>, ) -> anyhow::Result { let cmd = Command::new(cmd) diff --git a/src/file_utils.rs b/src/file_utils.rs index 8358f5e..5d2beb3 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -1,4 +1,4 @@ -use crate::{cmd_runner::CmdRunner, profile::Profile, runner::Runner}; +use crate::{async_process::async_process, profile::Profile}; use nix::{ errno::Errno, sys::statvfs::{statvfs, FsFlags}, @@ -74,10 +74,11 @@ pub fn setcap_cap_sys_nice_eip_cmd(profile: &Profile) -> Vec { ] } -pub fn setcap_cap_sys_nice_eip(profile: &Profile) { - let mut runner = CmdRunner::new(None, "pkexec".into(), setcap_cap_sys_nice_eip_cmd(profile)); - runner.start(); - runner.join(); +pub async fn setcap_cap_sys_nice_eip(profile: &Profile) { + if let Err(e) = async_process("pkexec", Some(&setcap_cap_sys_nice_eip_cmd(profile)), None).await + { + eprintln!("Error: failed running setcap: {e}"); + } } pub fn rm_rf(path: &Path) { diff --git a/src/main.rs b/src/main.rs index d4a768c..35881ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,7 @@ fn main() -> Result<()> { 0 }); let app = RelmApp::from_app(main_app.clone()).with_broker(&BROKER); - app.run::(AppInit { + app.run_async::(AppInit { application: main_app, }); Ok(()) diff --git a/src/ui/app.rs b/src/ui/app.rs index dd272da..e0e0494 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -55,7 +55,6 @@ use relm4::{ actions::{AccelsPlus, ActionGroupName, RelmAction, RelmActionGroup}, new_action_group, new_stateful_action, new_stateless_action, prelude::*, - {ComponentParts, ComponentSender, SimpleComponent}, }; use std::{collections::VecDeque, fs::remove_file, time::Duration}; @@ -150,7 +149,7 @@ impl App { } } - pub fn start_xrservice(&mut self, sender: ComponentSender, debug: bool) { + pub fn start_xrservice(&mut self, sender: AsyncComponentSender, debug: bool) { self.xrservice_ready = false; let prof = self.get_selected_profile(); if let Err(e) = set_current_active_runtime_to_profile(&prof) { @@ -215,7 +214,7 @@ impl App { } } - pub fn run_autostart(&mut self, sender: ComponentSender) { + pub fn run_autostart(&mut self, sender: AsyncComponentSender) { let prof = self.get_selected_profile(); if let Some(autostart_cmd) = &prof.autostart_command { let mut jobs = VecDeque::new(); @@ -281,11 +280,12 @@ pub struct AppInit { pub application: adw::Application, } -#[relm4::component(pub)] -impl SimpleComponent for App { +#[relm4::component(pub async)] +impl AsyncComponent for App { type Init = AppInit; type Input = Msg; type Output = (); + type CommandOutput = (); view! { #[root] @@ -321,7 +321,12 @@ impl SimpleComponent for App { self.restore_openxr_openvr_files(); } - fn update(&mut self, message: Self::Input, sender: ComponentSender) { + async fn update( + &mut self, + message: Self::Input, + sender: AsyncComponentSender, + _root: &Self::Root, + ) { match message { Msg::NoOp => {} Msg::OnServiceLog(rows) => { @@ -604,7 +609,7 @@ impl SimpleComponent for App { println!("pkexec not found, skipping setcap"); } else { let profile = self.get_selected_profile(); - setcap_cap_sys_nice_eip(&profile); + setcap_cap_sys_nice_eip(&profile).await; } } Msg::ProfileSelected(prof) => { @@ -738,11 +743,11 @@ impl SimpleComponent for App { } } - fn init( + async fn init( init: Self::Init, root: Self::Root, - sender: ComponentSender, - ) -> ComponentParts { + sender: AsyncComponentSender, + ) -> AsyncComponentParts { let config = Config::get_config(); let win_size = config.win_size; let profiles = config.profiles(); @@ -965,7 +970,7 @@ impl SimpleComponent for App { model.split_view = Some(widgets.split_view.clone()); - ComponentParts { model, widgets } + AsyncComponentParts { model, widgets } } }