Files
novem/src/app.rs

68 lines
1.6 KiB
Rust
Raw Normal View History

2026-04-20 15:13:26 +01:00
use gpui::{div, prelude::*};
use crate::dashboard;
2026-04-21 11:50:04 +01:00
use crate::query;
2026-04-20 15:13:26 +01:00
use crate::theme;
use crate::titlebar;
2026-04-21 11:50:04 +01:00
use crate::{api, app};
2026-04-20 15:13:26 +01:00
pub struct Global {
pub safe_area: gpui::Bounds<gpui::Pixels>,
2026-04-26 00:46:11 +01:00
pub theme_family: theme::ThemeFamily,
2026-04-20 15:13:26 +01:00
pub current_theme: theme::Theme,
2026-04-23 11:18:43 +01:00
pub rng: rand::prelude::ThreadRng,
2026-04-20 15:13:26 +01:00
}
pub struct Chrome {}
impl Chrome {
pub fn new(window: &mut gpui::Window, cx: &mut gpui::Context<Self>) -> Self {
cx.observe_window_appearance(window, |_, window, cx| {
2026-04-21 11:50:04 +01:00
cx.update_global::<app::Global, ()>(|global, cx| {
2026-04-26 00:46:11 +01:00
global.current_theme = global
.theme_family
.theme_for_appearance(window.appearance());
2026-04-21 11:50:04 +01:00
cx.notify();
2026-04-20 15:13:26 +01:00
});
})
.detach();
Self {}
}
}
impl gpui::Render for Chrome {
fn render(
&mut self,
_window: &mut gpui::Window,
cx: &mut gpui::Context<Self>,
) -> impl gpui::IntoElement {
2026-04-21 11:50:04 +01:00
let title_bar = cx.new(|cx| titlebar::TitleBar::new(cx));
2026-04-20 15:13:26 +01:00
let dashboard = cx.new(|_| dashboard::Screen {
text: "World".into(),
});
div()
2026-04-21 11:50:04 +01:00
.flex()
2026-04-20 15:13:26 +01:00
.flex_col()
2026-04-21 11:50:04 +01:00
.size_full()
2026-04-20 15:13:26 +01:00
.child(title_bar)
.child(dashboard)
}
}
impl gpui::Global for Global {}
2026-04-23 11:18:43 +01:00
pub fn current_theme(cx: &gpui::App) -> &theme::Theme {
2026-04-20 15:13:26 +01:00
&cx.global::<Global>().current_theme
}
2026-04-23 11:18:43 +01:00
pub fn rng(cx: &mut gpui::App) -> &mut rand::prelude::ThreadRng {
&mut cx.global_mut::<Global>().rng
}
2026-04-24 19:22:25 +01:00
pub fn query_store(cx: &gpui::App) -> &query::Store<api::QueryContext> {
2026-04-21 11:50:04 +01:00
cx.global::<query::Store<api::QueryContext>>()
2026-04-20 15:13:26 +01:00
}