Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,24 @@ fn create_branch(repo: String, name: String, checkout: bool) -> AppResult<()> {
branch::create_branch(&open(&repo)?, &name, checkout)
}

#[tauri::command]
// Network ops block for seconds (remote IO). `(async)` runs them on a worker
// thread so they don't freeze the UI/IPC - same rationale as the reads above.
#[tauri::command(async)]
fn push(repo: String) -> AppResult<String> {
ops::push(&open(&repo)?)
}

#[tauri::command]
#[tauri::command(async)]
fn push_force(repo: String) -> AppResult<String> {
ops::push_force(&open(&repo)?)
}

#[tauri::command]
#[tauri::command(async)]
fn pull(repo: String, mode: String) -> AppResult<String> {
ops::pull(&open(&repo)?, &mode)
}

#[tauri::command]
#[tauri::command(async)]
fn fetch(repo: String) -> AppResult<String> {
ops::fetch(&open(&repo)?)
}
Expand Down
18 changes: 11 additions & 7 deletions src/components/RepoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,20 @@ export default function RepoView({ path, isActive, onLoaded, onOpenPath }: Props

const run = useCallback(
async (fn: () => Promise<void>, action?: string) => {
// Re-entrancy guard: one op at a time. busyRef is set synchronously (not
// via the `busy` state, which lags a render) so a rapid double-trigger -
// e.g. hitting the pull/push keyboard shortcut twice - can't launch two
// concurrent git ops racing on the same .git lock files.
if (busyRef.current) return;
busyRef.current = true;
setBusy(true);
setActiveAction(action ?? null);
try {
await fn();
} catch (e) {
notify(String(e), true);
} finally {
busyRef.current = false;
setBusy(false);
setActiveAction(null);
}
Expand Down Expand Up @@ -778,13 +785,10 @@ export default function RepoView({ path, isActive, onLoaded, onOpenPath }: Props
return () => window.removeEventListener("keydown", onKey);
}, [isActive, onPush, onPullAction]);

// Auto-fetch: mirror `busy` into a ref, re-read the setting on a prefs change,
// and run a background fetch on the active tab at the chosen interval. Skips a
// tick while an op is in flight or the window is hidden, and never toasts on
// failure (a background fetch offline shouldn't nag).
useEffect(() => {
busyRef.current = busy;
}, [busy]);
// Auto-fetch: re-read the setting on a prefs change, and run a background
// fetch on the active tab at the chosen interval. Skips a tick while an op is
// in flight (busyRef, owned by run()) or the window is hidden, and never
// toasts on failure (a background fetch offline shouldn't nag).
useEffect(() => {
const onPrefs = () => setAutoFetchTick((t) => t + 1);
window.addEventListener("gitchef:prefs", onPrefs);
Expand Down