web: Let ImHex Web run more standalone

(cherry picked from commit f76ea2a677)
This commit is contained in:
WerWolv
2025-12-29 17:48:51 +01:00
parent e28f3b75a4
commit 1fd3580f97
2 changed files with 14 additions and 6 deletions

View File

@@ -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

View File

@@ -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