mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
add detection of installed tools in host environment
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use crate::gtk::Align;
|
||||
use crate::util::prerequisit::get_installed_terminals;
|
||||
use crate::util::prerequisit::is_toolbox_installed;
|
||||
|
||||
use crate::util::toolbox::ToolbxContainer;
|
||||
use relm4::adw::prelude::PreferencesGroupExt;
|
||||
use relm4::factory::FactoryHashMap;
|
||||
@@ -181,8 +184,9 @@ impl Component for App {
|
||||
};
|
||||
|
||||
sender.spawn_oneshot_command(|| {
|
||||
// TODO: actually check for compatibility
|
||||
AppCommandMsg::PrerequisitsInstalled(true)
|
||||
let terminals = get_installed_terminals().unwrap_or_default();
|
||||
let toolbox_installed = is_toolbox_installed().unwrap_or(false);
|
||||
AppCommandMsg::PrerequisitsInstalled(terminals.len() > 0 && toolbox_installed)
|
||||
});
|
||||
|
||||
actions.add_action(shortcuts_action);
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod prerequisit;
|
||||
pub mod toolbox;
|
||||
|
||||
51
src/util/prerequisit.rs
Normal file
51
src/util/prerequisit.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use crate::util::toolbox::ToolbxError;
|
||||
use std::process::Command;
|
||||
|
||||
pub enum TerminalType {
|
||||
GnomeTerminal,
|
||||
}
|
||||
|
||||
pub fn get_installed_terminals() -> Result<Vec<TerminalType>, ToolbxError> {
|
||||
let output = Command::new("flatpak-spawn")
|
||||
.arg("--host")
|
||||
.arg("gnome-terminal")
|
||||
.arg("--version")
|
||||
.output();
|
||||
|
||||
if output.is_err() {
|
||||
return Err(ToolbxError::CommandExecutionError(
|
||||
output.unwrap_err().to_string(),
|
||||
));
|
||||
}
|
||||
let output = output.unwrap();
|
||||
|
||||
if output.status.code() == Some(0) {
|
||||
Ok(vec![TerminalType::GnomeTerminal])
|
||||
} else {
|
||||
Err(ToolbxError::CommandUnsuccessfulError(
|
||||
String::from_utf8_lossy(&output.stderr).into_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_toolbox_installed() -> Result<bool, ToolbxError> {
|
||||
let output = Command::new("flatpak-spawn")
|
||||
.arg("--host")
|
||||
.arg("toolbox")
|
||||
.arg("--version")
|
||||
.output();
|
||||
|
||||
if output.is_err() {
|
||||
return Err(ToolbxError::CommandExecutionError(
|
||||
output.unwrap_err().to_string(),
|
||||
));
|
||||
}
|
||||
let output = output.unwrap();
|
||||
if output.status.code() == Some(0) {
|
||||
Ok(true)
|
||||
} else {
|
||||
Err(ToolbxError::CommandUnsuccessfulError(
|
||||
String::from_utf8_lossy(&output.stderr).into_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{fmt::Display, process::Command, str::FromStr};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -138,6 +137,7 @@ pub fn start_toolbox_container(hash: &str) -> Result<(), ToolbxError> {
|
||||
.output();
|
||||
|
||||
if output.is_err() {
|
||||
dbg!(&output);
|
||||
return Err(ToolbxError::CommandExecutionError(
|
||||
output.unwrap_err().to_string(),
|
||||
));
|
||||
@@ -155,6 +155,7 @@ pub fn start_toolbox_container(hash: &str) -> Result<(), ToolbxError> {
|
||||
if output.status.code() == Some(0) {
|
||||
Ok(())
|
||||
} else {
|
||||
dbg!(&output);
|
||||
Err(ToolbxError::CommandUnsuccessfulError(
|
||||
String::from_utf8_lossy(&output.stderr).into_owned(),
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user