You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/24 18:06:22 UTC

(maka) 09/17: fix(desktop): show a lost Host connection and reopen the session after reconnecting

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch feat/desktop-gpui-spike
in repository https://gitbox.apache.org/repos/asf/maka.git

commit ad3c5a7ddf6a484e6217d49990eaa597245f5ef2
Author: AstroHan <le...@outlook.com>
AuthorDate: Fri Sep 25 01:53:54 2026 +0800

    fix(desktop): show a lost Host connection and reopen the session after reconnecting
    
    When the Host connection closed, the workspace marked itself failed but
    kept drawing the open chat, so the transcript looked live, the composer
    stayed enabled and every send failed. The chat is now closed on
    disconnect, so the main area shows the failure and the reconnect button;
    a successful reconnect reopens the session that was selected.
    
    Generated-by: Claude Code
---
 crates/desktop/src/sidebar.rs   |  4 ++++
 crates/desktop/src/workspace.rs | 23 ++++++++++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/crates/desktop/src/sidebar.rs b/crates/desktop/src/sidebar.rs
index ac81094633..36741f78ce 100644
--- a/crates/desktop/src/sidebar.rs
+++ b/crates/desktop/src/sidebar.rs
@@ -133,6 +133,10 @@ impl Sidebar {
         cx.notify();
     }
 
+    pub fn selected(&self) -> Option<String> {
+        self.selected.clone()
+    }
+
     /// The project folder of `id`, or else of the latest session.
     pub fn folder(&self, id: Option<&str>) -> Option<String> {
         id.and_then(|id| self.sessions.iter().find(|session| session.id == id))
diff --git a/crates/desktop/src/workspace.rs b/crates/desktop/src/workspace.rs
index 4a2b4ddbe5..587fb3dce0 100644
--- a/crates/desktop/src/workspace.rs
+++ b/crates/desktop/src/workspace.rs
@@ -76,21 +76,25 @@ impl Workspace {
             copied: cx.new(|_| Copied::default()),
             _tasks: Vec::new(),
         };
-        this.connect(cx);
+        this.connect(window, cx);
         this
     }
 
-    fn connect(&mut self, cx: &mut Context<Self>) {
+    fn connect(&mut self, window: &mut Window, cx: &mut Context<Self>) {
         self.connection = Connection::Connecting;
         let connecting = cx.global::<Host>().spawn(host::connect(self.root.clone()));
-        self._tasks = vec![cx.spawn(async move |this, cx| {
+        self._tasks = vec![cx.spawn_in(window, async move |this, cx| {
             let result = connecting.await.and_then(|result| result);
-            let Ok(notifications) = this.update(cx, |this, cx| match result {
+            let Ok(notifications) = this.update_in(cx, |this, window, cx| match result {
                 Ok((client, notifications)) => {
                     this.connection = Connection::Ready(client);
                     this.sidebar
                         .update(cx, |sidebar, cx| sidebar.set_can_create(true, cx));
                     this.load_sessions(cx);
+                    // After a reconnect, the session that was open comes back.
+                    if let Some(selected) = this.sidebar.read(cx).selected() {
+                        this.open(selected, window, cx);
+                    }
                     cx.notify();
                     Some(notifications)
                 }
@@ -126,9 +130,14 @@ impl Workspace {
             }
         }
         let _ = this.update(cx, |this, cx| {
-            this.connection = Connection::Failed("Host connection closed".into());
+            this.connection = Connection::Failed("与 Host 的连接已断开".into());
             this.sidebar
                 .update(cx, |sidebar, cx| sidebar.set_can_create(false, cx));
+            // A chat without a connection looks live but cannot send; the
+            // main area shows the failure and a reconnect instead.
+            if let Some(chat) = this.chat.take() {
+                chat.update(cx, |chat, cx| chat.close(cx));
+            }
             cx.notify();
         });
     }
@@ -297,9 +306,9 @@ impl Workspace {
                 "重新连接",
                 ui::Tone::Outline,
                 false,
-                move |_, cx| {
+                move |window, cx| {
                     let _ = this.update(cx, |this, cx| {
-                        this.connect(cx);
+                        this.connect(window, cx);
                         cx.notify();
                     });
                 },


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org