Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

zed: Wait for session restore before handling CLI open requests (#61814)

Remco Smits08994c411cb1
diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs
index 0ca0c53afb3..6d8ccf98dca 100644
--- a/crates/zed/src/main.rs
+++ b/crates/zed/src/main.rs
@@ -26,7 +26,7 @@ use db::kvp::{GlobalKeyValueStore, KeyValueStore};
use editor::Editor;
use extension::ExtensionHostProxy;
use fs::{Fs, RealFs};
-use futures::{StreamExt, channel::oneshot, future};
+use futures::{FutureExt, StreamExt, channel::oneshot, future};
use git::GitHostingProviderRegistry;
use git_ui::clone::clone_and_open;
use gpui::{
@@ -945,11 +945,22 @@ fn main() {
}),
};
+ let (first_window_tx, first_window_rx) = oneshot::channel::<()>();
+ let first_window_tx = Rc::new(RefCell::new(Some(first_window_tx)));
+ let _first_window_subscription = cx.observe_new::<MultiWorkspace>(move |_, _, _| {
+ if let Some(tx) = first_window_tx.borrow_mut().take() {
+ tx.send(()).ok();
+ }
+ });
+
+ let restore_finished = cx.background_spawn(restore_task).shared();
+
cx.spawn({
let db = workspace::WorkspaceDb::global(cx);
let fs = app_state.fs.clone();
+ let restore_finished = restore_finished.clone();
async move |_cx| {
- restore_task.await;
+ restore_finished.await;
db.garbage_collect_workspaces(
fs.as_ref(),
&current_session_id,
@@ -965,7 +976,16 @@ fn main() {
component_preview::init(app_state.clone(), cx);
cx.spawn(async move |cx| {
+ let _first_window_subscription = _first_window_subscription;
+ let first_window_placed = first_window_rx.shared();
while let Some(urls) = open_rx.next().await {
+ // On a macOS cold launch, `zed <path>` arrives here after startup already
+ // began restoring the session, so wait for a restored window to exist before
+ // matching. Otherwise this open sees no windows and spawns a redundant one (#61346).
+ futures::select_biased! {
+ _ = restore_finished.clone() => {}
+ _ = first_window_placed.clone() => {}
+ }
cx.update(|cx| {
if let Some(request) = OpenRequest::parse(urls, cx).log_err() {
handle_open_request(request, app_state.clone(), cx);