@@ -26,7 +26,6 @@ use std::{
};
use util::http::{self, HttpClient};
-#[derive(Clone)]
pub struct App(Arc<Mutex<AppContext>>);
impl App {
@@ -83,15 +82,49 @@ impl App {
where
F: 'static + FnOnce(&mut MainThread<AppContext>),
{
- 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<AppContext>>(cx) };
on_finish_launching(cx);
}));
}
+ pub fn on_open_urls<F>(&self, mut callback: F) -> &Self
+ where
+ F: 'static + FnMut(Vec<String>, &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<F>(&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()
}
@@ -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::<Weak<AppState>>() {
- if let Some(app_state) = cx.global::<Weak<AppState>>().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::<Weak<AppState>>() {
+ // if let Some(app_state) = cx.global::<Weak<AppState>>().upgrade() {
+ // workspace::open_new(&app_state, cx, |workspace, cx| {
+ // Editor::new_file(workspace, &Default::default(), cx)
+ // })
+ // .detach();
+ // }
+ // }
});
app.run(move |cx| {
@@ -48,12 +48,12 @@ pub struct AppState;
pub async fn handle_cli_connection(
(mut requests, responses): (mpsc::Receiver<CliRequest>, IpcSender<CliResponse>),
- app_state: Arc<AppState>,
- mut cx: AsyncAppContext,
+ _app_state: Arc<AppState>,
+ 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() {