mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-02 06:08:42 +00:00
feat: use async_process for setcap; app is async component
This commit is contained in:
parent
7daa5987b5
commit
aa7f3ec0c4
4 changed files with 27 additions and 20 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use std::{collections::HashMap, os::unix::process::ExitStatusExt};
|
use std::{collections::HashMap, os::unix::process::ExitStatusExt};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
@ -8,9 +9,9 @@ pub struct AsyncProcessOut {
|
||||||
pub stderr: String,
|
pub stderr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn async_process(
|
pub async fn async_process<S: AsRef<OsStr>, T: AsRef<OsStr>>(
|
||||||
cmd: &str,
|
cmd: S,
|
||||||
args: Option<&[&str]>,
|
args: Option<&[T]>,
|
||||||
env: Option<HashMap<String, String>>,
|
env: Option<HashMap<String, String>>,
|
||||||
) -> anyhow::Result<AsyncProcessOut> {
|
) -> anyhow::Result<AsyncProcessOut> {
|
||||||
let cmd = Command::new(cmd)
|
let cmd = Command::new(cmd)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{cmd_runner::CmdRunner, profile::Profile, runner::Runner};
|
use crate::{async_process::async_process, profile::Profile};
|
||||||
use nix::{
|
use nix::{
|
||||||
errno::Errno,
|
errno::Errno,
|
||||||
sys::statvfs::{statvfs, FsFlags},
|
sys::statvfs::{statvfs, FsFlags},
|
||||||
|
@ -74,10 +74,11 @@ pub fn setcap_cap_sys_nice_eip_cmd(profile: &Profile) -> Vec<String> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setcap_cap_sys_nice_eip(profile: &Profile) {
|
pub async fn setcap_cap_sys_nice_eip(profile: &Profile) {
|
||||||
let mut runner = CmdRunner::new(None, "pkexec".into(), setcap_cap_sys_nice_eip_cmd(profile));
|
if let Err(e) = async_process("pkexec", Some(&setcap_cap_sys_nice_eip_cmd(profile)), None).await
|
||||||
runner.start();
|
{
|
||||||
runner.join();
|
eprintln!("Error: failed running setcap: {e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rm_rf(path: &Path) {
|
pub fn rm_rf(path: &Path) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ fn main() -> Result<()> {
|
||||||
0
|
0
|
||||||
});
|
});
|
||||||
let app = RelmApp::from_app(main_app.clone()).with_broker(&BROKER);
|
let app = RelmApp::from_app(main_app.clone()).with_broker(&BROKER);
|
||||||
app.run::<App>(AppInit {
|
app.run_async::<App>(AppInit {
|
||||||
application: main_app,
|
application: main_app,
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -55,7 +55,6 @@ use relm4::{
|
||||||
actions::{AccelsPlus, ActionGroupName, RelmAction, RelmActionGroup},
|
actions::{AccelsPlus, ActionGroupName, RelmAction, RelmActionGroup},
|
||||||
new_action_group, new_stateful_action, new_stateless_action,
|
new_action_group, new_stateful_action, new_stateless_action,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
{ComponentParts, ComponentSender, SimpleComponent},
|
|
||||||
};
|
};
|
||||||
use std::{collections::VecDeque, fs::remove_file, time::Duration};
|
use std::{collections::VecDeque, fs::remove_file, time::Duration};
|
||||||
|
|
||||||
|
@ -150,7 +149,7 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_xrservice(&mut self, sender: ComponentSender<Self>, debug: bool) {
|
pub fn start_xrservice(&mut self, sender: AsyncComponentSender<Self>, debug: bool) {
|
||||||
self.xrservice_ready = false;
|
self.xrservice_ready = false;
|
||||||
let prof = self.get_selected_profile();
|
let prof = self.get_selected_profile();
|
||||||
if let Err(e) = set_current_active_runtime_to_profile(&prof) {
|
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<Self>) {
|
pub fn run_autostart(&mut self, sender: AsyncComponentSender<Self>) {
|
||||||
let prof = self.get_selected_profile();
|
let prof = self.get_selected_profile();
|
||||||
if let Some(autostart_cmd) = &prof.autostart_command {
|
if let Some(autostart_cmd) = &prof.autostart_command {
|
||||||
let mut jobs = VecDeque::new();
|
let mut jobs = VecDeque::new();
|
||||||
|
@ -281,11 +280,12 @@ pub struct AppInit {
|
||||||
pub application: adw::Application,
|
pub application: adw::Application,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[relm4::component(pub)]
|
#[relm4::component(pub async)]
|
||||||
impl SimpleComponent for App {
|
impl AsyncComponent for App {
|
||||||
type Init = AppInit;
|
type Init = AppInit;
|
||||||
type Input = Msg;
|
type Input = Msg;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
type CommandOutput = ();
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
#[root]
|
#[root]
|
||||||
|
@ -321,7 +321,12 @@ impl SimpleComponent for App {
|
||||||
self.restore_openxr_openvr_files();
|
self.restore_openxr_openvr_files();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
|
async fn update(
|
||||||
|
&mut self,
|
||||||
|
message: Self::Input,
|
||||||
|
sender: AsyncComponentSender<Self>,
|
||||||
|
_root: &Self::Root,
|
||||||
|
) {
|
||||||
match message {
|
match message {
|
||||||
Msg::NoOp => {}
|
Msg::NoOp => {}
|
||||||
Msg::OnServiceLog(rows) => {
|
Msg::OnServiceLog(rows) => {
|
||||||
|
@ -604,7 +609,7 @@ impl SimpleComponent for App {
|
||||||
println!("pkexec not found, skipping setcap");
|
println!("pkexec not found, skipping setcap");
|
||||||
} else {
|
} else {
|
||||||
let profile = self.get_selected_profile();
|
let profile = self.get_selected_profile();
|
||||||
setcap_cap_sys_nice_eip(&profile);
|
setcap_cap_sys_nice_eip(&profile).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Msg::ProfileSelected(prof) => {
|
Msg::ProfileSelected(prof) => {
|
||||||
|
@ -738,11 +743,11 @@ impl SimpleComponent for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(
|
async fn init(
|
||||||
init: Self::Init,
|
init: Self::Init,
|
||||||
root: Self::Root,
|
root: Self::Root,
|
||||||
sender: ComponentSender<Self>,
|
sender: AsyncComponentSender<Self>,
|
||||||
) -> ComponentParts<Self> {
|
) -> AsyncComponentParts<Self> {
|
||||||
let config = Config::get_config();
|
let config = Config::get_config();
|
||||||
let win_size = config.win_size;
|
let win_size = config.win_size;
|
||||||
let profiles = config.profiles();
|
let profiles = config.profiles();
|
||||||
|
@ -965,7 +970,7 @@ impl SimpleComponent for App {
|
||||||
|
|
||||||
model.split_view = Some(widgets.split_view.clone());
|
model.split_view = Some(widgets.split_view.clone());
|
||||||
|
|
||||||
ComponentParts { model, widgets }
|
AsyncComponentParts { model, widgets }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue