Skip to content

Commit dd20974

Browse files
committed
refactor(bevy_workbench): conditionally compile native-only features
The Cargo.toml was updated to explicitly list Bevy features and move the `rfd` dependency behind a `cfg(not(target_arch = "wasm32"))` condition. The `menu_bar.rs` and `settings_panel_ui` functions were refactored to wrap file dialog operations in `#[cfg(not(target_arch = "wasm32"))]` blocks, ensuring the codebase is compatible with WebAssembly targets by excluding native-only file system operations.
1 parent 8d64c89 commit dd20974

2 files changed

Lines changed: 48 additions & 22 deletions

File tree

Cargo.toml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,23 @@ name = "control_link"
1818
path = "examples/control_link.rs"
1919

2020
[dependencies]
21-
bevy = "0.18"
21+
bevy = { version = "0.18", default-features = false, features = [
22+
"std",
23+
"multi_threaded",
24+
"async_executor",
25+
"reflect_auto_register",
26+
"bevy_asset",
27+
"bevy_camera",
28+
"bevy_color",
29+
"bevy_core_pipeline",
30+
"bevy_image",
31+
"bevy_log",
32+
"bevy_picking",
33+
"bevy_render",
34+
"bevy_state",
35+
"bevy_window",
36+
"png",
37+
] }
2238
bevy_egui = { version = "0.39", features = ["render"] }
2339
bevy-inspector-egui = "0.36"
2440
egui_tiles = { version = "0.14", features = ["serde"] }
@@ -27,11 +43,13 @@ catppuccin-egui = { version = "5.7", default-features = false, features = ["egui
2743
serde = { version = "1", features = ["derive"] }
2844
serde_json = "1"
2945
toml = "0.8"
30-
rfd = "0.17"
3146
fluent = "0.17"
3247
fluent-bundle = "0.16"
3348
unic-langid = "0.9"
3449
sys-locale = "0.3"
3550

51+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
52+
rfd = "0.17"
53+
3654
[dev-dependencies]
37-
bevy = "0.18"
55+
bevy = { version = "0.18", features = ["bevy_winit", "default_font", "x11"] }

src/menu_bar.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -312,28 +312,31 @@ fn edit_menu_ui(
312312

313313
/// View menu content, extracted to reduce nesting.
314314
fn view_menu_ui(ui: &mut egui::Ui, i18n: &crate::i18n::I18n, tile_state: &mut TileLayoutState) {
315-
if ui.button(i18n.t("menu-view-save-layout")).clicked() {
316-
if let Some(path) = rfd::FileDialog::new()
317-
.set_title(i18n.t("dialog-save-layout"))
318-
.add_filter("JSON", &["json"])
319-
.set_file_name("layout.json")
320-
.save_file()
321-
{
322-
tile_state.layout_save_path = Some(path);
315+
#[cfg(not(target_arch = "wasm32"))]
316+
{
317+
if ui.button(i18n.t("menu-view-save-layout")).clicked() {
318+
if let Some(path) = rfd::FileDialog::new()
319+
.set_title(i18n.t("dialog-save-layout"))
320+
.add_filter("JSON", &["json"])
321+
.set_file_name("layout.json")
322+
.save_file()
323+
{
324+
tile_state.layout_save_path = Some(path);
325+
}
326+
ui.close();
323327
}
324-
ui.close();
325-
}
326-
if ui.button(i18n.t("menu-view-load-layout")).clicked() {
327-
if let Some(path) = rfd::FileDialog::new()
328-
.set_title(i18n.t("dialog-load-layout"))
329-
.add_filter("JSON", &["json"])
330-
.pick_file()
331-
{
332-
tile_state.layout_load_path = Some(path);
328+
if ui.button(i18n.t("menu-view-load-layout")).clicked() {
329+
if let Some(path) = rfd::FileDialog::new()
330+
.set_title(i18n.t("dialog-load-layout"))
331+
.add_filter("JSON", &["json"])
332+
.pick_file()
333+
{
334+
tile_state.layout_load_path = Some(path);
335+
}
336+
ui.close();
333337
}
334-
ui.close();
338+
ui.separator();
335339
}
336-
ui.separator();
337340
if ui.button(i18n.t("menu-view-reset-layout")).clicked() {
338341
tile_state.layout_reset_requested = true;
339342
ui.close();
@@ -491,13 +494,18 @@ fn settings_panel_ui(panel: &mut SettingsPanel, ui: &mut egui::Ui) {
491494

492495
ui.label("Custom Font:");
493496
let display = panel.edited_font_path.as_deref().unwrap_or("(embedded)");
497+
#[cfg(not(target_arch = "wasm32"))]
494498
if ui.button(display).clicked()
495499
&& let Some(path) = rfd::FileDialog::new()
496500
.add_filter("Font", &["otf", "ttf", "ttc"])
497501
.pick_file()
498502
{
499503
panel.edited_font_path = Some(path.display().to_string());
500504
}
505+
#[cfg(target_arch = "wasm32")]
506+
{
507+
ui.label(display);
508+
}
501509
ui.end_row();
502510
});
503511

0 commit comments

Comments
 (0)