use std::borrow::Cow;
use std::sync::atomic::{AtomicBool, Ordering};
use gpui_kit::App;
pub const UI: &str = "IBM Plex Sans";
pub const MONO: &str = "IBM Plex Mono";
pub const FILES: [&str; 4] = [
"fonts/IBMPlexSans-Regular.ttf",
"fonts/IBMPlexSans-SemiBold.ttf",
"fonts/IBMPlexMono-Regular.ttf",
"fonts/IBMPlexMono-SemiBold.ttf",
];
static LOADED: AtomicBool = AtomicBool::new(false);
pub fn load(cx: &mut App) -> bool {
let source = cx.asset_source().clone();
let mut fonts: Vec<Cow<'static, [u8]>> = Vec::new();
let mut found = [false; 4];
for (i, path) in FILES.iter().enumerate() {
if let Ok(Some(bytes)) = source.load(path) {
fonts.push(bytes);
found[i] = true;
}
}
let both = found[0] && found[2];
if !fonts.is_empty() && cx.text_system().add_fonts(fonts).is_ok() && both {
LOADED.store(true, Ordering::Relaxed);
}
loaded()
}
pub fn loaded() -> bool {
LOADED.load(Ordering::Relaxed)
}