feat: initial Tauri desktop shell for BatchTube v1.0
This commit is contained in:
25
src-tauri/Cargo.toml
Normal file
25
src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,25 @@
|
||||
[package]
|
||||
name = "batchtube"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "batchtube_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-shell = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
strip = true
|
||||
3
src-tauri/build.rs
Normal file
3
src-tauri/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
BIN
src-tauri/icons/128x128.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
BIN
src-tauri/icons/128x128@2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
BIN
src-tauri/icons/32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
src-tauri/icons/icon.ico
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 664 B |
8
src-tauri/src/lib.rs
Normal file
8
src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.invoke_handler(tauri::generate_handler![])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
73
src-tauri/src/main.rs
Normal file
73
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
// Prevents additional console window on Windows in release
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use std::sync::Mutex;
|
||||
use tauri::{Manager, State};
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
|
||||
struct ServerProcess(Mutex<Option<tauri_plugin_shell::process::CommandChild>>);
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_server_status() -> String {
|
||||
match reqwest::get("http://localhost:8765/api/health").await {
|
||||
Ok(resp) if resp.status().is_success() => "ready".to_string(),
|
||||
_ => "starting".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.setup(|app| {
|
||||
let handle = app.handle().clone();
|
||||
|
||||
// Spawn the Python backend sidecar
|
||||
let sidecar_command = app.shell().sidecar("batchtube-server").unwrap();
|
||||
let (mut _rx, child) = sidecar_command
|
||||
.spawn()
|
||||
.expect("Failed to spawn BatchTube server");
|
||||
|
||||
// Store process handle for cleanup
|
||||
app.manage(ServerProcess(Mutex::new(Some(child))));
|
||||
|
||||
// Wait for server to be ready, then show window
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let mut attempts = 0;
|
||||
loop {
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
|
||||
if let Ok(resp) = reqwest::get("http://localhost:8765/api/health").await {
|
||||
if resp.status().is_success() {
|
||||
// Server ready — show the main window
|
||||
if let Some(window) = handle.get_webview_window("main") {
|
||||
window.show().unwrap();
|
||||
window.set_focus().unwrap();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
attempts += 1;
|
||||
if attempts > 30 {
|
||||
eprintln!("BatchTube server failed to start after 15 seconds");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
if let tauri::WindowEvent::CloseRequested { .. } = event {
|
||||
// Kill the backend server on window close
|
||||
if let Some(server) = window.app_handle().try_state::<ServerProcess>() {
|
||||
if let Ok(mut guard) = server.0.lock() {
|
||||
if let Some(child) = guard.take() {
|
||||
let _ = child.kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![get_server_status])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running BatchTube");
|
||||
}
|
||||
50
src-tauri/tauri.conf.json
Normal file
50
src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"productName": "BatchTube",
|
||||
"version": "1.0.0",
|
||||
"identifier": "com.intentures.batchtube",
|
||||
"build": {
|
||||
"beforeDevCommand": "",
|
||||
"beforeBuildCommand": "",
|
||||
"devUrl": "http://localhost:8765",
|
||||
"frontendDist": "http://localhost:8765"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "BatchTube",
|
||||
"width": 1200,
|
||||
"height": 800,
|
||||
"minWidth": 900,
|
||||
"minHeight": 600,
|
||||
"resizable": true,
|
||||
"fullscreen": false,
|
||||
"center": true
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"resources": [
|
||||
"../backend/**/*"
|
||||
],
|
||||
"externalBin": [
|
||||
"../backend/batchtube-server"
|
||||
],
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
"digestAlgorithm": "sha256",
|
||||
"timestampUrl": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user