diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index c201febed5..a949b64c04 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1048,7 +1048,7 @@ impl AppContext { } } - pub fn dispatch_global_action(&mut self, action: A) { + fn dispatch_global_action(&mut self, action: A) { self.dispatch_global_action_any(&action); } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 2724e8587f..58a53b9e40 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -29,8 +29,16 @@ use settings::{ use simplelog::ConfigBuilder; use smol::process::Command; use std::{ - env, ffi::OsStr, fs::OpenOptions, io::Write as _, os::unix::prelude::OsStrExt, panic, - path::PathBuf, sync::Arc, thread, time::Duration, + env, + ffi::OsStr, + fs::OpenOptions, + io::Write as _, + os::unix::prelude::OsStrExt, + panic, + path::PathBuf, + sync::{Arc, Weak}, + thread, + time::Duration, }; use terminal_view::{get_working_directory, TerminalView}; use util::http::{self, HttpClient}; @@ -104,7 +112,13 @@ fn main() { .log_err(); } }) - .on_reopen(move |cx| cx.dispatch_global_action(NewFile)); + .on_reopen(move |cx| { + if cx.has_global::>() { + if let Some(app_state) = cx.global::>().upgrade() { + workspace::open_new(&app_state, cx, |_, cx| cx.dispatch_action(NewFile)).detach(); + } + } + }); app.run(move |cx| { cx.set_global(*RELEASE_CHANNEL); @@ -190,6 +204,7 @@ fn main() { dock_default_item_factory, background_actions, }); + cx.set_global(Arc::downgrade(&app_state)); auto_update::init(http, client::ZED_SERVER_URL.clone(), cx); workspace::init(app_state.clone(), cx); @@ -274,7 +289,7 @@ async fn restore_or_create_workspace(app_state: &Arc, mut cx: AsyncApp cx.update(|cx| show_welcome_experience(app_state, cx)); } else { cx.update(|cx| { - cx.dispatch_global_action(NewFile); + workspace::open_new(app_state, cx, |_, cx| cx.dispatch_action(NewFile)).detach(); }); } }