Skip to content

Commit a59d86d

Browse files
committed
Fix status account display after auth changes
1 parent 16f961d commit a59d86d

4 files changed

Lines changed: 19 additions & 26 deletions

File tree

codex-rs/tui/src/app.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,15 @@ impl AuthIdentity {
676676
if !self.has_chatgpt_account {
677677
return "API key".to_string();
678678
}
679-
let email = self.email.as_deref().unwrap_or("unknown email");
680-
let plan = self
681-
.plan_type
682-
.map(crate::status::plan_type_display_name)
683-
.unwrap_or_else(|| "unknown plan".to_string());
684-
format!("{email} ({plan})")
679+
match (
680+
self.email.as_deref(),
681+
self.plan_type.map(crate::status::plan_type_display_name),
682+
) {
683+
(Some(email), Some(plan)) => format!("{email} ({plan})"),
684+
(Some(email), None) => email.to_string(),
685+
(None, Some(plan)) => plan,
686+
(None, None) => "ChatGPT".to_string(),
687+
}
685688
}
686689
}
687690

codex-rs/tui/src/app/app_server_events.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use crate::app_command::AppCommand;
88
use crate::app_event::AppEvent;
99
use crate::app_event::ConnectorsSnapshot;
1010
use crate::app_server_session::AppServerSession;
11-
use crate::app_server_session::status_account_display_from_auth_mode;
1211
use codex_app_server_client::AppServerEvent;
13-
use codex_app_server_protocol::AuthMode;
1412
use codex_app_server_protocol::ServerNotification;
1513
use codex_app_server_protocol::ServerRequest;
1614

@@ -80,18 +78,8 @@ impl App {
8078
.on_rate_limit_snapshot(Some(notification.rate_limits.clone()));
8179
return;
8280
}
83-
ServerNotification::AccountUpdated(notification) => {
84-
self.chat_widget.update_account_state(
85-
status_account_display_from_auth_mode(
86-
notification.auth_mode,
87-
notification.plan_type,
88-
),
89-
notification.plan_type,
90-
matches!(
91-
notification.auth_mode,
92-
Some(AuthMode::Chatgpt) | Some(AuthMode::ChatgptAuthTokens)
93-
),
94-
);
81+
ServerNotification::AccountUpdated(_notification) => {
82+
self.app_event_tx.send(AppEvent::AuthFileChanged);
9583
return;
9684
}
9785
ServerNotification::ExternalAgentConfigImportCompleted(_) => {

codex-rs/tui/src/app_server_session.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use codex_app_server_client::AppServerRequestHandle;
1717
use codex_app_server_client::TypedRequestError;
1818
use codex_app_server_protocol::Account;
1919
use codex_app_server_protocol::AskForApproval;
20+
#[cfg(test)]
2021
use codex_app_server_protocol::AuthMode;
2122
use codex_app_server_protocol::ClientRequest;
2223
use codex_app_server_protocol::ConfigBatchWriteParams;
@@ -1153,6 +1154,7 @@ fn thread_realtime_start_params(
11531154
.wrap_err("mapping TUI realtime start params to app-server params")
11541155
}
11551156

1157+
#[cfg(test)]
11561158
pub(crate) fn status_account_display_from_auth_mode(
11571159
auth_mode: Option<AuthMode>,
11581160
plan_type: Option<codex_protocol::account::PlanType>,

codex-rs/tui/src/chatwidget/status_header.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,7 @@ fn status_header_account_label(
393393
}
394394

395395
let (email, display_plan) = match account_display {
396-
Some(StatusAccountDisplay::ChatGpt { email, plan }) => {
397-
(email.as_deref().unwrap_or("unknown email"), plan.as_deref())
398-
}
396+
Some(StatusAccountDisplay::ChatGpt { email, plan }) => (email.as_deref(), plan.as_deref()),
399397
Some(StatusAccountDisplay::ApiKey) => return Some("API key".to_string()),
400398
None => return None,
401399
};
@@ -405,9 +403,11 @@ fn status_header_account_label(
405403
None => plan_type.map(crate::status::plan_type_display_name),
406404
};
407405

408-
match plan {
409-
Some(plan) => Some(format!("{email}({plan})")),
410-
None => Some(email.to_string()),
406+
match (email, plan) {
407+
(Some(email), Some(plan)) => Some(format!("{email}({plan})")),
408+
(Some(email), None) => Some(email.to_string()),
409+
(None, Some(plan)) => Some(plan),
410+
(None, None) => None,
411411
}
412412
}
413413

0 commit comments

Comments
 (0)