feat(web): proper viewport scaling, instant load, and file downloads

Make the Emscripten build behave like the desktop app for loading, window
scaling, and exporting. All changes are #ifdef __EMSCRIPTEN__-gated or no-op on
desktop, so native behavior is unchanged.

Scaling:
- Drop FLAG_WINDOW_HIGHDPI on web. The emscripten-GLFW shim forces a fixed
  pixel canvas style (!important) when HiDPI-aware, overriding the shell's
  100vw/100vh CSS so the canvas can't fill the page; raylib's own resize/window
  callbacks also disagree about dividing by devicePixelRatio, desyncing the
  framebuffer from the reported screen size.
- Sync raylib's window size to window.innerWidth/innerHeight each frame via
  SetWindowSize (guarded against no-op churn). This keeps screen size, GL
  viewport, and projection consistent, so the UI fills the viewport and reflows
  on resize like the desktop window.

Loading:
- Compute the full-resolution STFT synchronously when a file loads instead of
  the desktop overview-then-deferred-high-res path, which relied on many
  main-loop iterations yielding to the browser and appeared to stall partway.
- Allow the wasm heap to grow (INITIAL_MEMORY + ALLOW_MEMORY_GROWTH) so longer
  recordings fit now that everything is computed up front.

Exports:
- Add Platform_OfferFileToUser(): no-op on desktop (file is already on disk);
  on web it reads the just-written file from MEMFS and triggers a browser
  download, then unlinks the temp copy. Wired into PNG and WAV export, which
  now show just the filename in the status message.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 11:48:47 -07:00
parent 6347eb172e
commit cef7619833
8 changed files with 118 additions and 6 deletions
+30 -1
View File
@@ -10,7 +10,8 @@
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <errno.h> /* ENOSYS */
#include <errno.h> /* ENOSYS */
#include <emscripten.h> /* EM_ASM */
/* ── Helpers ─────────────────────────────────────────────────────────── */
@@ -64,3 +65,31 @@ const char *Platform_GetTempDir(void) {
*/
return "/";
}
void Platform_OfferFileToUser(const char *path) {
if (!path) return;
/*
* The file was just written into the in-memory (MEMFS) filesystem, which
* the user can't see. Read it back and hand it to the browser as a
* download, then unlink the temporary copy so we don't leak heap memory.
*/
EM_ASM({
var p = UTF8ToString($0);
try {
var data = FS.readFile(p); // Uint8Array
var name = p.split('/').pop() || 'download';
var blob = new Blob([data], { type: 'application/octet-stream' });
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(function() { URL.revokeObjectURL(url); }, 1000);
try { FS.unlink(p); } catch (e) {}
} catch (e) {
console.error('rspektrum: download failed for ' + p + ': ' + e);
}
}, path);
}