diff --git a/gui/src-tauri/.gitignore b/gui/src-tauri/.gitignore new file mode 100644 index 0000000..4cacddf --- /dev/null +++ b/gui/src-tauri/.gitignore @@ -0,0 +1,2 @@ +/target +/gen diff --git a/gui/src-tauri/Cargo.toml b/gui/src-tauri/Cargo.toml new file mode 100644 index 0000000..66ee7d6 --- /dev/null +++ b/gui/src-tauri/Cargo.toml @@ -0,0 +1,19 @@ +# Tauri shell for the grove GUI. Deliberately NOT a member of the root workspace: it needs the +# webkit2gtk/libsoup system packages (see docs/phase3.md) and must not break `cargo test` without them. +[package] +name = "grove-gui" +version = "0.1.0" +edition = "2024" +license = "MIT" +description = "grove desktop GUI (Tauri shell around gui/ui)" + +[workspace] + +[dependencies] +grove-bridge = { path = "../../crates/grove-bridge" } +grove-daemon = { path = "../../crates/grove-daemon" } +serde_json = "1" +tauri = { version = "2", features = ["tray-icon"] } + +[build-dependencies] +tauri-build = "2" diff --git a/gui/src-tauri/build.rs b/gui/src-tauri/build.rs new file mode 100644 index 0000000..d860e1e --- /dev/null +++ b/gui/src-tauri/build.rs @@ -0,0 +1,3 @@ +fn main() { + tauri_build::build() +} diff --git a/gui/src-tauri/capabilities/default.json b/gui/src-tauri/capabilities/default.json new file mode 100644 index 0000000..e9b9f39 --- /dev/null +++ b/gui/src-tauri/capabilities/default.json @@ -0,0 +1,7 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "Main window: only the app's own commands, no filesystem or shell access.", + "windows": ["main"], + "permissions": ["core:default"] +} diff --git a/gui/src-tauri/icons/icon.png b/gui/src-tauri/icons/icon.png new file mode 100644 index 0000000..76c0e69 Binary files /dev/null and b/gui/src-tauri/icons/icon.png differ diff --git a/gui/src-tauri/src/main.rs b/gui/src-tauri/src/main.rs new file mode 100644 index 0000000..2af493c --- /dev/null +++ b/gui/src-tauri/src/main.rs @@ -0,0 +1,79 @@ +//! Tauri shell: serves `gui/ui` and exposes the same three calls the dev bridge offers +//! (`ipc`, `cli`, `config`) as Tauri commands, backed by the shared `grove-bridge` library. +//! Also a tray icon with open / pause-resume / quit so the window can be closed. + +use grove_bridge::Bridge; +use serde_json::{Value, json}; +use tauri::menu::{Menu, MenuItem}; +use tauri::tray::TrayIconBuilder; +use tauri::{Manager, WindowEvent}; + +fn bridge() -> Bridge { + Bridge { + grove_bin: std::env::var_os("GROVE_BIN") + .map(Into::into) + .unwrap_or_else(|| "grove".into()), + config: None, + socket: grove_daemon::ipc::default_socket_path(), + } +} + +#[tauri::command] +fn ipc(req: Value) -> Value { + bridge().ipc(&req) +} + +#[tauri::command] +fn cli(args: Vec, stdin: Option) -> Value { + bridge().cli(&args, &stdin.unwrap_or_default()) +} + +#[tauri::command] +fn config() -> Value { + match bridge().config_json() { + Some(c) => json!({"exists": true, "config": c}), + None => json!({"exists": false}), + } +} + +fn main() { + tauri::Builder::default() + .invoke_handler(tauri::generate_handler![ipc, cli, config]) + .setup(|app| { + let open = MenuItem::with_id(app, "open", "Open Grove", true, None::<&str>)?; + let pause = MenuItem::with_id(app, "pause", "Pause / resume sync", true, None::<&str>)?; + let quit = MenuItem::with_id(app, "quit", "Quit GUI (daemon keeps running)", true, None::<&str>)?; + let menu = Menu::with_items(app, &[&open, &pause, &quit])?; + TrayIconBuilder::new() + .icon(app.default_window_icon().cloned().expect("window icon")) + .menu(&menu) + .on_menu_event(|app, ev| match ev.id.as_ref() { + "open" => { + if let Some(w) = app.get_webview_window("main") { + let _ = w.show(); + let _ = w.set_focus(); + } + } + "pause" => { + let b = bridge(); + let paused = b.ipc(&json!({"v":1,"cmd":"status"}))["data"]["paused"] + .as_bool() + .unwrap_or(false); + b.ipc(&json!({"v":1,"cmd": if paused {"resume"} else {"pause"}})); + } + "quit" => app.exit(0), + _ => {} + }) + .build(app)?; + Ok(()) + }) + // Closing the window hides it; the tray keeps the app (and its notifications) alive. + .on_window_event(|w, ev| { + if let WindowEvent::CloseRequested { api, .. } = ev { + api.prevent_close(); + let _ = w.hide(); + } + }) + .run(tauri::generate_context!()) + .expect("error while running grove-gui"); +} diff --git a/gui/src-tauri/tauri.conf.json b/gui/src-tauri/tauri.conf.json new file mode 100644 index 0000000..d52dad4 --- /dev/null +++ b/gui/src-tauri/tauri.conf.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://schema.tauri.app/config/2", + "productName": "Grove", + "version": "0.1.0", + "identifier": "es.zenvairo.grove", + "build": { "frontendDist": "../ui" }, + "app": { + "withGlobalTauri": true, + "windows": [{ "title": "Grove", "width": 1100, "height": 720, "minWidth": 720, "minHeight": 480 }], + "security": { + "csp": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" + } + }, + "bundle": { + "active": true, + "targets": ["deb", "appimage"], + "icon": ["icons/icon.png"], + "category": "DeveloperTool" + } +}