Make file types live reload

This commit is contained in:
Mikayla Maki 2023-07-17 13:09:47 -07:00
parent 96ef6ab326
commit 8c855680e7
No known key found for this signature in database
4 changed files with 68 additions and 33 deletions

View file

@ -166,6 +166,7 @@ fn main() {
cx.spawn(|cx| watch_themes(fs.clone(), cx)).detach();
cx.spawn(|_| watch_languages(fs.clone(), languages.clone()))
.detach();
watch_file_types(fs.clone(), cx);
languages.set_theme(theme::current(cx).clone());
cx.observe_global::<SettingsStore, _>({
@ -685,6 +686,25 @@ async fn watch_languages(fs: Arc<dyn Fs>, languages: Arc<LanguageRegistry>) -> O
Some(())
}
#[cfg(debug_assertions)]
fn watch_file_types(fs: Arc<dyn Fs>, cx: &mut AppContext) {
cx.spawn(|mut cx| async move {
let mut events = fs
.watch(
"assets/icons/file_icons/file_types.json".as_ref(),
Duration::from_millis(100),
)
.await;
while (events.next().await).is_some() {
cx.update(|cx| {
cx.update_global(|file_types, _| {
*file_types = project_panel::file_associations::FileAssociations::new(Assets);
});
})
}
}).detach()
}
#[cfg(not(debug_assertions))]
async fn watch_themes(_fs: Arc<dyn Fs>, _cx: AsyncAppContext) -> Option<()> {
None
@ -695,6 +715,11 @@ async fn watch_languages(_: Arc<dyn Fs>, _: Arc<LanguageRegistry>) -> Option<()>
None
}
#[cfg(not(debug_assertions))]
fn watch_file_types(fs: Arc<dyn Fs>, cx: &mut AppContext) {
None
}
fn connect_to_cli(
server_name: &str,
) -> Result<(mpsc::Receiver<CliRequest>, IpcSender<CliResponse>)> {