Skip to content

Commit aaf1a97

Browse files
committed
fix: repair wasm version after upgrade
1 parent 24be0b4 commit aaf1a97

File tree

7 files changed

+62
-23
lines changed

7 files changed

+62
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ tokio = { version = "1.35.1", features = ["full"] }
3131
[target.'cfg(target_arch = "wasm32")'.dependencies]
3232
poll-promise = { version = "0.3.0", features = ["web"] }
3333
wasm-bindgen-futures = "0.4.49"
34+
web-sys = "0.3.76"
3435

3536
[profile.release]
3637
opt-level = 2 # fast and small wasm

Trunk.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
[build]
2+
filehash = false

assets/manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"short_name": "log-viewer-pwa",
44
"icons": [
55
{
6-
"src": "./icon-256.png",
6+
"src": "./assets/icon-256.png",
77
"sizes": "256x256",
88
"type": "image/png"
99
},
1010
{
11-
"src": "./maskable_icon_x512.png",
11+
"src": "./assets/maskable_icon_x512.png",
1212
"sizes": "512x512",
1313
"type": "image/png",
1414
"purpose": "any maskable"
1515
},
1616
{
17-
"src": "./icon-1024.png",
17+
"src": "./assets/icon-1024.png",
1818
"sizes": "1024x1024",
1919
"type": "image/png"
2020
}
@@ -25,4 +25,4 @@
2525
"display": "standalone",
2626
"background_color": "white",
2727
"theme_color": "white"
28-
}
28+
}

assets/sw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ var cacheName = 'log-viewer-pwa';
22
var filesToCache = [
33
'./',
44
'./index.html',
5-
'./log_viewer.js',
6-
'./log_viewer_bg.wasm',
5+
'./log-viewer.js',
6+
'./log-viewer_bg.wasm',
77
];
88

99
/* Start the service worker and cache all of the app's content */

index.html

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
<link data-trunk rel="icon" href="assets/favicon.ico">
1818

1919

20-
<link data-trunk rel="copy-file" href="assets/sw.js" />
21-
<link data-trunk rel="copy-file" href="assets/manifest.json" />
22-
<link data-trunk rel="copy-file" href="assets/icon-1024.png" />
23-
<link data-trunk rel="copy-file" href="assets/icon-256.png" />
24-
<link data-trunk rel="copy-file" href="assets/icon_ios_touch_192.png" />
25-
<link data-trunk rel="copy-file" href="assets/maskable_icon_x512.png" />
20+
<link data-trunk rel="copy-file" href="assets/sw.js"/>
21+
<link data-trunk rel="copy-file" href="assets/manifest.json"/>
22+
<link data-trunk rel="copy-file" href="assets/icon-1024.png" data-target-path="assets"/>
23+
<link data-trunk rel="copy-file" href="assets/icon-256.png" data-target-path="assets"/>
24+
<link data-trunk rel="copy-file" href="assets/icon_ios_touch_192.png" data-target-path="assets"/>
25+
<link data-trunk rel="copy-file" href="assets/maskable_icon_x512.png" data-target-path="assets"/>
2626

2727

2828
<link rel="manifest" href="manifest.json">
29-
<link rel="apple-touch-icon" href="icon_ios_touch_192.png">
29+
<link rel="apple-touch-icon" href="assets/icon_ios_touch_192.png">
3030
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
3131
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#404040">
3232

@@ -60,15 +60,16 @@
6060
width: 100%;
6161
}
6262

63-
/* Position canvas in center-top: */
63+
/* Make canvas fill entire document: */
6464
canvas {
6565
margin-right: auto;
6666
margin-left: auto;
6767
display: block;
6868
position: absolute;
69-
top: 0%;
70-
left: 50%;
71-
transform: translate(-50%, 0%);
69+
top: 0;
70+
left: 0;
71+
width: 100%;
72+
height: 100%;
7273
}
7374

7475
.centered {
@@ -122,6 +123,14 @@
122123
<!-- the id is hardcoded in main.rs . so, make sure both match. -->
123124
<canvas id="the_canvas_id"></canvas>
124125

126+
<!-- the loading spinner will be removed in main.rs -->
127+
<div class="centered" id="loading_text">
128+
<p style="font-size:16px">
129+
Loading…
130+
</p>
131+
<div class="lds-dual-ring"></div>
132+
</div>
133+
125134
<!--Register Service Worker. this will cache the wasm / js scripts for offline use (for PWA functionality). -->
126135
<!-- Force refresh (Ctrl + F5) to load the latest files instead of cached files -->
127136
<script>
@@ -136,4 +145,4 @@
136145

137146
</html>
138147

139-
<!-- Powered by egui: https://github.com/emilk/egui/ -->
148+
<!-- Powered by egui: https://github.com/emilk/egui/ -->

src/main.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,46 @@ async fn main() -> eframe::Result<()> {
2727
// When compiling to web using trunk:
2828
#[cfg(target_arch = "wasm32")]
2929
fn main() {
30+
use eframe::wasm_bindgen::JsCast as _;
31+
3032
// Redirect `log` message to `console.log` and friends:
3133
eframe::WebLogger::init(log::LevelFilter::Debug).ok();
3234

3335
let web_options = eframe::WebOptions::default();
3436

3537
wasm_bindgen_futures::spawn_local(async {
36-
eframe::WebRunner::new()
38+
let document = web_sys::window()
39+
.expect("No window")
40+
.document()
41+
.expect("No document");
42+
43+
let canvas = document
44+
.get_element_by_id("the_canvas_id")
45+
.expect("Failed to find the_canvas_id")
46+
.dyn_into::<web_sys::HtmlCanvasElement>()
47+
.expect("the_canvas_id was not a HtmlCanvasElement");
48+
49+
let start_result = eframe::WebRunner::new()
3750
.start(
38-
"the_canvas_id", // hardcode it
51+
canvas,
3952
web_options,
40-
Box::new(|cc| Box::new(log_viewer::LogViewerApp::new(cc))),
53+
Box::new(|cc| Ok(Box::new(log_viewer::LogViewerApp::new(cc)))),
4154
)
42-
.await
43-
.expect("failed to start eframe");
55+
.await;
56+
57+
// Remove the loading text and spinner:
58+
if let Some(loading_text) = document.get_element_by_id("loading_text") {
59+
match start_result {
60+
Ok(_) => {
61+
loading_text.remove();
62+
}
63+
Err(e) => {
64+
loading_text.set_inner_html(
65+
"<p> The app has crashed. See the developer console for details. </p>",
66+
);
67+
panic!("Failed to start eframe: {e:?}");
68+
}
69+
}
70+
}
4471
});
4572
}

0 commit comments

Comments
 (0)