use std::{rc::Rc, sync::LazyLock};
use gpui::{App, Global};
use gpui_material_theme::MaterialStrings;
struct ActiveMaterialStrings(Rc<MaterialStrings>);
impl Global for ActiveMaterialStrings {}
static DEFAULT_STRINGS: LazyLock<MaterialStrings> = LazyLock::new(MaterialStrings::default);
pub(crate) fn init_default_strings(cx: &mut App) {
if !cx.has_global::<ActiveMaterialStrings>() {
cx.set_global(ActiveMaterialStrings(Rc::new(MaterialStrings::default())));
}
}
pub(crate) fn app_strings_handle(cx: &App) -> Rc<MaterialStrings> {
cx.try_global::<ActiveMaterialStrings>()
.map(|active| active.0.clone())
.unwrap_or_else(|| Rc::new(MaterialStrings::default()))
}
pub fn material_strings(cx: &App) -> &MaterialStrings {
cx.try_global::<ActiveMaterialStrings>()
.map(|active| active.0.as_ref())
.unwrap_or(&DEFAULT_STRINGS)
}
pub fn set_material_strings(strings: MaterialStrings, cx: &mut App) {
if cx
.try_global::<ActiveMaterialStrings>()
.is_some_and(|previous| *previous.0 == strings)
{
return;
}
cx.set_global(ActiveMaterialStrings(Rc::new(strings)));
cx.refresh_windows();
}