Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
tomara-x committed Oct 28, 2024
1 parent 21f0799 commit 0912f21
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
4 changes: 2 additions & 2 deletions assets/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var cacheName = 'egui-template-pwa';
var filesToCache = [
'./',
'./index.html',
'./eframe_template.js',
'./eframe_template_bg.wasm',
'./lapis.js',
'./lapis_bg.wasm',
];

/* Start the service worker and cache all of the app's content */
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<head>
<!-- change this to your project name -->
<title>eframe template</title>
<title>awawawa</title>

<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
<link data-trunk rel="rust" data-wasm-opt="2" />
Expand Down
42 changes: 42 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use cpal::traits::{DeviceTrait, HostTrait};
use eframe::egui::*;

Expand All @@ -6,6 +8,7 @@ mod components;
mod eval;
use {audio::*, components::*, eval::*};

#[cfg(not(target_arch = "wasm32"))]
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: ViewportBuilder {
Expand All @@ -19,6 +22,45 @@ fn main() -> eframe::Result {
eframe::run_native("awawawa", options, Box::new(|_| Ok(Box::new(Lapis::new()))))
}

#[cfg(target_arch = "wasm32")]
fn main() {
use eframe::wasm_bindgen::JsCast as _;

// Redirect `log` message to `console.log` and friends:
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("the_canvas_id")
.expect("Failed to find the_canvas_id")
.dyn_into::<web_sys::HtmlCanvasElement>()
.expect("the_canvas_id was not a HtmlCanvasElement");

let start_result = eframe::WebRunner::new()
.start(canvas, web_options, Box::new(|_| Ok(Box::new(Lapis::new()))))
.await;

// Remove the loading text and spinner:
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:?}");
}
}
}
});
}

impl eframe::App for Lapis {
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
let center = Align2::CENTER_CENTER;
Expand Down

0 comments on commit 0912f21

Please sign in to comment.