mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-25 01:34:02 +00:00
Added internal flag that checks the last logged in user
This commit is contained in:
parent
6555d6f1c9
commit
a1889ad236
4 changed files with 74 additions and 5 deletions
|
@ -37,6 +37,7 @@ pub struct Settings {
|
|||
pub language_overrides: HashMap<Arc<str>, EditorSettings>,
|
||||
pub lsp: HashMap<Arc<str>, LspSettings>,
|
||||
pub theme: Arc<Theme>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -60,12 +60,19 @@ pub fn watch_settings_file(
|
|||
defaults: Settings,
|
||||
mut file: WatchedJsonFile<SettingsFileContent>,
|
||||
theme_registry: Arc<ThemeRegistry>,
|
||||
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<ThemeRegistry>,
|
||||
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,
|
||||
)
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue