diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index d3118323ab..16e22f6cef 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -26,7 +26,6 @@ use std::{ }; use util::http::{self, HttpClient}; -#[derive(Clone)] pub struct App(Arc>); impl App { @@ -83,15 +82,49 @@ impl App { where F: 'static + FnOnce(&mut MainThread), { - let this = self.clone(); + let this = self.0.clone(); let platform = self.0.lock().platform.clone(); platform.borrow_on_main_thread().run(Box::new(move || { - let cx = &mut *this.0.lock(); + let cx = &mut *this.lock(); let cx = unsafe { mem::transmute::<&mut AppContext, &mut MainThread>(cx) }; on_finish_launching(cx); })); } + pub fn on_open_urls(&self, mut callback: F) -> &Self + where + F: 'static + FnMut(Vec, &mut AppContext), + { + let this = Arc::downgrade(&self.0); + self.0 + .lock() + .platform + .borrow_on_main_thread() + .on_open_urls(Box::new(move |urls| { + if let Some(app) = this.upgrade() { + callback(urls, &mut app.lock()); + } + })); + self + } + + pub fn on_reopen(&self, mut callback: F) -> &Self + where + F: 'static + FnMut(&mut AppContext), + { + let this = Arc::downgrade(&self.0); + self.0 + .lock() + .platform + .borrow_on_main_thread() + .on_reopen(Box::new(move || { + if let Some(app) = this.upgrade() { + callback(&mut app.lock()); + } + })); + self + } + pub fn executor(&self) -> Executor { self.0.lock().executor.clone() } diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index f30e4873eb..ae82948120 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -18,7 +18,6 @@ use settings2::{default_settings, handle_settings_file_changes, watch_config_fil use simplelog::ConfigBuilder; use smol::process::Command; use std::{ - collections::HashMap, env, fs::OpenOptions, io::IsTerminal, @@ -78,15 +77,15 @@ fn main() { let callback_listener = listener.clone(); app.on_open_urls(move |urls, _| callback_listener.open_urls(urls)) .on_reopen(move |cx| { - if cx.has_global::>() { - if let Some(app_state) = cx.global::>().upgrade() { - // todo!("workspace") - // workspace::open_new(&app_state, cx, |workspace, cx| { - // Editor::new_file(workspace, &Default::default(), cx) - // }) - // .detach(); - } - } + // todo!("workspace") + // if cx.has_global::>() { + // if let Some(app_state) = cx.global::>().upgrade() { + // workspace::open_new(&app_state, cx, |workspace, cx| { + // Editor::new_file(workspace, &Default::default(), cx) + // }) + // .detach(); + // } + // } }); app.run(move |cx| { diff --git a/crates/zed2/src/zed2.rs b/crates/zed2/src/zed2.rs index 00d5b9a700..9fb379b48c 100644 --- a/crates/zed2/src/zed2.rs +++ b/crates/zed2/src/zed2.rs @@ -48,12 +48,12 @@ pub struct AppState; pub async fn handle_cli_connection( (mut requests, responses): (mpsc::Receiver, IpcSender), - app_state: Arc, - mut cx: AsyncAppContext, + _app_state: Arc, + mut _cx: AsyncAppContext, ) { if let Some(request) = requests.next().await { match request { - CliRequest::Open { paths, wait } => { + CliRequest::Open { paths: _, wait: _ } => { // let mut caret_positions = HashMap::new(); // let paths = if paths.is_empty() {