mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 15:26:09 +00:00
feat(gui): Tauri v2 shell with tray (not yet compiled)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2d71d9d413
commit
8e118c90ba
7 files changed
+130
No files matched your search
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
/gen
|
||||
@@ -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"
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
@@ -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"]
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 209 B |
@@ -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<String>, stdin: Option<String>) -> 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");
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user