1// Allow binary to be called Zed for a nice application menu when running executable directly
2#![allow(non_snake_case)]
3
4use anyhow::{anyhow, Context, Result};
5use backtrace::Backtrace;
6use chrono::Utc;
7use cli::FORCE_CLI_MODE_ENV_VAR_NAME;
8use client::{
9 self, Client, TelemetrySettings, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN,
10};
11use collab_ui::channel_view::ChannelView;
12use db::kvp::KEY_VALUE_STORE;
13use editor::Editor;
14use futures::StreamExt;
15use gpui::{Action, App, AppContext, AssetSource, AsyncAppContext, Task};
16use isahc::{config::Configurable, Request};
17use language::LanguageRegistry;
18use log::LevelFilter;
19use node_runtime::RealNodeRuntime;
20use parking_lot::Mutex;
21use project::Fs;
22use serde::{Deserialize, Serialize};
23use settings::{default_settings, handle_settings_file_changes, watch_config_file, SettingsStore};
24use simplelog::ConfigBuilder;
25use smol::process::Command;
26use std::{
27 env,
28 ffi::OsStr,
29 fs::OpenOptions,
30 io::{IsTerminal, Write as _},
31 panic,
32 path::Path,
33 sync::{
34 atomic::{AtomicU32, Ordering},
35 Arc, Weak,
36 },
37 thread,
38};
39use util::{
40 channel::{parse_zed_link, ReleaseChannel},
41 http::{self, HttpClient},
42};
43use uuid::Uuid;
44use welcome::{show_welcome_experience, FIRST_OPEN};
45
46use fs::RealFs;
47use util::{channel::RELEASE_CHANNEL, paths, ResultExt, TryFutureExt};
48use workspace::{AppState, WorkspaceStore};
49use zed::{
50 assets::Assets,
51 build_window_options, handle_keymap_file_changes, initialize_workspace, languages, menus,
52 only_instance::{ensure_only_instance, IsOnlyInstance},
53 open_listener::{handle_cli_connection, OpenListener, OpenRequest},
54};
55
56fn main() {
57 let http = http::client();
58 init_paths();
59 init_logger();
60
61 if ensure_only_instance() != IsOnlyInstance::Yes {
62 return;
63 }
64
65 log::info!("========== starting zed ==========");
66 let mut app = gpui::App::new(Assets).unwrap();
67
68 let (installation_id, existing_installation_id_found) =
69 app.background().block(installation_id()).ok().unzip();
70 let session_id = Uuid::new_v4().to_string();
71 init_panic_hook(&app, installation_id.clone(), session_id.clone());
72
73 load_embedded_fonts(&app);
74
75 let fs = Arc::new(RealFs);
76 let user_settings_file_rx =
77 watch_config_file(app.background(), fs.clone(), paths::SETTINGS.clone());
78 let user_keymap_file_rx =
79 watch_config_file(app.background(), fs.clone(), paths::KEYMAP.clone());
80
81 let login_shell_env_loaded = if stdout_is_a_pty() {
82 Task::ready(())
83 } else {
84 app.background().spawn(async {
85 load_login_shell_environment().await.log_err();
86 })
87 };
88
89 let (listener, mut open_rx) = OpenListener::new();
90 let listener = Arc::new(listener);
91 let callback_listener = listener.clone();
92 app.on_open_urls(move |urls, _| callback_listener.open_urls(urls))
93 .on_reopen(move |cx| {
94 if cx.has_global::<Weak<AppState>>() {
95 if let Some(app_state) = cx.global::<Weak<AppState>>().upgrade() {
96 workspace::open_new(&app_state, cx, |workspace, cx| {
97 Editor::new_file(workspace, &Default::default(), cx)
98 })
99 .detach();
100 }
101 }
102 });
103
104 app.run(move |cx| {
105 cx.set_global(*RELEASE_CHANNEL);
106 cx.set_global(listener.clone());
107
108 let mut store = SettingsStore::default();
109 store
110 .set_default_settings(default_settings().as_ref(), cx)
111 .unwrap();
112 cx.set_global(store);
113 handle_settings_file_changes(user_settings_file_rx, cx);
114 handle_keymap_file_changes(user_keymap_file_rx, cx);
115
116 let client = client::Client::new(http.clone(), cx);
117 let mut languages = LanguageRegistry::new(login_shell_env_loaded);
118 let copilot_language_server_id = languages.next_language_server_id();
119 languages.set_executor(cx.background().clone());
120 languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone());
121 let languages = Arc::new(languages);
122 let node_runtime = RealNodeRuntime::new(http.clone());
123
124 languages::init(languages.clone(), node_runtime.clone(), cx);
125 let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
126 let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx));
127
128 cx.set_global(client.clone());
129
130 theme::init(Assets, cx);
131 context_menu::init(cx);
132 project::Project::init(&client, cx);
133 client::init(&client, cx);
134 command_palette::init(cx);
135 language::init(cx);
136 editor::init(cx);
137 go_to_line::init(cx);
138 file_finder::init(cx);
139 outline::init(cx);
140 project_symbols::init(cx);
141 project_panel::init(Assets, cx);
142 channel::init(&client, user_store.clone(), cx);
143 diagnostics::init(cx);
144 search::init(cx);
145 semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
146 vim::init(cx);
147 terminal_view::init(cx);
148 copilot::init(
149 copilot_language_server_id,
150 http.clone(),
151 node_runtime.clone(),
152 cx,
153 );
154 assistant::init(cx);
155 component_test::init(cx);
156
157 cx.spawn(|cx| watch_themes(fs.clone(), cx)).detach();
158 cx.spawn(|_| watch_languages(fs.clone(), languages.clone()))
159 .detach();
160 watch_file_types(fs.clone(), cx);
161
162 languages.set_theme(theme::current(cx).clone());
163 cx.observe_global::<SettingsStore, _>({
164 let languages = languages.clone();
165 move |cx| languages.set_theme(theme::current(cx).clone())
166 })
167 .detach();
168
169 client.telemetry().start(installation_id, session_id, cx);
170 // TODO:
171 // Cleanly identify open / first open
172 // What should we do if we fail when looking for installation_id?
173 // - set to true, false, or skip?
174 // Report closed
175 // Copy logic to zed2
176 let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
177 let event_operation = match existing_installation_id_found {
178 Some(false) => "first open",
179 _ => "open",
180 };
181 client
182 .telemetry()
183 .report_app_event(telemetry_settings, event_operation);
184
185 let app_state = Arc::new(AppState {
186 languages,
187 client: client.clone(),
188 user_store,
189 fs,
190 build_window_options,
191 initialize_workspace,
192 background_actions,
193 workspace_store,
194 node_runtime,
195 });
196 cx.set_global(Arc::downgrade(&app_state));
197
198 audio::init(Assets, cx);
199 auto_update::init(http.clone(), client::ZED_SERVER_URL.clone(), cx);
200
201 workspace::init(app_state.clone(), cx);
202 recent_projects::init(cx);
203
204 journal::init(app_state.clone(), cx);
205 language_selector::init(cx);
206 theme_selector::init(cx);
207 activity_indicator::init(cx);
208 language_tools::init(cx);
209 call::init(app_state.client.clone(), app_state.user_store.clone(), cx);
210 notifications::init(app_state.client.clone(), app_state.user_store.clone(), cx);
211 collab_ui::init(&app_state, cx);
212 feedback::init(cx);
213 welcome::init(cx);
214 zed::init(&app_state, cx);
215
216 cx.set_menus(menus::menus());
217
218 if stdout_is_a_pty() {
219 cx.platform().activate(true);
220 let urls = collect_url_args();
221 if !urls.is_empty() {
222 listener.open_urls(urls)
223 }
224 } else {
225 upload_previous_panics(http.clone(), cx);
226
227 // TODO Development mode that forces the CLI mode usually runs Zed binary as is instead
228 // of an *app, hence gets no specific callbacks run. Emulate them here, if needed.
229 if std::env::var(FORCE_CLI_MODE_ENV_VAR_NAME).ok().is_some()
230 && !listener.triggered.load(Ordering::Acquire)
231 {
232 listener.open_urls(collect_url_args())
233 }
234 }
235
236 let mut triggered_authentication = false;
237
238 match open_rx.try_next() {
239 Ok(Some(OpenRequest::Paths { paths })) => {
240 cx.update(|cx| workspace::open_paths(&paths, &app_state, None, cx))
241 .detach();
242 }
243 Ok(Some(OpenRequest::CliConnection { connection })) => {
244 cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
245 .detach();
246 }
247 Ok(Some(OpenRequest::JoinChannel { channel_id })) => {
248 triggered_authentication = true;
249 let app_state = app_state.clone();
250 let client = client.clone();
251 cx.spawn(|mut cx| async move {
252 // ignore errors here, we'll show a generic "not signed in"
253 let _ = authenticate(client, &cx).await;
254 cx.update(|cx| workspace::join_channel(channel_id, app_state, None, cx))
255 .await
256 })
257 .detach_and_log_err(cx)
258 }
259 Ok(Some(OpenRequest::OpenChannelNotes { channel_id })) => {
260 triggered_authentication = true;
261 let app_state = app_state.clone();
262 let client = client.clone();
263 cx.spawn(|mut cx| async move {
264 // ignore errors here, we'll show a generic "not signed in"
265 let _ = authenticate(client, &cx).await;
266 let workspace =
267 workspace::get_any_active_workspace(app_state, cx.clone()).await?;
268 cx.update(|cx| ChannelView::open(channel_id, workspace, cx))
269 .await
270 })
271 .detach_and_log_err(cx)
272 }
273 Ok(None) | Err(_) => cx
274 .spawn({
275 let app_state = app_state.clone();
276 |cx| async move { restore_or_create_workspace(&app_state, cx).await }
277 })
278 .detach(),
279 }
280
281 cx.spawn(|mut cx| {
282 let app_state = app_state.clone();
283 async move {
284 while let Some(request) = open_rx.next().await {
285 match request {
286 OpenRequest::Paths { paths } => {
287 cx.update(|cx| {
288 workspace::open_paths(&paths, &app_state.clone(), None, cx)
289 })
290 .detach();
291 }
292 OpenRequest::CliConnection { connection } => {
293 cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
294 .detach();
295 }
296 OpenRequest::JoinChannel { channel_id } => cx
297 .update(|cx| {
298 workspace::join_channel(channel_id, app_state.clone(), None, cx)
299 })
300 .detach(),
301 OpenRequest::OpenChannelNotes { channel_id } => {
302 let app_state = app_state.clone();
303 if let Ok(workspace) =
304 workspace::get_any_active_workspace(app_state, cx.clone()).await
305 {
306 cx.update(|cx| {
307 ChannelView::open(channel_id, workspace, cx).detach();
308 })
309 }
310 }
311 }
312 }
313 }
314 })
315 .detach();
316
317 if !triggered_authentication {
318 cx.spawn(|cx| async move { authenticate(client, &cx).await })
319 .detach_and_log_err(cx);
320 }
321 });
322}
323
324async fn authenticate(client: Arc<Client>, cx: &AsyncAppContext) -> Result<()> {
325 if stdout_is_a_pty() {
326 if client::IMPERSONATE_LOGIN.is_some() {
327 client.authenticate_and_connect(false, &cx).await?;
328 }
329 } else if client.has_keychain_credentials(&cx) {
330 client.authenticate_and_connect(true, &cx).await?;
331 }
332 Ok::<_, anyhow::Error>(())
333}
334
335async fn installation_id() -> Result<(String, bool)> {
336 let legacy_key_name = "device_id";
337
338 if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(legacy_key_name) {
339 Ok((installation_id, true))
340 } else {
341 let installation_id = Uuid::new_v4().to_string();
342
343 KEY_VALUE_STORE
344 .write_kvp(legacy_key_name.to_string(), installation_id.clone())
345 .await?;
346
347 Ok((installation_id, false))
348 }
349}
350
351async fn restore_or_create_workspace(app_state: &Arc<AppState>, mut cx: AsyncAppContext) {
352 if let Some(location) = workspace::last_opened_workspace_paths().await {
353 cx.update(|cx| workspace::open_paths(location.paths().as_ref(), app_state, None, cx))
354 .await
355 .log_err();
356 } else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) {
357 cx.update(|cx| show_welcome_experience(app_state, cx));
358 } else {
359 cx.update(|cx| {
360 workspace::open_new(app_state, cx, |workspace, cx| {
361 Editor::new_file(workspace, &Default::default(), cx)
362 })
363 .detach();
364 });
365 }
366}
367
368fn init_paths() {
369 std::fs::create_dir_all(&*util::paths::CONFIG_DIR).expect("could not create config path");
370 std::fs::create_dir_all(&*util::paths::LANGUAGES_DIR).expect("could not create languages path");
371 std::fs::create_dir_all(&*util::paths::DB_DIR).expect("could not create database path");
372 std::fs::create_dir_all(&*util::paths::LOGS_DIR).expect("could not create logs path");
373}
374
375fn init_logger() {
376 if stdout_is_a_pty() {
377 env_logger::init();
378 } else {
379 let level = LevelFilter::Info;
380
381 // Prevent log file from becoming too large.
382 const KIB: u64 = 1024;
383 const MIB: u64 = 1024 * KIB;
384 const MAX_LOG_BYTES: u64 = MIB;
385 if std::fs::metadata(&*paths::LOG).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES)
386 {
387 let _ = std::fs::rename(&*paths::LOG, &*paths::OLD_LOG);
388 }
389
390 let log_file = OpenOptions::new()
391 .create(true)
392 .append(true)
393 .open(&*paths::LOG)
394 .expect("could not open logfile");
395
396 let config = ConfigBuilder::new()
397 .set_time_format_str("%Y-%m-%dT%T") //All timestamps are UTC
398 .build();
399
400 simplelog::WriteLogger::init(level, config, log_file).expect("could not initialize logger");
401 }
402}
403
404#[derive(Serialize, Deserialize)]
405struct LocationData {
406 file: String,
407 line: u32,
408}
409
410#[derive(Serialize, Deserialize)]
411struct Panic {
412 thread: String,
413 payload: String,
414 #[serde(skip_serializing_if = "Option::is_none")]
415 location_data: Option<LocationData>,
416 backtrace: Vec<String>,
417 app_version: String,
418 release_channel: String,
419 os_name: String,
420 os_version: Option<String>,
421 architecture: String,
422 panicked_on: i64,
423 #[serde(skip_serializing_if = "Option::is_none")]
424 installation_id: Option<String>,
425 session_id: String,
426}
427
428#[derive(Serialize)]
429struct PanicRequest {
430 panic: Panic,
431 token: String,
432}
433
434static PANIC_COUNT: AtomicU32 = AtomicU32::new(0);
435
436fn init_panic_hook(app: &App, installation_id: Option<String>, session_id: String) {
437 let is_pty = stdout_is_a_pty();
438 let platform = app.platform();
439
440 panic::set_hook(Box::new(move |info| {
441 let prior_panic_count = PANIC_COUNT.fetch_add(1, Ordering::SeqCst);
442 if prior_panic_count > 0 {
443 // Give the panic-ing thread time to write the panic file
444 loop {
445 std::thread::yield_now();
446 }
447 }
448
449 let thread = thread::current();
450 let thread_name = thread.name().unwrap_or("<unnamed>");
451
452 let payload = info
453 .payload()
454 .downcast_ref::<&str>()
455 .map(|s| s.to_string())
456 .or_else(|| info.payload().downcast_ref::<String>().map(|s| s.clone()))
457 .unwrap_or_else(|| "Box<Any>".to_string());
458
459 if *util::channel::RELEASE_CHANNEL == ReleaseChannel::Dev {
460 let location = info.location().unwrap();
461 let backtrace = Backtrace::new();
462 eprintln!(
463 "Thread {:?} panicked with {:?} at {}:{}:{}\n{:?}",
464 thread_name,
465 payload,
466 location.file(),
467 location.line(),
468 location.column(),
469 backtrace,
470 );
471 std::process::exit(-1);
472 }
473
474 let app_version = ZED_APP_VERSION
475 .or_else(|| platform.app_version().ok())
476 .map_or("dev".to_string(), |v| v.to_string());
477
478 let backtrace = Backtrace::new();
479 let mut backtrace = backtrace
480 .frames()
481 .iter()
482 .filter_map(|frame| Some(format!("{:#}", frame.symbols().first()?.name()?)))
483 .collect::<Vec<_>>();
484
485 // Strip out leading stack frames for rust panic-handling.
486 if let Some(ix) = backtrace
487 .iter()
488 .position(|name| name == "rust_begin_unwind")
489 {
490 backtrace.drain(0..=ix);
491 }
492
493 let panic_data = Panic {
494 thread: thread_name.into(),
495 payload: payload.into(),
496 location_data: info.location().map(|location| LocationData {
497 file: location.file().into(),
498 line: location.line(),
499 }),
500 app_version: app_version.clone(),
501 release_channel: RELEASE_CHANNEL.display_name().into(),
502 os_name: platform.os_name().into(),
503 os_version: platform
504 .os_version()
505 .ok()
506 .map(|os_version| os_version.to_string()),
507 architecture: env::consts::ARCH.into(),
508 panicked_on: Utc::now().timestamp_millis(),
509 backtrace,
510 installation_id: installation_id.clone(),
511 session_id: session_id.clone(),
512 };
513
514 if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() {
515 log::error!("{}", panic_data_json);
516 }
517
518 if !is_pty {
519 if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() {
520 let timestamp = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string();
521 let panic_file_path = paths::LOGS_DIR.join(format!("zed-{}.panic", timestamp));
522 let panic_file = std::fs::OpenOptions::new()
523 .append(true)
524 .create(true)
525 .open(&panic_file_path)
526 .log_err();
527 if let Some(mut panic_file) = panic_file {
528 writeln!(&mut panic_file, "{}", panic_data_json).log_err();
529 panic_file.flush().log_err();
530 }
531 }
532 }
533
534 std::process::abort();
535 }));
536}
537
538fn upload_previous_panics(http: Arc<dyn HttpClient>, cx: &mut AppContext) {
539 let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
540
541 cx.background()
542 .spawn({
543 async move {
544 let panic_report_url = format!("{}/api/panic", &*client::ZED_SERVER_URL);
545 let mut children = smol::fs::read_dir(&*paths::LOGS_DIR).await?;
546 while let Some(child) = children.next().await {
547 let child = child?;
548 let child_path = child.path();
549
550 if child_path.extension() != Some(OsStr::new("panic")) {
551 continue;
552 }
553 let filename = if let Some(filename) = child_path.file_name() {
554 filename.to_string_lossy()
555 } else {
556 continue;
557 };
558
559 if !filename.starts_with("zed") {
560 continue;
561 }
562
563 if telemetry_settings.diagnostics {
564 let panic_file_content = smol::fs::read_to_string(&child_path)
565 .await
566 .context("error reading panic file")?;
567
568 let panic = serde_json::from_str(&panic_file_content)
569 .ok()
570 .or_else(|| {
571 panic_file_content
572 .lines()
573 .next()
574 .and_then(|line| serde_json::from_str(line).ok())
575 })
576 .unwrap_or_else(|| {
577 log::error!(
578 "failed to deserialize panic file {:?}",
579 panic_file_content
580 );
581 None
582 });
583
584 if let Some(panic) = panic {
585 let body = serde_json::to_string(&PanicRequest {
586 panic,
587 token: ZED_SECRET_CLIENT_TOKEN.into(),
588 })
589 .unwrap();
590
591 let request = Request::post(&panic_report_url)
592 .redirect_policy(isahc::config::RedirectPolicy::Follow)
593 .header("Content-Type", "application/json")
594 .body(body.into())?;
595 let response =
596 http.send(request).await.context("error sending panic")?;
597 if !response.status().is_success() {
598 log::error!(
599 "Error uploading panic to server: {}",
600 response.status()
601 );
602 }
603 }
604 }
605
606 // We've done what we can, delete the file
607 std::fs::remove_file(child_path)
608 .context("error removing panic")
609 .log_err();
610 }
611 Ok::<_, anyhow::Error>(())
612 }
613 .log_err()
614 })
615 .detach();
616}
617
618async fn load_login_shell_environment() -> Result<()> {
619 let marker = "ZED_LOGIN_SHELL_START";
620 let shell = env::var("SHELL").context(
621 "SHELL environment variable is not assigned so we can't source login environment variables",
622 )?;
623 let output = Command::new(&shell)
624 .args(["-lic", &format!("echo {marker} && /usr/bin/env -0")])
625 .output()
626 .await
627 .context("failed to spawn login shell to source login environment variables")?;
628 if !output.status.success() {
629 Err(anyhow!("login shell exited with error"))?;
630 }
631
632 let stdout = String::from_utf8_lossy(&output.stdout);
633
634 if let Some(env_output_start) = stdout.find(marker) {
635 let env_output = &stdout[env_output_start + marker.len()..];
636 for line in env_output.split_terminator('\0') {
637 if let Some(separator_index) = line.find('=') {
638 let key = &line[..separator_index];
639 let value = &line[separator_index + 1..];
640 env::set_var(key, value);
641 }
642 }
643 log::info!(
644 "set environment variables from shell:{}, path:{}",
645 shell,
646 env::var("PATH").unwrap_or_default(),
647 );
648 }
649
650 Ok(())
651}
652
653fn stdout_is_a_pty() -> bool {
654 std::env::var(FORCE_CLI_MODE_ENV_VAR_NAME).ok().is_none() && std::io::stdout().is_terminal()
655}
656
657fn collect_url_args() -> Vec<String> {
658 env::args()
659 .skip(1)
660 .filter_map(|arg| match std::fs::canonicalize(Path::new(&arg)) {
661 Ok(path) => Some(format!("file://{}", path.to_string_lossy())),
662 Err(error) => {
663 if let Some(_) = parse_zed_link(&arg) {
664 Some(arg)
665 } else {
666 log::error!("error parsing path argument: {}", error);
667 None
668 }
669 }
670 })
671 .collect()
672}
673
674fn load_embedded_fonts(app: &App) {
675 let font_paths = Assets.list("fonts");
676 let embedded_fonts = Mutex::new(Vec::new());
677 smol::block_on(app.background().scoped(|scope| {
678 for font_path in &font_paths {
679 if !font_path.ends_with(".ttf") {
680 continue;
681 }
682
683 scope.spawn(async {
684 let font_path = &*font_path;
685 let font_bytes = Assets.load(font_path).unwrap().to_vec();
686 embedded_fonts.lock().push(Arc::from(font_bytes));
687 });
688 }
689 }));
690 app.platform()
691 .fonts()
692 .add_fonts(&embedded_fonts.into_inner())
693 .unwrap();
694}
695
696#[cfg(debug_assertions)]
697async fn watch_themes(fs: Arc<dyn Fs>, mut cx: AsyncAppContext) -> Option<()> {
698 let mut events = fs
699 .watch("styles/src".as_ref(), std::time::Duration::from_millis(100))
700 .await;
701 while (events.next().await).is_some() {
702 let output = Command::new("npm")
703 .current_dir("styles")
704 .args(["run", "build"])
705 .output()
706 .await
707 .log_err()?;
708 if output.status.success() {
709 cx.update(|cx| theme_selector::reload(cx))
710 } else {
711 eprintln!(
712 "build script failed {}",
713 String::from_utf8_lossy(&output.stderr)
714 );
715 }
716 }
717 Some(())
718}
719
720#[cfg(debug_assertions)]
721async fn watch_languages(fs: Arc<dyn Fs>, languages: Arc<LanguageRegistry>) -> Option<()> {
722 let mut events = fs
723 .watch(
724 "crates/zed/src/languages".as_ref(),
725 std::time::Duration::from_millis(100),
726 )
727 .await;
728 while (events.next().await).is_some() {
729 languages.reload();
730 }
731 Some(())
732}
733
734#[cfg(debug_assertions)]
735fn watch_file_types(fs: Arc<dyn Fs>, cx: &mut AppContext) {
736 cx.spawn(|mut cx| async move {
737 let mut events = fs
738 .watch(
739 "assets/icons/file_icons/file_types.json".as_ref(),
740 std::time::Duration::from_millis(100),
741 )
742 .await;
743 while (events.next().await).is_some() {
744 cx.update(|cx| {
745 cx.update_global(|file_types, _| {
746 *file_types = project_panel::file_associations::FileAssociations::new(Assets);
747 });
748 })
749 }
750 })
751 .detach()
752}
753
754#[cfg(not(debug_assertions))]
755async fn watch_themes(_fs: Arc<dyn Fs>, _cx: AsyncAppContext) -> Option<()> {
756 None
757}
758
759#[cfg(not(debug_assertions))]
760async fn watch_languages(_: Arc<dyn Fs>, _: Arc<LanguageRegistry>) -> Option<()> {
761 None
762}
763
764#[cfg(not(debug_assertions))]
765fn watch_file_types(_fs: Arc<dyn Fs>, _cx: &mut AppContext) {}
766
767pub fn background_actions() -> &'static [(&'static str, &'static dyn Action)] {
768 &[
769 ("Go to file", &file_finder::Toggle),
770 ("Open command palette", &command_palette::Toggle),
771 ("Open recent projects", &recent_projects::OpenRecent),
772 ("Change your settings", &zed_actions::OpenSettings),
773 ]
774}