Skip to content

Commit 906bc04

Browse files
committed
feat(tui): add update status tracking to AppState
1 parent d4d834a commit 906bc04

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cortex-tui/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ audio = ["dep:rodio"]
1616
# Cortex TUI core (the TUI engine)
1717
cortex-core = { path = "../cortex-core" }
1818

19+
# Auto-update system
20+
cortex-update = { path = "../cortex-update" }
21+
1922
# Centralized TUI components
2023
cortex-tui-components = { path = "../cortex-tui-components" }
2124

src/cortex-tui/src/app/state.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cortex_core::{
77
style::ThemeColors,
88
widgets::{CortexInput, Message},
99
};
10+
use cortex_update::{DownloadProgress, UpdateInfo};
1011
use uuid::Uuid;
1112

1213
use crate::permissions::PermissionMode;
@@ -22,6 +23,68 @@ use super::streaming::StreamingState;
2223
use super::subagent::SubagentTaskDisplay;
2324
use super::types::{AppView, FocusTarget, OperationMode};
2425

26+
/// Status of the auto-update system
27+
#[derive(Debug, Clone, Default, PartialEq, Eq)]
28+
pub enum UpdateStatus {
29+
/// No update check performed yet
30+
#[default]
31+
NotChecked,
32+
/// Currently checking for updates
33+
Checking,
34+
/// An update is available
35+
Available {
36+
/// The new version available
37+
version: String,
38+
},
39+
/// Currently downloading the update
40+
Downloading {
41+
/// The version being downloaded
42+
version: String,
43+
/// Download progress percentage (0-100)
44+
progress: u8,
45+
},
46+
/// Download complete, restart required
47+
ReadyToRestart {
48+
/// The version that was downloaded
49+
version: String,
50+
},
51+
/// Update check failed (network error, etc.)
52+
CheckFailed {
53+
/// Error message
54+
error: String,
55+
},
56+
/// Already on the latest version
57+
UpToDate,
58+
}
59+
60+
impl UpdateStatus {
61+
/// Returns true if an update notification should be shown
62+
pub fn should_show_banner(&self) -> bool {
63+
matches!(
64+
self,
65+
UpdateStatus::Available { .. }
66+
| UpdateStatus::Downloading { .. }
67+
| UpdateStatus::ReadyToRestart { .. }
68+
)
69+
}
70+
71+
/// Get the banner text for the current status
72+
pub fn banner_text(&self) -> Option<String> {
73+
match self {
74+
UpdateStatus::Available { version } => {
75+
Some(format!("A new version ({}) is available", version))
76+
}
77+
UpdateStatus::Downloading { progress, .. } => {
78+
Some(format!("Downloading update... {}%", progress))
79+
}
80+
UpdateStatus::ReadyToRestart { .. } => {
81+
Some("You must restart to run the latest version".to_string())
82+
}
83+
_ => None,
84+
}
85+
}
86+
}
87+
2588
/// Main application state
2689
pub struct AppState {
2790
pub view: AppView,
@@ -172,6 +235,10 @@ pub struct AppState {
172235
pub user_email: Option<String>,
173236
/// Organization name for welcome screen
174237
pub org_name: Option<String>,
238+
/// Current update status for the banner notification
239+
pub update_status: UpdateStatus,
240+
/// Cached update info when an update is available
241+
pub update_info: Option<cortex_update::UpdateInfo>,
175242
}
176243

177244
impl AppState {
@@ -272,6 +339,8 @@ impl AppState {
272339
user_name: None,
273340
user_email: None,
274341
org_name: None,
342+
update_status: UpdateStatus::default(),
343+
update_info: None,
275344
}
276345
}
277346

@@ -679,3 +748,39 @@ impl AppState {
679748
self.diff_scroll = (self.diff_scroll + delta).max(0);
680749
}
681750
}
751+
752+
// ============================================================================
753+
// APPSTATE METHODS - Update Status
754+
// ============================================================================
755+
756+
impl AppState {
757+
/// Set the update status
758+
pub fn set_update_status(&mut self, status: UpdateStatus) {
759+
self.update_status = status;
760+
}
761+
762+
/// Set update info when an update is available
763+
pub fn set_update_info(&mut self, info: Option<cortex_update::UpdateInfo>) {
764+
self.update_info = info;
765+
}
766+
767+
/// Check if an update banner should be shown
768+
pub fn should_show_update_banner(&self) -> bool {
769+
self.update_status.should_show_banner()
770+
}
771+
772+
/// Get the update banner text if one should be shown
773+
pub fn get_update_banner_text(&self) -> Option<String> {
774+
self.update_status.banner_text()
775+
}
776+
777+
/// Update download progress
778+
pub fn update_download_progress(&mut self, progress: u8) {
779+
if let UpdateStatus::Downloading { version, .. } = &self.update_status {
780+
self.update_status = UpdateStatus::Downloading {
781+
version: version.clone(),
782+
progress,
783+
};
784+
}
785+
}
786+
}

0 commit comments

Comments
 (0)