1pub mod assets;
2pub mod channel;
3pub mod chat_panel;
4pub mod editor;
5pub mod file_finder;
6pub mod fs;
7mod fuzzy;
8pub mod language;
9pub mod menus;
10pub mod project_browser;
11pub mod rpc;
12pub mod settings;
13#[cfg(any(test, feature = "test-support"))]
14pub mod test;
15pub mod theme;
16pub mod theme_selector;
17mod time;
18pub mod user;
19mod util;
20pub mod workspace;
21pub mod worktree;
22
23use crate::util::TryFutureExt;
24use channel::ChannelList;
25use gpui::{action, keymap::Binding, ModelHandle};
26use parking_lot::Mutex;
27use postage::watch;
28use std::sync::Arc;
29
30pub use settings::Settings;
31
32action!(About);
33action!(Quit);
34action!(Authenticate);
35action!(AdjustBufferFontSize, f32);
36
37const MIN_FONT_SIZE: f32 = 6.0;
38
39pub struct AppState {
40 pub settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
41 pub settings: watch::Receiver<Settings>,
42 pub languages: Arc<language::LanguageRegistry>,
43 pub themes: Arc<settings::ThemeRegistry>,
44 pub rpc: Arc<rpc::Client>,
45 pub fs: Arc<dyn fs::Fs>,
46 pub channel_list: ModelHandle<ChannelList>,
47}
48
49pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
50 cx.add_global_action(quit);
51
52 cx.add_global_action({
53 let rpc = app_state.rpc.clone();
54 move |_: &Authenticate, cx| {
55 let rpc = rpc.clone();
56 cx.spawn(|cx| async move { rpc.authenticate_and_connect(&cx).log_err().await })
57 .detach();
58 }
59 });
60
61 cx.add_global_action({
62 let settings_tx = app_state.settings_tx.clone();
63
64 move |action: &AdjustBufferFontSize, cx| {
65 let mut settings_tx = settings_tx.lock();
66 let new_size = (settings_tx.borrow().buffer_font_size + action.0).max(MIN_FONT_SIZE);
67 settings_tx.borrow_mut().buffer_font_size = new_size;
68 cx.refresh_windows();
69 }
70 });
71
72 cx.add_bindings(vec![
73 Binding::new("cmd-=", AdjustBufferFontSize(1.), None),
74 Binding::new("cmd--", AdjustBufferFontSize(-1.), None),
75 ])
76}
77
78fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
79 cx.platform().quit();
80}