From 64a4efa1063260546b33ce7a426887a17ad4090b Mon Sep 17 00:00:00 2001 From: Jonathan Ami <126116089+jonathan-ami@users.noreply.github.com> Date: Sat, 20 Apr 2024 23:14:27 -0700 Subject: [PATCH] added core sidecar --- Cargo.lock | 24 ++++++++++++++++++++++++ src-tauri/Cargo.toml | 2 +- src-tauri/src/main.rs | 13 ++++++------- src-tauri/tauri.conf.json | 12 ++++++++++-- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12f4551..0f65ae6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1681,6 +1681,16 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "os_pipe" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57119c3b893986491ec9aa85056780d3a0f3cf4da7cc09dd3650dbd6c6738fb9" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "overload" version = "0.1.1" @@ -2404,6 +2414,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shared_child" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -2651,15 +2671,18 @@ dependencies = [ "ignore", "objc", "once_cell", + "os_pipe", "percent-encoding", "rand 0.8.5", "raw-window-handle", + "regex", "rfd", "semver", "serde", "serde_json", "serde_repr", "serialize-to-javascript", + "shared_child", "state", "tar", "tauri-macros", @@ -2709,6 +2732,7 @@ dependencies = [ "png", "proc-macro2", "quote", + "regex", "semver", "serde", "serde_json", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4b3b2dd..90bfed3 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,7 @@ tauri-build = { version = "1.5.1", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.6.1", features = ["dialog"] } +tauri = { version = "1.6.1", features = [ "shell-sidecar", "dialog", "process-command-api"] } [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7b290e6..b1b4563 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,17 +2,15 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] mod config; -use config::Config; use config::{read_config, set_data}; -use serde::{Deserialize, Serialize}; -use std::process::{Child, Command}; use std::sync::{Arc, Mutex}; use tauri::api::dialog::FileDialogBuilder; +use tauri::api::process::{Command, CommandChild}; use tauri::State; struct CoreProcess { running: bool, - child: Option, + child: Option, } impl CoreProcess { @@ -24,17 +22,18 @@ impl CoreProcess { } fn start(&mut self) { if self.child.is_none() { - let child = Command::new(r"..\target\release\whirlwin.exe") + let child = Command::new_sidecar("whirlwincore") + .expect("failed to spawn sidecare") .spawn() .expect("Failed to start whirlwin"); - self.child = Some(child); + self.child = Some(child.1); } else { println!("whirlwin is already running"); } } fn stop(&mut self) { println!("whirlwin stopped"); - if let Some(mut child) = self.child.take() { + if let Some(child) = self.child.take() { child.kill().expect("Failed to kill whirlwin"); } } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 72e15df..5be32a5 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -12,7 +12,15 @@ }, "tauri": { "allowlist": { - "all": false + "shell": { + "sidecar": true, + "scope": [ + { + "name": "../target/x86_64-pc-windows-msvc/release/whirlwincore", + "sidecar": true + } + ] + } }, "bundle": { "active": true, @@ -21,7 +29,7 @@ "deb": { "depends": [] }, - "externalBin": [], + "externalBin": ["../target/x86_64-pc-windows-msvc/release/whirlwincore"], "icon": [ "icons/32x32.png", "icons/128x128.png",