Skip to content

Commit

Permalink
added core sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
jhideki committed Apr 21, 2024
1 parent f196915 commit 64a4efa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
child: Option<CommandChild>,
}

impl CoreProcess {
Expand All @@ -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");
}
}
Expand Down
12 changes: 10 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +29,7 @@
"deb": {
"depends": []
},
"externalBin": [],
"externalBin": ["../target/x86_64-pc-windows-msvc/release/whirlwincore"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand Down

0 comments on commit 64a4efa

Please sign in to comment.