← All Workshops

MudEngine Part 10: Desktop with Blitz

Step 6 / 13

Configure the window

By default, the Blitz window opens at a reasonable size. You can customise it with dioxus_native::Config and dioxus_native::WindowAttributes.

This is optional — the MUD works fine with default settings. But it's useful to know how to control the window for a polished desktop feel.

To set a custom window title and size, add this before the launch call:

mud-engine/src/main.rs
// Native window types — compiled only for the desktop client.
#[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))]
use dioxus_native::{Config, LogicalSize, WindowAttributes};

// ...inside main() — this is the native-client arm:
#[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))]
{
    set_server_url("http://localhost:8080");
    let cfg = Config::new()
        .with_window_attributes(
            WindowAttributes::default()
                .with_title("MudEngine")
                .with_inner_size(LogicalSize::new(1024.0, 768.0)),
        );
    // 0.7.10 changed the signature: extra configs + window configs as boxed Vecs
    dioxus_native::launch_cfg(App, vec![], vec![Box::new(cfg)]);
}
🎯 The cfg split

main.rs is compiled three times, so each launch must sit behind the right cfg:

  1. Server binary — features = ["server"]: dioxus::launch(App) renders HTML on the server side.
  2. Web client — WASM target, web feature only: dioxus::launch(App) hydrates the SSR page.
  3. Native client — host target, no server feature: set_server_url(...) + dioxus_native::launch_cfg(...).

Without the split, the server would try to open a native window, and the WASM build would try to compile dioxus_native — which is gated out of the dependency graph (see Cargo.toml).

⚠️ Don't skip the cfg split

Do not replace this with a single unconditional dioxus_native::launch(App). Because dioxus-native is gated to native targets, the WASM build doesn't even have the crate available — the web client and the server would fail to compile with unresolved import dioxus_native. The three-way split is mandatory.

💡 Why this works

dx serve compiles two binaries from this one crate: the Axum server (with the server feature, host) and a WASM web client (the web feature). cargo run compiles the third: the host binary without the server feature, which opens the Blitz window.

Only the native arm links against dioxus_native. The server and web arms use dioxus::launch — the entry points those binaries actually run.

Step 6 / 13