Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web refactor and custom eframe and egui-wgpu #70

Merged
merged 50 commits into from
Dec 3, 2023

Conversation

white-axe
Copy link
Collaborator

@white-axe white-axe commented Nov 30, 2023

Connections

Description
This pull request adds modified versions of eframe and egui-wgpu into the crates directory after renaming the packages to luminol-eframe and luminol-egui-wgpu. The web runner has also been merged into eframe, including the change from a mutex to AtomicF64 for the time (although the removing of this lock is not strictly required because the web runner's time is inaccessible from the main thread).

The first commit in this pull request just adds eframe and egui-wgpu verbatim into the crates directory, so if you want to see the actual changes I made to those crates, use this comparison that excludes that commit: 498cd2b...c5a4b1b

Here is the list of other significant refactoring that was done to the web code:

  • The wgpu version has been bumped to 0.18. eframe and egui-wgpu are still based on egui version 0.23 though because catppuccin-egui hasn't upgraded to egui 0.24 yet.
  • The web runner and web filesystem are split into smaller files now.
  • The channels for the web runner and web filesystem are now created by helper functions inside their respective crates so main.rs doesn't have to be updated every time the types of those channels change.
  • The web filesystem uses closures for error handling now instead of a bunch of nested if statements.

There are also some new related features and bug fixes:

  • I fixed the random "Atomics.wait cannot be called in this context" crashes that were sometimes happening. They were being caused by a lock inside of flume blocking the main thread, so I made a fork at Astrabit-ST/flume with the problematic lock fixed and then patched the root Cargo.toml to use that fork. There's a relevant issue above.
  • Ctrl+O and Ctrl+F are now also intercepted by the web runner because I felt those would be useful as keyboard shortcuts.
  • eframe's text agent is now incorporated into the web runner. It handles input method editors (like opening the IME window and positioning it in the correct location) which are required to type in some languages.

ime

(egui's font doesn't support CJK characters, but I'll address this later.) This was fixed by #71.

Testing
In addition to generally checking that nothing in the web version of Luminol broke, to test the flume thing, try running the web version of Luminol before and after the changes in this pull request to see if the flume crash happens, or alternatively use the example I posted in the flume issue before and after patching flume in Cargo.toml with the forked version of flume. To test the text agent, install any IME and use it to type into the text boxes in the map picker or script editor in a web build. ArchWiki has a list of some Linux IMEs used for CJK/Indic input, but there are probably more for things like handwriting recognition.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo build --release
  • If applicable, run trunk build --release

Yes, I know it just renders a black rectangle right now. I'm getting to
the rest.
Relaxed ordering should be fine here.
We never need to acquire a read lock on `WORKER_DATA`.
This is something that eframe's original web runner supported that the
web worker runner didn't. It allows users to control Luminol via a
touchscreen display (like the one on the Microsoft Surface).

Chromium-based browsers have a "Device Mode" that emulates touch events
for those who lack devices with touchscreen displays.
This text agent allows eframe to trigger the onscreen keyboard (for
devices that lack a keyboard) and/or input method editor (for e.g.
Chinese/Japanese/Korean input) when the user edits an egui `TextEdit` in
web builds.
This allows TTS to work properly in web builds if it's enabled.
This reduces the amount of arguments we have to pass around.
This prevents these keyboard shortcuts from performing their default
behaviour in web browsers so we can use them in Luminol.
This encases all of the main thread event handlers for the web
filesystem in async blocks so that they can use the `?` operator for
proper error handling.
Under rare circumstances, flume channel senders can block. This
absolutely cannot happen on the main thread, so we need to force flume
to use spinlocks instead of mutexes. Enabling spinlocks doesn't seem to
change the way flume receivers' blocking receive method works, which is
good.
Flume's global spinlock uses `thread::sleep` which is not allowed in
WebAssembly, so I've removed `thread::sleep` from the spinlock.
Do or do not. There is no try.

Any instances of these borrows failing are unambiguous errors since they
all run on the main thread, so trying here is doing more harm than good.
This prevents us from having to change main.rs every time the channels
change.
I put these there originally so that I can do an easy replace with
`pub(super)` later if I needed to move things around.
This removes the name of the project file from the recent projects menu
in web for consistency with native.
@white-axe white-axe requested a review from a team as a code owner November 30, 2023 05:26
@melody-rs melody-rs requested a review from somedevfox November 30, 2023 22:02
@melody-rs melody-rs merged commit 016409a into Astrabit-ST:dev Dec 3, 2023
@melody-rs melody-rs added this to the v1.0 milestone Dec 3, 2023
@white-axe white-axe deleted the web-refactor branch December 3, 2023 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom egui app runner to replace eframe
2 participants