Route all app commands through a single RPC envelope (#542)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Gregory Schier
2026-08-14 14:16:14 -07:00
committed by GitHub
co-authored by Claude Fable 5
parent 1f91cddab9
commit 23e7229e63
37 changed files with 2473 additions and 395 deletions
+14 -15
View File
@@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize};
use std::path::Path;
use std::sync::mpsc;
use std::time::Duration;
use tauri::ipc::Channel;
use tauri::{AppHandle, Listener, Runtime};
use tokio::select;
use tokio::sync::watch;
@@ -23,11 +22,15 @@ pub(crate) struct GitWatchResult {
unlisten_event: String,
}
pub(crate) async fn watch_git_worktree_status<R: Runtime>(
pub(crate) async fn watch_git_worktree_status<R, F>(
app_handle: AppHandle<R>,
dir: &Path,
channel: Channel<GitWorktreeStatus>,
) -> Result<GitWatchResult> {
on_status: F,
) -> Result<GitWatchResult>
where
R: Runtime,
F: Fn(GitWorktreeStatus) + Send + Sync + 'static,
{
let paths = git_repository_paths(dir)?;
let repo_dir = dir.to_path_buf();
let workdir = paths.workdir;
@@ -76,7 +79,7 @@ pub(crate) async fn watch_git_worktree_status<R: Runtime>(
let (cancel_tx, cancel_rx) = watch::channel(());
let mut cancel_rx = cancel_rx;
send_worktree_status(&repo_dir, &channel);
send_worktree_status(&repo_dir, &on_status);
tauri::async_runtime::spawn(async move {
let _watcher = watcher;
@@ -90,7 +93,7 @@ pub(crate) async fn watch_git_worktree_status<R: Runtime>(
&workdir,
&gitdir,
&commondir,
&channel,
&on_status,
).await;
}
_ = cancel_rx.changed() => {
@@ -119,13 +122,13 @@ async fn handle_git_watch_event(
workdir: &Path,
gitdir: &Path,
commondir: &Path,
channel: &Channel<GitWorktreeStatus>,
on_status: &impl Fn(GitWorktreeStatus),
) {
if !is_relevant_git_watch_event(event_res, repo_dir, workdir, gitdir, commondir) {
return;
}
send_worktree_status(repo_dir, channel);
send_worktree_status(repo_dir, on_status);
let settle_window = sleep(GIT_STATUS_COALESCE_WINDOW);
tokio::pin!(settle_window);
@@ -140,7 +143,7 @@ async fn handle_git_watch_event(
}
}
send_worktree_status(repo_dir, channel);
send_worktree_status(repo_dir, on_status);
}
fn is_relevant_git_watch_event(
@@ -180,13 +183,9 @@ fn is_relevant_git_watch_event(
false
}
fn send_worktree_status(repo_dir: &Path, channel: &Channel<GitWorktreeStatus>) {
fn send_worktree_status(repo_dir: &Path, on_status: &impl Fn(GitWorktreeStatus)) {
match git_worktree_status(repo_dir) {
Ok(status) => {
if let Err(e) = channel.send(status) {
warn!("Failed to send git worktree status: {:?}", e);
}
}
Ok(status) => on_status(status),
Err(e) => {
warn!("Failed to get git worktree status: {e}");
}