lib.rs

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