Konata fix for Unix
This commit is contained in:
parent
ac484fdea8
commit
fdaacaa6f3
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1701,6 +1701,7 @@ dependencies = [
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-plugin-dialog",
|
"tauri-plugin-dialog",
|
||||||
"tauri-plugin-window-state",
|
"tauri-plugin-window-state",
|
||||||
|
"tokio",
|
||||||
"wasmtime",
|
"wasmtime",
|
||||||
"wasmtime-wasi",
|
"wasmtime-wasi",
|
||||||
"wellen",
|
"wellen",
|
||||||
|
|
|
@ -26,6 +26,7 @@ tauri-plugin-dialog = "=2.0.0-beta.9"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
reqwest = "0.12.9"
|
reqwest = "0.12.9"
|
||||||
|
tokio = "*"
|
||||||
|
|
||||||
# wasmtime = "22.0.0"
|
# wasmtime = "22.0.0"
|
||||||
# wasmtime-wasi = "22.0.0"
|
# wasmtime-wasi = "22.0.0"
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::sync::{Arc, RwLock as StdRwLock};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tauri::{async_runtime::RwLock, AppHandle};
|
use tauri::{async_runtime::RwLock, AppHandle};
|
||||||
use tauri_plugin_dialog::DialogExt;
|
use tauri_plugin_dialog::DialogExt;
|
||||||
|
use tokio::time::sleep;
|
||||||
use wasmtime::AsContextMut;
|
use wasmtime::AsContextMut;
|
||||||
use wellen::simple::Waveform;
|
use wellen::simple::Waveform;
|
||||||
|
|
||||||
|
@ -188,20 +189,40 @@ async fn open_konata_file(app: tauri::AppHandle) {
|
||||||
};
|
};
|
||||||
let file_path = file_response.path.into_os_string().into_string().unwrap();
|
let file_path = file_response.path.into_os_string().into_string().unwrap();
|
||||||
|
|
||||||
spawn_konata_app();
|
|
||||||
|
|
||||||
let port = 30000;
|
let port = 30000;
|
||||||
let base_url = format!("http://localhost:{port}");
|
let base_url = format!("http://localhost:{port}");
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(30))
|
.connect_timeout(Duration::from_secs(1))
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if client
|
|
||||||
|
let mut konata_server_ready = false;
|
||||||
|
|
||||||
|
let is_konata_server_ready = || async {
|
||||||
|
client
|
||||||
.get(format!("{base_url}/status"))
|
.get(format!("{base_url}/status"))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
};
|
||||||
|
|
||||||
|
if is_konata_server_ready().await {
|
||||||
|
konata_server_ready = true;
|
||||||
|
} else {
|
||||||
|
spawn_konata_app();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut attempts = 1;
|
||||||
|
while !konata_server_ready {
|
||||||
|
attempts += 1;
|
||||||
|
if attempts > 5 {
|
||||||
|
eprintln!("Failed to get Konata server status (5 attempts)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
konata_server_ready = is_konata_server_ready().await;
|
||||||
|
sleep(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
|
||||||
client
|
client
|
||||||
.post(format!("{base_url}/open-konata-file"))
|
.post(format!("{base_url}/open-konata-file"))
|
||||||
.json(&serde_json::json!({
|
.json(&serde_json::json!({
|
||||||
|
@ -212,15 +233,12 @@ async fn open_konata_file(app: tauri::AppHandle) {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.error_for_status()
|
.error_for_status()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else {
|
|
||||||
println!("Failed to get Konata server status");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
fn spawn_konata_app() {
|
fn spawn_konata_app() {
|
||||||
Command::new("cscript")
|
Command::new("cscript")
|
||||||
.current_dir("../../konata")
|
.current_dir("../../Konata")
|
||||||
.arg("konata.vbs")
|
.arg("konata.vbs")
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -229,7 +247,7 @@ fn spawn_konata_app() {
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
fn spawn_konata_app() {
|
fn spawn_konata_app() {
|
||||||
Command::new("sh")
|
Command::new("sh")
|
||||||
.current_dir("../../konata")
|
.current_dir("../../Konata")
|
||||||
.arg("konata.sh")
|
.arg("konata.sh")
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Reference in a new issue