Remove checked-in theme JSON files

* Generate the themes on build
* In debug builds, watch the theme sources. When they change, re-generate
  the themes and reload the current theme, removing the need for the
  `theme_selector::Reload` command.

Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-05-18 12:22:14 -07:00
parent bdeac6b66a
commit ec41dd9f18
15 changed files with 72 additions and 12288 deletions

View file

@ -23,7 +23,6 @@ actions!(theme_selector, [Toggle, Reload]);
pub fn init(cx: &mut MutableAppContext) {
cx.add_action(ThemeSelector::toggle);
cx.add_action(ThemeSelector::reload);
Picker::<ThemeSelector>::init(cx);
}
@ -73,9 +72,9 @@ impl ThemeSelector {
});
}
fn reload(workspace: &mut Workspace, _: &Reload, cx: &mut ViewContext<Workspace>) {
#[cfg(debug_assertions)]
pub fn reload(themes: Arc<ThemeRegistry>, cx: &mut MutableAppContext) {
let current_theme_name = cx.global::<Settings>().theme.name.clone();
let themes = workspace.themes();
themes.clear();
match themes.get(&current_theme_name) {
Ok(theme) => {

View file

@ -1,3 +1,31 @@
use std::process::Command;
fn main() {
println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.14");
let output = Command::new("npm")
.current_dir("../../styles")
.args(["ci"])
.output()
.expect("failed to run npm");
if !output.status.success() {
panic!(
"failed to install theme dependencies {}",
String::from_utf8_lossy(&output.stderr)
);
}
let output = Command::new("npm")
.current_dir("../../styles")
.args(["run", "build-themes"])
.output()
.expect("failed to run npm");
if !output.status.success() {
panic!(
"build-themes script failed {}",
String::from_utf8_lossy(&output.stderr)
);
}
println!("cargo:rerun-if-changed=../../styles");
}

View file

@ -162,6 +162,8 @@ fn main() {
cx.font_cache().clone(),
);
cx.spawn(|cx| watch_themes(fs.clone(), themes.clone(), cx))
.detach();
cx.spawn(|cx| watch_keymap_file(keymap_file, cx)).detach();
let settings = cx.background().block(settings_rx.next()).unwrap();
@ -440,6 +442,43 @@ fn load_embedded_fonts(app: &App) {
.unwrap();
}
#[cfg(debug_assertions)]
async fn watch_themes(
fs: Arc<dyn Fs>,
themes: Arc<ThemeRegistry>,
mut cx: AsyncAppContext,
) -> Option<()> {
let mut events = fs
.watch("styles/src".as_ref(), Duration::from_millis(250))
.await;
while let Some(_) = events.next().await {
let output = Command::new("npm")
.current_dir("styles")
.args(["run", "build-themes"])
.output()
.await
.log_err()?;
if output.status.success() {
cx.update(|cx| theme_selector::ThemeSelector::reload(themes.clone(), cx))
} else {
eprintln!(
"build-themes script failed {}",
String::from_utf8_lossy(&output.stderr)
);
}
}
Some(())
}
#[cfg(not(debug_assertions))]
async fn watch_themes(
_fs: Arc<dyn Fs>,
_themes: Arc<ThemeRegistry>,
_cx: AsyncAppContext,
) -> Option<()> {
None
}
fn load_config_files(
app: &App,
fs: Arc<dyn Fs>,