#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use vegravis::MainApp;
#[cfg(not(target_arch = "wasm32"))]
fn main() -> Result<(), eframe::Error> {
env_logger::init(); let options = eframe::NativeOptions {
viewport: eframe::egui::ViewportBuilder::default().with_icon(
eframe::icon_data::from_png_bytes(&include_bytes!("../assets/icon-256.png")[..])
.expect("Failed to load icon"),
),
..Default::default()
};
eframe::run_native(
"Vector Graphics Visualizer",
options,
Box::new(|_cc| Ok(Box::<MainApp>::default())),
)
}
#[cfg(target_arch = "wasm32")]
fn main() {
use eframe::wasm_bindgen::JsCast as _;
eframe::WebLogger::init(log::LevelFilter::Debug).ok();
let web_options = eframe::WebOptions::default();
wasm_bindgen_futures::spawn_local(async {
let document = web_sys::window()
.expect("No window")
.document()
.expect("No document");
let canvas = document
.get_element_by_id("vegravis_canvas")
.expect("Failed to find vegravis_canvas")
.dyn_into::<web_sys::HtmlCanvasElement>()
.expect("vegravis_canvas was not a HtmlCanvasElement");
let start_result = eframe::WebRunner::new()
.start(
canvas,
web_options,
Box::new(|_cc| Ok(Box::<MainApp>::default())),
)
.await;
if let Some(loading_text) = document.get_element_by_id("loading_text") {
match start_result {
Ok(_) => {
loading_text.remove();
}
Err(e) => {
loading_text.set_inner_html(
"<p> The app has crashed. See the developer console for details. </p>",
);
panic!("Failed to start eframe: {e:?}");
}
}
}
});
}