From 1fd3580f97a3087ca0e457bec2371a784b0f444d Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 29 Dec 2025 17:48:51 +0100 Subject: [PATCH] web: Let ImHex Web run more standalone (cherry picked from commit f76ea2a677a76829440152c8851b8279b48a4c24) --- dist/web/source/wasm-config.js | 18 +++++++++++++----- lib/libimhex/source/api/imhex_api.cpp | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dist/web/source/wasm-config.js b/dist/web/source/wasm-config.js index b16a5fe29..e78805b86 100644 --- a/dist/web/source/wasm-config.js +++ b/dist/web/source/wasm-config.js @@ -59,8 +59,14 @@ monkeyPatch((file, done) => { const mibTotal = (wasmSize / 1024**2).toFixed(1); let root = document.querySelector(':root'); - root.style.setProperty("--progress", `${percent}%`) - document.getElementById("progress-bar-content").innerHTML = `${percent}%  [${mibNow} MiB / ${mibTotal} MiB]`; + if (root != null) { + root.style.setProperty("--progress", `${percent}%`) + let progressBar = document.getElementById("progress-bar-content"); + + if (progressBar != null) { + progressBar.innerHTML = `${percent}%  [${mibNow} MiB / ${mibTotal} MiB]`; + } + } }); function glfwSetCursorCustom(wnd, shape) { @@ -174,7 +180,9 @@ var Module = { }, onRuntimeInitialized: function() { // Triggered when the wasm module is loaded and ready to use. - document.getElementById("loading").style.display = "none" + let loading = document.getElementById("loading"); + if (loading != null) + document.getElementById("loading").style.display = "none" document.getElementById("canvas").style.display = "initial" clearTimeout(notWorkingTimer); @@ -263,8 +271,8 @@ function js_resizeCanvas() { canvas.top = document.documentElement.clientTop; canvas.left = document.documentElement.clientLeft; - canvas.width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0); - canvas.height = Math.min(document.documentElement.clientHeight, window.innerHeight || 0); + canvas.width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0) * window.devicePixelRatio; + canvas.height = Math.min(document.documentElement.clientHeight, window.innerHeight || 0) * window.devicePixelRatio; } // Prevent some default browser shortcuts from preventing ImHex ones to work diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index d303a61ec..7bdbca409 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -681,7 +681,7 @@ namespace hex { return std::midpoint(xScale, yScale); } #elif defined(OS_WEB) - return 1.0F; + return MAIN_THREAD_EM_ASM_INT({ return window.devicePixelRatio; }); #else return 1.0F; #endif