From a1889ad23665f1bf51ea1c7f6f09fe1cced892d4 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 8 Sep 2022 13:31:04 -0700 Subject: [PATCH] Added internal flag that checks the last logged in user --- crates/settings/src/settings.rs | 5 +++ crates/zed/src/main.rs | 58 +++++++++++++++++++++++++++++++-- crates/zed/src/paths.rs | 1 + crates/zed/src/settings_file.rs | 15 +++++++-- 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 895a0bc363..4e4bd8c8c3 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -37,6 +37,7 @@ pub struct Settings { pub language_overrides: HashMap, EditorSettings>, pub lsp: HashMap, LspSettings>, pub theme: Arc, + pub internal: bool, } #[derive(Copy, Clone, Debug, Default, Deserialize, JsonSchema)] @@ -226,6 +227,7 @@ impl Settings { language_overrides: Default::default(), lsp: defaults.lsp.clone(), theme: themes.get(&defaults.theme.unwrap()).unwrap(), + internal: false, } } @@ -234,6 +236,7 @@ impl Settings { data: SettingsFileContent, theme_registry: &ThemeRegistry, font_cache: &FontCache, + internal: bool, ) { if let Some(value) = &data.buffer_font_family { if let Some(id) = font_cache.load_family(&[value]).log_err() { @@ -271,6 +274,7 @@ impl Settings { self.terminal_overrides = data.terminal; self.language_overrides = data.languages; self.lsp = data.lsp; + self.internal = internal } pub fn with_language_defaults( @@ -345,6 +349,7 @@ impl Settings { lsp: Default::default(), projects_online_by_default: true, theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), Default::default), + internal: false, } } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 141355742a..1db6656fb3 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -21,9 +21,10 @@ use futures::{ }; use gpui::{executor::Background, App, AssetSource, AsyncAppContext, Task}; use isahc::{config::Configurable, AsyncBody, Request}; -use language::LanguageRegistry; +use language::{LanguageRegistry, Rope}; use log::LevelFilter; use parking_lot::Mutex; +use postage::stream::Stream; use project::{Fs, ProjectStore}; use serde_json::json; use settings::{self, KeymapFileContent, Settings, SettingsFileContent}; @@ -60,6 +61,30 @@ fn main() { load_embedded_fonts(&app); let fs = Arc::new(RealFs); + + let internal = smol::block_on({ + let fs = fs.clone(); + + async move { + fs.load(&*zed::paths::LAST_USERNAME) + .await + .map(|github| { + &github == "as-cii" + || &github == "ForLoveOfCats" + || &github == "ForLoveOfCats" + || &github == "gibusu" + || &github == "iamnbutler" + || &github == "JosephTLyons" + || &github == "Kethku" + || &github == "maxbrunsfeld" + || &github == "mikayla-maki" + || &github == "nathansobo" + || &github == "slightknack" + }) + .unwrap_or(false) + } + }); + let themes = ThemeRegistry::new(Assets, app.font_cache()); let default_settings = Settings::defaults(Assets, &app.font_cache(), &themes); @@ -95,10 +120,39 @@ fn main() { .spawn(languages::init(languages.clone(), cx.background().clone())); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx)); + // Watch for the current user so we can set the internal flag + let mut current_user = user_store.read(cx).watch_current_user(); + cx.background() + .spawn({ + let fs = fs.clone(); + async move { + while let Some(user) = current_user.recv().await { + let user_name = user + .map(|user| user.github_login.clone()) + .unwrap_or_else(|| String::new()); + + fs.save( + &*zed::paths::LAST_USERNAME, + &Rope::from(user_name.as_str()), + Default::default(), + ) + .await + .ok(); + } + } + }) + .detach(); + let (settings_file, keymap_file) = cx.background().block(config_files).unwrap(); //Setup settings global before binding actions - watch_settings_file(default_settings, settings_file, themes.clone(), cx); + watch_settings_file( + default_settings, + settings_file, + themes.clone(), + internal, + cx, + ); watch_keymap_file(keymap_file, cx); context_menu::init(cx); diff --git a/crates/zed/src/paths.rs b/crates/zed/src/paths.rs index 6643cc0fe6..d6d99288c7 100644 --- a/crates/zed/src/paths.rs +++ b/crates/zed/src/paths.rs @@ -9,6 +9,7 @@ lazy_static::lazy_static! { pub static ref DB: PathBuf = DB_DIR.join("zed.db"); pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json"); pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json"); + pub static ref LAST_USERNAME: PathBuf = CONFIG_DIR.join("last-username.txt"); pub static ref LOG: PathBuf = LOGS_DIR.join("Zed.log"); pub static ref OLD_LOG: PathBuf = LOGS_DIR.join("Zed.log.old"); } diff --git a/crates/zed/src/settings_file.rs b/crates/zed/src/settings_file.rs index 14c9f63e95..6d28efbcbc 100644 --- a/crates/zed/src/settings_file.rs +++ b/crates/zed/src/settings_file.rs @@ -60,12 +60,19 @@ pub fn watch_settings_file( defaults: Settings, mut file: WatchedJsonFile, theme_registry: Arc, + internal: bool, cx: &mut MutableAppContext, ) { - settings_updated(&defaults, file.0.borrow().clone(), &theme_registry, cx); + settings_updated( + &defaults, + file.0.borrow().clone(), + &theme_registry, + internal, + cx, + ); cx.spawn(|mut cx| async move { while let Some(content) = file.0.recv().await { - cx.update(|cx| settings_updated(&defaults, content, &theme_registry, cx)); + cx.update(|cx| settings_updated(&defaults, content, &theme_registry, internal, cx)); } }) .detach(); @@ -81,10 +88,11 @@ pub fn settings_updated( defaults: &Settings, content: SettingsFileContent, theme_registry: &Arc, + internal: bool, cx: &mut MutableAppContext, ) { let mut settings = defaults.clone(); - settings.set_user_settings(content, theme_registry, cx.font_cache()); + settings.set_user_settings(content, theme_registry, cx.font_cache(), internal); cx.set_global(settings); cx.refresh_windows(); } @@ -146,6 +154,7 @@ mod tests { default_settings.clone(), source, ThemeRegistry::new((), font_cache), + false, cx, ) });