web: Let ImHex Web run more standalone

This commit is contained in:
WerWolv
2025-12-29 17:48:51 +01:00
parent 7a8c57a9a0
commit f76ea2a677
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); const mibTotal = (wasmSize / 1024**2).toFixed(1);
let root = document.querySelector(':root'); let root = document.querySelector(':root');
root.style.setProperty("--progress", `${percent}%`) if (root != null) {
document.getElementById("progress-bar-content").innerHTML = `${percent}%  [${mibNow} MiB / ${mibTotal} MiB]`; 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) { function glfwSetCursorCustom(wnd, shape) {
@@ -174,7 +180,9 @@ var Module = {
}, },
onRuntimeInitialized: function() { onRuntimeInitialized: function() {
// Triggered when the wasm module is loaded and ready to use. // 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" document.getElementById("canvas").style.display = "initial"
clearTimeout(notWorkingTimer); clearTimeout(notWorkingTimer);
@@ -263,8 +271,8 @@ function js_resizeCanvas() {
canvas.top = document.documentElement.clientTop; canvas.top = document.documentElement.clientTop;
canvas.left = document.documentElement.clientLeft; canvas.left = document.documentElement.clientLeft;
canvas.width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0); canvas.width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0) * window.devicePixelRatio;
canvas.height = Math.min(document.documentElement.clientHeight, window.innerHeight || 0); canvas.height = Math.min(document.documentElement.clientHeight, window.innerHeight || 0) * window.devicePixelRatio;
} }
// Prevent some default browser shortcuts from preventing ImHex ones to work // Prevent some default browser shortcuts from preventing ImHex ones to work

View File

@@ -677,7 +677,7 @@ namespace hex {
return std::midpoint(xScale, yScale); return std::midpoint(xScale, yScale);
} }
#elif defined(OS_WEB) #elif defined(OS_WEB)
return 1.0F; return MAIN_THREAD_EM_ASM_INT({ return window.devicePixelRatio; });
#else #else
return 1.0F; return 1.0F;
#endif #endif