eframe_template icon indicating copy to clipboard operation
eframe_template copied to clipboard

[Reference implementation] Service worker has no update functionality

Open Swarkin opened this issue 6 months ago • 2 comments

The service worker currently does not have functionality for updating when the source files have changed, and it also does not clean up files that are no longer needed (files present in the cache but not in filesToCache array).

Swarkin avatar Jul 25 '25 19:07 Swarkin

Implemented this in my project on this commit. Feel free to take inspiration and use code snippets if it helps implementing this feature in eframe_template.

Key features

Auto-update with custom modal inside egui

Image

Dynamic progress status and error display in HTML

Image

Uses the trunk initializer feature.

Image

No web_sys required to remove loading text

Implementation

Service worker changes

Custom trunk hook is used to create an unique sw.js file. The browser detects updates by checking if the registered service worker changed on the origin. By inserting something like the build timestamp at build time, we generate an unique file every time.

Image

This is then used to clear out any stale caches.

Image

HTML page changes

Added JS that takes care of reacting to the browser's built in update check and then tells the result to the Rust side using wasm_bindgen.

JavaScript side (this later calls into Rust code)

Image

Rust side (this value is then later checked in the UI code)

Image

Swarkin avatar Jul 26 '25 18:07 Swarkin

Why did I not submit a PR?

The issue is that my implementation is very specialized towards my app and I dont really know how to make a generalized implementation that would work for any project or fit the style guide / expected code architecture. It is also not very future proof as you might want to pass more data (like the load time for example) to the Rust side upon project load, but my impl currently only has a single static AtomicBool representing whether an update is available.

Swarkin avatar Jul 26 '25 18:07 Swarkin