Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
stub out the theme stuff only for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
jkelleyrtp committed Feb 4, 2025
1 parent 5fe37c4 commit 0e77d14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ example-projects = { path = "example-projects" }
# Dioxus Release
dioxus = "0.6.2"
dioxus-document = "0.6.2"
dioxus-sdk = "0.6"
dioxus-sdk = { version = "0.6", default-features = false }
dioxus-core = "0.6.2"
dioxus-core-types = "0.6.2"
dioxus-devtools = "0.6.2"
Expand Down
6 changes: 5 additions & 1 deletion playground/src/editor/monaco.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::hotreload::HotReload;
use dioxus::prelude::*;
use dioxus_sdk::{theme::SystemTheme, utils::timing::UseDebounce};
use dioxus_sdk::utils::timing::UseDebounce;
use model::{CargoDiagnostic, CargoLevel};
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -50,6 +50,7 @@ pub fn set_monaco_markers(diagnostics: Signal<Vec<CargoDiagnostic>>) {
}

/// Initialize Monaco once the loader script loads.
#[cfg(target_arch = "wasm32")]
pub fn on_monaco_load(
folder: Asset,
system_theme: SystemTheme,
Expand Down Expand Up @@ -138,6 +139,7 @@ extern "C" {
fn register_model_change_event(callback: &Closure<dyn FnMut(String)>);
}

#[cfg(target_arch = "wasm32")]
pub fn init(
vs_path_prefix: &str,
element_id: &str,
Expand All @@ -149,6 +151,7 @@ pub fn init(
register_paste_as_rsx_action();
}

#[cfg(target_arch = "wasm32")]
pub fn set_theme(theme: SystemTheme) {
let theme = system_theme_to_string(theme);
set_monaco_theme(&theme);
Expand All @@ -165,6 +168,7 @@ fn register_paste_as_rsx_action() {
callback.forget();
}

#[cfg(target_arch = "wasm32")]
fn system_theme_to_string(theme: SystemTheme) -> String {
match theme {
SystemTheme::Light => "dx-vs",
Expand Down
9 changes: 5 additions & 4 deletions playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dioxus_sdk::{
theme::{use_system_theme, SystemTheme},
utils::timing::use_debounce,
};
use editor::monaco::{self, monaco_loader_src, on_monaco_load, set_monaco_markers};
use editor::monaco::{self, monaco_loader_src, set_monaco_markers};
use example_projects::ExampleProject;
use hotreload::{attempt_hot_reload, HotReload};
// use snippets::use_provide_selected_example;
Expand Down Expand Up @@ -71,8 +71,8 @@ pub fn Playground(
// Themes
let system_theme = use_system_theme();
use_effect(move || {
let theme = system_theme().unwrap_or(SystemTheme::Light);
editor::monaco::set_theme(theme);
#[cfg(target_arch = "wasm32")]
editor::monaco::set_theme(system_theme().unwrap_or(SystemTheme::Light));
});

// The current contents of the editor.
Expand Down Expand Up @@ -124,7 +124,8 @@ pub fn Playground(
script {
src: monaco_loader_src(MONACO_FOLDER),
onload: move |_| {
on_monaco_load(
#[cfg(target_arch = "wasm32")]
monaco::on_monaco_load(
MONACO_FOLDER,
system_theme().unwrap_or(SystemTheme::Light),
&contents(),
Expand Down

0 comments on commit 0e77d14

Please sign in to comment.