mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-24 17:28:40 +00:00
Removed github username check, added settings file
This commit is contained in:
parent
afc3f3fe9c
commit
ec5d8f8c7c
5 changed files with 40 additions and 98 deletions
|
@ -37,7 +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,
|
||||
pub staff_mode: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||
|
@ -178,6 +178,8 @@ pub struct SettingsFileContent {
|
|||
pub lsp: HashMap<Arc<str>, LspSettings>,
|
||||
#[serde(default)]
|
||||
pub theme: Option<String>,
|
||||
#[serde(default)]
|
||||
pub staff_mode: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
|
@ -229,7 +231,8 @@ impl Settings {
|
|||
language_overrides: Default::default(),
|
||||
lsp: defaults.lsp.clone(),
|
||||
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
||||
internal: false,
|
||||
|
||||
staff_mode: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +241,6 @@ 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() {
|
||||
|
@ -265,7 +267,7 @@ impl Settings {
|
|||
merge(&mut self.vim_mode, data.vim_mode);
|
||||
merge(&mut self.autosave, data.autosave);
|
||||
merge(&mut self.experiments, data.experiments);
|
||||
|
||||
merge(&mut self.staff_mode, data.staff_mode);
|
||||
// Ensure terminal font is loaded, so we can request it in terminal_element layout
|
||||
if let Some(terminal_font) = &data.terminal.font_family {
|
||||
font_cache.load_family(&[terminal_font]).log_err();
|
||||
|
@ -276,7 +278,6 @@ impl Settings {
|
|||
self.terminal_overrides = data.terminal;
|
||||
self.language_overrides = data.languages;
|
||||
self.lsp = data.lsp;
|
||||
self.internal = internal
|
||||
}
|
||||
|
||||
pub fn with_language_defaults(
|
||||
|
@ -351,7 +352,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,
|
||||
staff_mode: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -407,27 +408,25 @@ pub fn settings_file_json_schema(
|
|||
("ThemeName".into(), theme_name_schema.into()),
|
||||
("Languages".into(), languages_object_schema.into()),
|
||||
]);
|
||||
root_schema
|
||||
.schema
|
||||
.object
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.properties
|
||||
.extend([
|
||||
(
|
||||
"theme".to_owned(),
|
||||
Schema::new_ref("#/definitions/ThemeName".into()),
|
||||
),
|
||||
(
|
||||
"languages".to_owned(),
|
||||
Schema::new_ref("#/definitions/Languages".into()),
|
||||
),
|
||||
// For backward compatibility
|
||||
(
|
||||
"language_overrides".to_owned(),
|
||||
Schema::new_ref("#/definitions/Languages".into()),
|
||||
),
|
||||
]);
|
||||
let root_schema_object = &mut root_schema.schema.object.as_mut().unwrap();
|
||||
|
||||
// Avoid automcomplete for non-user facing settings
|
||||
root_schema_object.properties.remove("staff_mode");
|
||||
root_schema_object.properties.extend([
|
||||
(
|
||||
"theme".to_owned(),
|
||||
Schema::new_ref("#/definitions/ThemeName".into()),
|
||||
),
|
||||
(
|
||||
"languages".to_owned(),
|
||||
Schema::new_ref("#/definitions/Languages".into()),
|
||||
),
|
||||
// For backward compatibility
|
||||
(
|
||||
"language_overrides".to_owned(),
|
||||
Schema::new_ref("#/definitions/Languages".into()),
|
||||
),
|
||||
]);
|
||||
|
||||
serde_json::to_value(root_schema).unwrap()
|
||||
}
|
||||
|
|
|
@ -40,10 +40,14 @@ impl ThemeSelector {
|
|||
let handle = cx.weak_handle();
|
||||
let picker = cx.add_view(|cx| Picker::new(handle, cx));
|
||||
let settings = cx.global::<Settings>();
|
||||
|
||||
let original_theme = settings.theme.clone();
|
||||
|
||||
let mut theme_names = registry
|
||||
.list(settings.internal, settings.experiments.experimental_themes)
|
||||
.list(
|
||||
settings.staff_mode,
|
||||
settings.experiments.experimental_themes,
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
theme_names.sort_unstable_by(|a, b| {
|
||||
a.is_light
|
||||
|
|
|
@ -21,10 +21,9 @@ use futures::{
|
|||
};
|
||||
use gpui::{executor::Background, App, AssetSource, AsyncAppContext, Task};
|
||||
use isahc::{config::Configurable, AsyncBody, Request};
|
||||
use language::{LanguageRegistry, Rope};
|
||||
use language::LanguageRegistry;
|
||||
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};
|
||||
|
@ -62,28 +61,6 @@ fn main() {
|
|||
|
||||
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 == "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);
|
||||
|
||||
|
@ -119,42 +96,10 @@ 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 {
|
||||
// When the user logs out, `user` is None.
|
||||
if user.is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let user_name = user.unwrap().github_login.clone();
|
||||
|
||||
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(),
|
||||
internal,
|
||||
cx,
|
||||
);
|
||||
watch_settings_file(default_settings, settings_file, themes.clone(), cx);
|
||||
watch_keymap_file(keymap_file, cx);
|
||||
|
||||
context_menu::init(cx);
|
||||
|
|
|
@ -60,19 +60,12 @@ 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,
|
||||
internal,
|
||||
cx,
|
||||
);
|
||||
settings_updated(&defaults, file.0.borrow().clone(), &theme_registry, cx);
|
||||
cx.spawn(|mut cx| async move {
|
||||
while let Some(content) = file.0.recv().await {
|
||||
cx.update(|cx| settings_updated(&defaults, content, &theme_registry, internal, cx));
|
||||
cx.update(|cx| settings_updated(&defaults, content, &theme_registry, cx));
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
@ -88,11 +81,10 @@ 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(), internal);
|
||||
settings.set_user_settings(content, theme_registry, cx.font_cache());
|
||||
cx.set_global(settings);
|
||||
cx.refresh_windows();
|
||||
}
|
||||
|
@ -154,7 +146,6 @@ mod tests {
|
|||
default_settings.clone(),
|
||||
source,
|
||||
ThemeRegistry::new((), font_cache),
|
||||
false,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
|
|
@ -248,7 +248,10 @@ pub fn initialize_workspace(
|
|||
|
||||
let theme_names = app_state
|
||||
.themes
|
||||
.list(settings.internal, settings.experiments.experimental_themes)
|
||||
.list(
|
||||
settings.staff_mode,
|
||||
settings.experiments.experimental_themes,
|
||||
)
|
||||
.map(|meta| meta.name)
|
||||
.collect();
|
||||
let language_names = &languages::LANGUAGE_NAMES;
|
||||
|
|
Loading…
Reference in a new issue