Skip to content

Commit

Permalink
Feature/rust (#12)
Browse files Browse the repository at this point in the history
* add dashboard tile for Rust
* deploy Rust toolchain with espup
  • Loading branch information
georgik authored Aug 9, 2023
1 parent 26ea5af commit 67756c5
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 21 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@ Check out releases for binary version.
### Features

- Installation of multiple versions of ESP-IDF
- Installation of Rust toolchain for Xtensa and RISC-V ESP32 based chips
- Display available disk space
- Display list of connected ESP32 devices
- Auto-update
- Monitoring
- Flashing


## Development

### Running the application

```
pnpm install
pnpm tauri dev
```

### Release build

```
pnpm tauri build
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "esp-helm",
"private": true,
"version": "0.0.10",
"version": "0.0.11",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ futures = "0.3.28"
reqwest = { version = "0.11", features = ["blocking"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri = { version = "1.4", features = [ "updater", "path-all", "dialog-ask", "dialog-confirm", "dialog-open", "shell-open"] }
tauri = { version = "1.4", features = [ "os-all", "updater", "path-all", "dialog-ask", "dialog-confirm", "dialog-open", "shell-open"] }
tokio = { version = "1.29.1" }
thiserror = "1.0.44"
zip = "0.6.6"
Expand Down
101 changes: 101 additions & 0 deletions src-tauri/src/external_command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use std::io::BufReader;
use std::io::BufRead;
use std::process::Command;
use std::process::Stdio;
use std::thread;
use std::path::Path;
use std::sync::{Mutex};

use tauri::Manager;
use tauri::Window;
use crate::app_state::{AppState, BuilderState};

#[derive(Clone, serde::Serialize)]
struct ConsoleEvent {
message: String,
}

fn is_abort_state(app: tauri::AppHandle) -> bool {
let state_mutex = app.state::<Mutex<AppState>>();
let mut state = state_mutex.lock().unwrap();
match state.builder {
BuilderState::Abort => true,
_ => false
}
}

pub fn emit_rust_console(window: &Window, message: String) {
let event = ConsoleEvent {
message: message,
};
window.emit("rust-console", event).unwrap();
}

pub fn run_external_command_with_progress(
window: Window,
app: tauri::AppHandle,
cmd_name: &str,
cmd_args: &[&str],
progress_event: &str
) -> Result<String, ()> {

// Convert the references to owned data
let cmd_name_owned = cmd_name.to_string();
let cmd_args_owned: Vec<String> = cmd_args.iter().map(|&s| s.to_string()).collect();

let child_handle = thread::spawn(move || {
// Launch the command
let mut child = Command::new(&cmd_name_owned) // Use the owned data here
.args(&cmd_args_owned) // And here
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to launch command");

let stdout = child.stderr.take().unwrap();
let reader = BufReader::new(stdout);

// Read the command's output line by line
for line in reader.lines() {
let line = line.expect("Failed to read line");
println!("{}", line);
// window.emit(progress_event, line).unwrap();
emit_rust_console(&window, line);

// If is_abort_state is true, kill the command
if is_abort_state(app.clone()) {
child.kill().expect("Failed to kill command");
break;
}
}

// window.emit(progress_event, "Done".to_string()).unwrap();
emit_rust_console(&window, "Done".to_string());

// Wait for the child to exit completely
child.wait().expect("Failed to wait on child");
});

// Wait for the child process to finish
child_handle.join().unwrap();

Ok("Success".to_string())
}


#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;

#[cfg(unix)]
pub fn set_exec_permission(path: &std::path::Path) -> std::io::Result<()> {
use std::fs;

let mut perms = fs::metadata(path)?.permissions();
perms.set_mode(0o755); // rwxr-xr-x
fs::set_permissions(path, perms)
}

#[cfg(windows)]
pub fn set_exec_permission(path: &std::path::Path) -> std::io::Result<()> {
todo!()
}
16 changes: 10 additions & 6 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::sync::{Arc, Mutex};
use std::sync::{Mutex};

use dirs;

Expand All @@ -11,19 +11,20 @@ use app_state::{AppState, BuilderState};
mod download;

mod esp_idf;
use esp_idf::{run_install_script};

use esp_idf::run_install_script;
mod external_command;
mod flasher;
mod monitor;
mod rust;
use rust::{check_rust_support, install_rust_support};

mod zip_archiver;
use zip_archiver::{zip_dir, unzip};

use serde::Serialize;
use thiserror;
use tauri::{State, Window};

use sysinfo::{NetworkExt, NetworksExt, ProcessExt, System, SystemExt, DiskExt};
use sysinfo::{System, SystemExt, DiskExt};
use serialport::available_ports;

// Create a custom Error that we can return in Results
Expand Down Expand Up @@ -308,7 +309,10 @@ fn main() {
.invoke_handler(tauri::generate_handler![compress, decompress, download_esp_idf, get_connected_serial_devices, get_disk_usage,
get_user_home, get_esp_idf_list, get_esp_idf_tools_dir, abort_build, run_esp_idf_install_script,
start_flash, stop_flash,
start_monitor, stop_monitor])
start_monitor, stop_monitor,
check_rust_support,
install_rust_support
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Loading

0 comments on commit 67756c5

Please sign in to comment.