migrate theming to gpui-native-kit
This commit is contained in:
+2
-1
@@ -22,7 +22,8 @@ person = { path = "../crates/person" }
|
||||
gpui.workspace = true
|
||||
gpui_platform.workspace = true
|
||||
gpui_web.workspace = true
|
||||
gpui-kit.workspace = true
|
||||
gpui-native-kit.workspace = true
|
||||
speech = { path = "../crates/speech" }
|
||||
|
||||
log.workspace = true
|
||||
instant = { workspace = true, features = ["wasm-bindgen"] }
|
||||
|
||||
+18
-34
@@ -1,10 +1,10 @@
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::*;
|
||||
use gpui_native_kit::theme::ActiveTheme;
|
||||
use universal_time::{Instant, MonotonicClock, SystemTime, WallClock, define_time_provider};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
@@ -83,16 +83,15 @@ pub fn run() -> Result<(), JsValue> {
|
||||
KeyBinding::new("ctrl-d", chat_ui::ToggleDictation, None),
|
||||
]);
|
||||
|
||||
gpui_kit::init(cx);
|
||||
gpui_native_kit::init(cx);
|
||||
speech::init_compat(cx);
|
||||
|
||||
load_embedded_fonts(cx);
|
||||
apply_web_fonts(cx);
|
||||
|
||||
// Initialize settings
|
||||
settings::init(cx);
|
||||
|
||||
apply_appearance(settings::persisted_appearance_mode(), cx);
|
||||
settings::AppSettings::apply_theme_style(cx);
|
||||
workspace::apply_appearance_mode(settings::persisted_appearance_mode(), cx);
|
||||
|
||||
// Initialize the nostr client
|
||||
state::init(cx, None);
|
||||
@@ -111,7 +110,20 @@ pub fn run() -> Result<(), JsValue> {
|
||||
// Initialize groups registry
|
||||
nip29::init(cx);
|
||||
|
||||
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
|
||||
let opts = WindowOptions {
|
||||
window_background: cx.theme().window_background,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
cx.open_window(opts, |window, cx| {
|
||||
gpui_native_kit::theme::Theme::sync_from_window(window, cx);
|
||||
gpui_native_kit::theme::Theme::sync_window_rem_size(window, cx);
|
||||
window
|
||||
.observe_window_appearance(|window, cx| {
|
||||
gpui_native_kit::theme::Theme::sync_from_window(window, cx);
|
||||
cx.refresh_windows();
|
||||
})
|
||||
.detach();
|
||||
workspace::init(window, cx)
|
||||
})
|
||||
.expect("Failed to open window. Please restart the application.");
|
||||
@@ -139,31 +151,3 @@ fn load_embedded_fonts(cx: &mut App) {
|
||||
.add_fonts(fonts)
|
||||
.expect("Failed to load bundled fonts");
|
||||
}
|
||||
|
||||
fn apply_web_fonts(cx: &mut App) {
|
||||
use gpui_kit::component::Theme;
|
||||
|
||||
const UI_FONT: &str = "Inter";
|
||||
|
||||
Theme::update(cx, |theme| {
|
||||
theme.font_family = UI_FONT.into();
|
||||
theme.mono_font_family = UI_FONT.into();
|
||||
|
||||
for config in [&mut theme.light_theme, &mut theme.dark_theme] {
|
||||
let config = Rc::make_mut(config);
|
||||
config.font_family = Some(UI_FONT.into());
|
||||
config.mono_font_family = Some(UI_FONT.into());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Honor the appearance mode against the default palettes
|
||||
fn apply_appearance(appearance: settings::AppearanceMode, cx: &mut App) {
|
||||
use gpui_kit::component::{Theme, ThemeMode};
|
||||
|
||||
match appearance {
|
||||
settings::AppearanceMode::System => Theme::sync_system_appearance(None, cx),
|
||||
settings::AppearanceMode::Light => Theme::change(ThemeMode::Light, None, cx),
|
||||
settings::AppearanceMode::Dark => Theme::change(ThemeMode::Dark, None, cx),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user