Make a macro for less boilerplate when moving variables (#12182)

Also: 
- Simplify open listener implementation
- Add set_global API to global traits

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2024-05-22 22:07:29 -07:00 committed by GitHub
parent 8b57d6d4c6
commit 3eb0418bda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 164 additions and 31 deletions

View file

@ -17,7 +17,9 @@ use env_logger::Builder;
use fs::RealFs;
use futures::{future, StreamExt};
use git::GitHostingProviderRegistry;
use gpui::{App, AppContext, AsyncAppContext, Context, Global, Task, VisualContext};
use gpui::{
App, AppContext, AsyncAppContext, Context, Global, Task, UpdateGlobal as _, VisualContext,
};
use image_viewer;
use language::LanguageRegistry;
use log::LevelFilter;
@ -38,11 +40,7 @@ use std::{
sync::Arc,
};
use theme::{ActiveTheme, SystemAppearance, ThemeRegistry, ThemeSettings};
use util::{
maybe, parse_env_output,
paths::{self},
ResultExt, TryFutureExt,
};
use util::{maybe, parse_env_output, paths, with_clone, ResultExt, TryFutureExt};
use uuid::Uuid;
use welcome::{show_welcome_view, BaseKeymap, FIRST_OPEN};
use workspace::{AppState, WorkspaceSettings, WorkspaceStore};
@ -260,13 +258,11 @@ fn main() {
let session_id = Uuid::new_v4().to_string();
reliability::init_panic_hook(&app, installation_id.clone(), session_id.clone());
let (listener, mut open_rx) = OpenListener::new();
let listener = Arc::new(listener);
let open_listener = listener.clone();
let (open_listener, mut open_rx) = OpenListener::new();
#[cfg(target_os = "linux")]
{
if crate::zed::listen_for_cli_connections(listener.clone()).is_err() {
if crate::zed::listen_for_cli_connections(open_listener.clone()).is_err() {
println!("zed is already running");
return;
}
@ -317,7 +313,7 @@ fn main() {
})
};
app.on_open_urls(move |urls| open_listener.open_urls(urls));
app.on_open_urls(with_clone!(open_listener, move |urls| open_listener.open_urls(urls)));
app.on_reopen(move |cx| {
if let Some(app_state) = AppState::try_global(cx).and_then(|app_state| app_state.upgrade())
{
@ -338,7 +334,7 @@ fn main() {
GitHostingProviderRegistry::set_global(git_hosting_provider_registry, cx);
git_hosting_providers::init(cx);
OpenListener::set_global(listener.clone(), cx);
OpenListener::set_global(cx, open_listener.clone());
settings::init(cx);
handle_settings_file_changes(user_settings_file_rx, cx);
@ -396,7 +392,7 @@ fn main() {
.collect();
if !urls.is_empty() {
listener.open_urls(urls)
open_listener.open_urls(urls)
}
match open_rx