[sword-devel] Sword and WebAssembly
Donna Whisnant
dewhisna at dewtronics.com
Tue Nov 17 23:25:46 EST 2020
Hi Loren,
It's not "Sword" per se, but I have ported my King James Pure Bible Search (KJPBS) software to WASM (in addition to VNC, WebChannel, and native platform executables). It is also in Qt. I even had it running as a "WASM" before WASM -- back in the early days of Emscripten-Qt.
My main website is at:
https://www.purebiblesearch.com/
And you can launch the webassembly from here:
https://www.purebiblesearch.com/online/webassembly.html
It's quite huge at around 24megs of .wasm and 80megs of .data, which the browser has to "compile" after downloading (more like unzip and setup memory structures). That actually includes three Bible databases too, if I'm not mistaken.
As mentioned earlier in this thread, if you want to do any local file accesses, it's all sandboxed and in a specific local data store on the user's machine. I only use that for settings and such and have the module data downloaded from the upstream CDN along with the rest of it.
The other big thing you'll have issues with (which I still haven't totally resolved) is clipboard operations. The browser has all of that sandboxed as well, but it's sort of weird with what works and what doesn't work -- experiment with it and you'll see what I mean. And of course even that varies from browser to browser.
And I still even have the old Emscripten-Qt version online:
https://www.purebiblesearch.com/online/emscripten.html
In some ways, it actually works better than the newer WASM variant, but was impossible to maintain. It's still there as a novelty.
I guess in some ways, the WASM version is somewhat a novelty too. For most users who want to access KJPBS online, I suggest they use either the WebChannel version at:
https://webchannel.purebiblesearch.com/
Or the VNC version at:
https://vnc.purebiblesearch.com/
Or just download the native desktop version and run it locally. Since it's Qt, I have native executables for Windows, Linux, and Mac. I love Qt's portability.
If you want to see any details, the source is all on GitHub (just follow the link on the main page). Since I already had it for Emscripten, the WASM path mostly followed it. Oh yeah, there were also some weird asynchronous dialog issues I had to contend with. On the version of WASM I built it on, it was necessary for modal dialogs to "exit" and return back to the main outer event loop rather than run a separate event loop. The trick, though, was to keep it still as a modal dialog and especially when the caller of the modal dialog was expecting a return value -- lambdas to the rescue there! I don't know if they've improved that on newer versions of WASM or not. I suspect so, but it's still something to be aware of.
Good luck with it!
Donna
> Date: Tue, 17 Nov 2020 22:20:26 -0500
> From: Loren Burkholder <computersemiexpert at outlook.com>
>
> Thanks for the suggestions, Greg. One positive thing for me is that I
> am using Qt, and Qt has a macro Q_OS_WASM that is defined when you are
> building for WASM. I'm planning to use this, if necessary, to
> circumvent WASM limitations by removing/rethinking features when in
> WASM. Also, settings that require program reloads are not (in my
> experience) stored between loads of the WASM app. Therefore, the
> Q_OS_WASM macro could be used to simply cut such features from the WASM
> build.
>
> One thing to consider, as far as modules are concerned, is that if
> somebody is using the WebAssembly build of a program, they almost
> certainly will have a working internet connection at some point. This
> could mean that the program could simply download a basic module--like
> KJV--at startup, and give the user the option to download others
> straight from the web. Alternatively, embedded resources work just fine
> in WASM (that's how I've been delivering the Bible in my app up until
> now), so the KJV module could be embedded with the option to install
> others.
>
> About CLucene--is that something that is used in Sword by default or is
> it an optional feature?
>
> Loren
>
More information about the sword-devel
mailing list