mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-04-27 16:09:58 -07:00
implement installer as library and use it in gui
This commit is contained in:
committed by
Markus Unterwaditzer
parent
9e9fe4d392
commit
3b44234ae1
@@ -22,4 +22,4 @@ serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tauri-plugin-shell = "2"
|
||||
anyhow = "1.0.100"
|
||||
|
||||
installer = { path = "../../installer" }
|
||||
|
||||
@@ -1,52 +1,3 @@
|
||||
use std::env::consts::EXE_SUFFIX;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
println!("cargo::rerun-if-env-changed=INSTALLER_PATH");
|
||||
println!("cargo::rerun-if-env-changed=SKIP_INSTALLER_COPY");
|
||||
|
||||
let destination = get_installer_destination();
|
||||
if std::env::var_os("SKIP_INSTALLER_COPY").is_none() {
|
||||
let cli_installer =
|
||||
std::env::var_os("INSTALLER_PATH").map_or_else(default_installer_path, PathBuf::from);
|
||||
if !cli_installer.exists() {
|
||||
println!(
|
||||
"cargo::error=CLI installer binary not present at {}",
|
||||
cli_installer.display()
|
||||
);
|
||||
std::process::exit(0);
|
||||
}
|
||||
std::fs::copy(&cli_installer, &destination).unwrap();
|
||||
println!("cargo::rerun-if-changed={}", cli_installer.display());
|
||||
println!("cargo::rerun-if-changed={}", destination.display());
|
||||
} else if !destination.exists() {
|
||||
// if SKIP_INSTALLER_COPY is set, make sure something exists at destination so the build succeeds
|
||||
std::fs::write(&destination, []).unwrap();
|
||||
}
|
||||
|
||||
tauri_build::build()
|
||||
}
|
||||
|
||||
fn default_installer_path() -> PathBuf {
|
||||
// the approach used here was taken from https://github.com/rust-lang/cargo/issues/9661#issuecomment-1722358176
|
||||
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
let profile = std::env::var("PROFILE").unwrap();
|
||||
let profile_dir = out_dir
|
||||
.ancestors()
|
||||
.find(|&path| path.ends_with(&profile))
|
||||
.unwrap();
|
||||
|
||||
profile_dir.join(format!("installer{EXE_SUFFIX}"))
|
||||
}
|
||||
|
||||
fn get_installer_destination() -> PathBuf {
|
||||
// tauri expects included binaries to have the target triple appended to the file name like
|
||||
// this. see https://tauri.app/develop/sidecar/
|
||||
let target_triple = std::env::var("TARGET").unwrap();
|
||||
[
|
||||
"binaries",
|
||||
&format!("installer-cli-{target_triple}{EXE_SUFFIX}"),
|
||||
]
|
||||
.iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -1,29 +1,18 @@
|
||||
use anyhow::Context;
|
||||
use tauri::Emitter;
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
use tauri_plugin_shell::process::CommandEvent;
|
||||
|
||||
async fn run_installer(app_handle: tauri::AppHandle, args: String) -> anyhow::Result<()> {
|
||||
let (mut rx, _child) = app_handle
|
||||
.shell()
|
||||
.sidecar("installer-cli")
|
||||
.context("Error preparing Rayhunter CLI installer to be run")?
|
||||
.args(args.split_whitespace())
|
||||
.spawn()
|
||||
.context("Error launching Rayhunter CLI installer")?;
|
||||
while let Some(event) = rx.recv().await {
|
||||
match event {
|
||||
CommandEvent::Stdout(line_bytes) | CommandEvent::Stderr(line_bytes) => {
|
||||
let line = String::from_utf8(line_bytes)
|
||||
.context("Error parsing Rayhunter CLI installer output")?;
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
installer::run_with_callback(
|
||||
// TODO: we should split using something similar to shlex in python
|
||||
args.split_whitespace().map(String::from).collect(),
|
||||
Some(Box::new(move |output| {
|
||||
app_handle
|
||||
.emit("installer-output", &line)
|
||||
.context("Error sending Rayhunter CLI installer output to GUI frontend")?;
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
.emit("installer-output", output)
|
||||
.expect("Error sending Rayhunter CLI installer output to GUI frontend");
|
||||
})),
|
||||
)
|
||||
})
|
||||
.await?
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": ["app", "appimage", "deb", "msi", "nsis", "rpm"],
|
||||
"externalBin": ["binaries/installer-cli"],
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
|
||||
Reference in New Issue
Block a user