feat(status-ui): improve bridge recovery and desktop controls

This commit is contained in:
2026-07-28 21:15:25 +02:00
parent 7cc15cca92
commit a792c577ef
23 changed files with 1336 additions and 204 deletions
+10
View File
@@ -100,6 +100,16 @@ pub async fn select_worktree(socket_path: &str, worktree_path: &str) -> Result<V
.await
}
pub async fn forget_directory(socket_path: &str, worktree_path: &str) -> Result<Value, String> {
request(
socket_path,
"forget_directory",
None,
Some(json!({ "worktreePath": worktree_path })),
)
.await
}
pub async fn list_sessions(socket_path: &str, agent_id: &str) -> Result<Value, String> {
request(socket_path, "list_sessions", Some(agent_id), None).await
}
+46 -3
View File
@@ -6,6 +6,22 @@ use tauri::{async_runtime::JoinHandle, AppHandle, Emitter, Manager, State};
struct Subscription(Mutex<Option<JoinHandle<()>>>);
#[derive(Debug, PartialEq, Eq)]
enum WindowAction {
Hide,
ShowAndFocus,
}
fn window_action(args: &[String], is_visible: bool) -> WindowAction {
if args.iter().any(|arg| arg == "--hide")
|| (args.iter().any(|arg| arg == "--toggle") && is_visible)
{
WindowAction::Hide
} else {
WindowAction::ShowAndFocus
}
}
fn socket_path() -> Result<String, String> {
bridge::default_socket_path()
}
@@ -25,6 +41,11 @@ async fn select_worktree(worktree_path: String) -> Result<Value, String> {
bridge::select_worktree(&socket_path()?, &worktree_path).await
}
#[tauri::command]
async fn forget_directory(worktree_path: String) -> Result<Value, String> {
bridge::forget_directory(&socket_path()?, &worktree_path).await
}
#[tauri::command]
async fn load_agent(agent_id: String) -> Result<Value, String> {
bridge::load_agent(&socket_path()?, &agent_id).await
@@ -121,16 +142,24 @@ fn subscribe_agent(
pub fn run() {
let builder = tauri::Builder::default()
.manage(Subscription(Mutex::new(None)))
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
match window_action(&args, window.is_visible().unwrap_or(false)) {
WindowAction::Hide => {
let _ = window.hide();
}
WindowAction::ShowAndFocus => {
let _ = window.show();
let _ = window.set_focus();
}
}
}
}))
.invoke_handler(tauri::generate_handler![
list_agents,
list_directories,
select_worktree,
forget_directory,
load_agent,
list_sessions,
switch_session,
@@ -149,3 +178,17 @@ pub fn run() {
eprintln!("Pi Status UI exited: {error}");
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn toggle_hides_a_visible_window_and_shows_a_hidden_window() {
let toggle = vec!["--toggle".to_owned()];
assert_eq!(window_action(&toggle, true), WindowAction::Hide);
assert_eq!(window_action(&toggle, false), WindowAction::ShowAndFocus);
assert_eq!(window_action(&vec!["--show".to_owned()], true), WindowAction::ShowAndFocus);
}
}