use gpui::AppContext; use gpui::BorrowAppContext; use crate::api; use crate::query; use crate::theme; pub struct Global { pub safe_area: gpui::Bounds, pub theme_family: theme::ThemeFamily, pub current_theme: theme::Theme, pub rng: rand::prelude::ThreadRng, } impl gpui::Global for Global {} pub fn current_theme(cx: &gpui::App) -> &theme::Theme { &cx.global::().current_theme } pub fn rng(cx: &mut gpui::App) -> &mut rand::prelude::ThreadRng { &mut cx.global_mut::().rng } pub fn query_store(cx: &gpui::App) -> &query::Store { cx.global::>() } pub fn open_window( cx: &mut gpui::App, options: gpui::WindowOptions, screen: impl FnOnce(&mut gpui::Window, &mut gpui::Context) -> V, ) -> anyhow::Result<()> where V: gpui::Render, { cx.open_window(options, |window, cx| { cx.new(|cx| { cx.observe_window_appearance(window, |_, window, cx| { cx.update_global::(|global, cx| { global.current_theme = global .theme_family .theme_for_appearance(window.appearance()); cx.notify(); }); }) .detach(); screen(window, cx) }) }) .map(|_| ()) }