kiosk_core/event.rs
1use std::{collections::HashMap, path::PathBuf};
2
3use crate::{
4 agent::AgentStatus,
5 git::{Repo, Worktree},
6};
7
8/// Events that arrive asynchronously from background tasks.
9/// These get merged into the main event loop alongside keyboard input.
10#[derive(Debug, Clone)]
11pub enum AppEvent {
12 /// Repository discovery completed (full batch — replaces repo list)
13 ReposDiscovered {
14 repos: Vec<Repo>,
15 session_activity: HashMap<String, u64>,
16 },
17
18 /// Single repo discovered during streaming scan (appended to existing list)
19 ReposFound { repo: Repo },
20
21 /// All scan threads finished — triggers collision resolution and final sort.
22 /// Carries `search_dirs` so collision resolution can use the correct search dir names.
23 ScanComplete { search_dirs: Vec<(PathBuf, u16)> },
24
25 /// A background git operation completed successfully
26 WorktreeCreated { path: PathBuf, session_name: String },
27
28 /// A worktree was successfully removed
29 WorktreeRemoved {
30 branch_name: String,
31 worktree_path: PathBuf,
32 },
33
34 /// A worktree removal failed
35 WorktreeRemoveFailed {
36 branch_name: String,
37 worktree_path: PathBuf,
38 error: String,
39 },
40
41 /// Local branches loaded
42 BranchesLoaded {
43 branches: Vec<crate::state::BranchEntry>,
44 worktrees: Vec<crate::git::Worktree>,
45 /// Local branch names, needed to spawn remote branch loading
46 local_names: Vec<String>,
47 /// Session activity timestamps
48 session_activity: HashMap<String, u64>,
49 },
50
51 /// Remote branches loaded (appended after local)
52 RemoteBranchesLoaded {
53 branches: Vec<crate::state::BranchEntry>,
54 },
55
56 /// Background git fetch completed for one remote (or all remotes if `is_final`).
57 GitFetchCompleted {
58 branches: Vec<crate::state::BranchEntry>,
59 repo_path: PathBuf,
60 /// True when this is the last remote to finish, so the UI can clear the spinner.
61 is_final: bool,
62 },
63
64 /// Single repo enriched with worktree data (streamed from phase 2)
65 RepoEnriched {
66 repo_path: PathBuf,
67 worktrees: Vec<Worktree>,
68 },
69
70 /// Session activity data loaded (from tmux, sent once)
71 SessionActivityLoaded {
72 session_activity: HashMap<String, u64>,
73 },
74
75 /// Agent states updated from background detection (full snapshot —
76 /// `None` means no agent detected, allowing stale statuses to be cleared)
77 AgentStatesUpdated {
78 states: Vec<(String, Option<AgentStatus>)>,
79 },
80
81 /// A background git operation failed
82 GitError(String),
83}