Update ChatGPT authentication and sign-in recovery
Co-Authored-By: Warp <agent@warp.dev>
This commit is contained in:
@@ -220,6 +220,7 @@ pub enum ProviderSetupViewAction {
|
||||
ToggleModel(usize),
|
||||
CycleModelCapability(usize, CapabilityKey),
|
||||
ConnectChatGPT,
|
||||
CancelChatGPTSignIn,
|
||||
ConnectClaude,
|
||||
SignOutClaude,
|
||||
CancelClaudeSignIn,
|
||||
@@ -1590,10 +1591,10 @@ impl ProviderSetupView {
|
||||
);
|
||||
}
|
||||
|
||||
if matches!(
|
||||
state,
|
||||
ChatGPTAuthState::NotConnected | ChatGPTAuthState::Failed(_)
|
||||
) {
|
||||
let pending = matches!(state,
|
||||
ChatGPTAuthState::AwaitingBrowser | ChatGPTAuthState::ExchangingToken
|
||||
);
|
||||
{
|
||||
children.push(
|
||||
appearance
|
||||
.ui_builder()
|
||||
@@ -1601,10 +1602,21 @@ impl ProviderSetupView {
|
||||
ButtonVariant::Secondary,
|
||||
self.chatgpt_connect_mouse_state.clone(),
|
||||
)
|
||||
.with_text_label("Connect ChatGPT".to_owned())
|
||||
.with_text_label(if pending {
|
||||
"Cancel sign-in"
|
||||
} else if matches!(state, ChatGPTAuthState::Connected) {
|
||||
"Reconnect ChatGPT"
|
||||
} else {
|
||||
"Connect ChatGPT"
|
||||
}.to_owned())
|
||||
.build()
|
||||
.on_click(|ctx, _, _| {
|
||||
ctx.dispatch_typed_action(ProviderSetupViewAction::ConnectChatGPT);
|
||||
.on_click(move |ctx, _, _| {
|
||||
let action = if pending {
|
||||
ProviderSetupViewAction::CancelChatGPTSignIn
|
||||
} else {
|
||||
ProviderSetupViewAction::ConnectChatGPT
|
||||
};
|
||||
ctx.dispatch_typed_action(action);
|
||||
})
|
||||
.finish(),
|
||||
);
|
||||
@@ -1861,7 +1873,7 @@ impl ProviderSetupView {
|
||||
.finish()
|
||||
}
|
||||
|
||||
fn render_discovery(&self, appearance: &Appearance) -> Box<dyn galaxyui::Element> {
|
||||
fn render_discovery(&self, appearance: &Appearance, app: &AppContext) -> Box<dyn galaxyui::Element> {
|
||||
let (message, color) = match &self.discovery_state {
|
||||
DiscoveryState::Idle | DiscoveryState::Loading => (
|
||||
if self.provider_type == ProviderSetupProviderType::Acp
|
||||
@@ -1875,7 +1887,7 @@ impl ProviderSetupView {
|
||||
),
|
||||
DiscoveryState::Failed(error) => (error.clone(), appearance.theme().ui_error_color()),
|
||||
};
|
||||
Flex::column()
|
||||
let mut column = Flex::column()
|
||||
.with_spacing(12.)
|
||||
.with_child(
|
||||
Text::new(
|
||||
@@ -1913,8 +1925,13 @@ impl ProviderSetupView {
|
||||
.with_color(color)
|
||||
.soft_wrap(true)
|
||||
.finish()
|
||||
})
|
||||
.finish()
|
||||
});
|
||||
if self.provider_type == ProviderSetupProviderType::ChatGPTSubscription
|
||||
&& matches!(self.discovery_state, DiscoveryState::Failed(_))
|
||||
{
|
||||
column = column.with_child(self.render_chatgpt_auth(appearance, app));
|
||||
}
|
||||
column.finish()
|
||||
}
|
||||
|
||||
fn render_model_table(
|
||||
@@ -2468,7 +2485,7 @@ impl View for ProviderSetupView {
|
||||
let content = match self.step {
|
||||
ProviderSetupStep::ProviderType => self.render_provider_type(appearance),
|
||||
ProviderSetupStep::Configure => self.render_configure(appearance, app),
|
||||
ProviderSetupStep::Discover => self.render_discovery(appearance),
|
||||
ProviderSetupStep::Discover => self.render_discovery(appearance, app),
|
||||
ProviderSetupStep::Models => self.render_models(appearance),
|
||||
};
|
||||
Flex::column()
|
||||
@@ -2488,6 +2505,10 @@ impl TypedActionView for ProviderSetupView {
|
||||
match action {
|
||||
ProviderSetupViewAction::SelectProvider(kind) => {
|
||||
if self.provider_type != *kind {
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
if self.provider_type == ProviderSetupProviderType::ChatGPTSubscription {
|
||||
ChatGPTAuthModel::handle(ctx).update(ctx, |model, ctx| model.cancel_sign_in(ctx));
|
||||
}
|
||||
self.cancel_claude_signin();
|
||||
self.draft_api_key = None;
|
||||
self.claude_credentials_available = false;
|
||||
@@ -2588,6 +2609,10 @@ impl TypedActionView for ProviderSetupView {
|
||||
ProviderSetupViewAction::Cancel => {
|
||||
self.cancel_acp_setup();
|
||||
self.cancel_claude_signin();
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
if self.provider_type == ProviderSetupProviderType::ChatGPTSubscription {
|
||||
ChatGPTAuthModel::handle(ctx).update(ctx, |model, ctx| model.cancel_sign_in(ctx));
|
||||
}
|
||||
self.discovery_state = DiscoveryState::Idle;
|
||||
ctx.emit(ProviderSetupViewEvent::Close);
|
||||
}
|
||||
@@ -2633,6 +2658,10 @@ impl TypedActionView for ProviderSetupView {
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
ChatGPTAuthModel::handle(ctx).update(ctx, |model, ctx| model.connect(ctx));
|
||||
}
|
||||
ProviderSetupViewAction::CancelChatGPTSignIn => {
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
ChatGPTAuthModel::handle(ctx).update(ctx, |model, ctx| model.cancel_sign_in(ctx));
|
||||
}
|
||||
ProviderSetupViewAction::ConnectClaude => {
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
self.connect_claude(ctx);
|
||||
|
||||
Reference in New Issue
Block a user