feat(web): add Pause in Background option, TeaVM reflection filtering, and HUD drawImage guards
Improve webclient stability, background resource usage, and script reflection compatibility across desktop and mobile browsers. ### Web Client Features & Fixes - `index.html` & `RSApplet.java` - Added a **Pause in Background** (`#opt-pause-bg`) option under **Display & Graphics** persisted in `localStorage` (`2006scape_web_options.pauseInBackground`) and synced live via `window.scapePauseInBackground`. - Added `visibilitychange` Web Audio suspend/resume handling in `index.html` and `isPausedInBackground()` loop throttling in `RSApplet.run()` (resetting timing buffers on resume to avoid tick bursts). - `DesktopHooks.java` - Added `naturalWidth > 0` guards to `jsDrawModernMinimap` and `jsDrawModernChat` to prevent `InvalidStateError` on `drawImage` when HUD images are still loading or broken. ### TeaVM Script Reflection - `WebReflectionSupplier.java` - Added `hasUnscriptableParam(...)` to exclude methods referencing `java.util.function.*`, `java.lang.Thread*`, `java.io.*`, or `java.awt.*` from TeaVM reflection metadata.
This commit is contained in:
1 parent
ea04dfe196
commit
e57315b785
4 files changed
+61
-3
No files matched your search
@@ -456,7 +456,7 @@ public final class DesktopHooks {
|
||||
private static native void jsInitHudAssets();
|
||||
|
||||
@JSBody(params = {"canvas", "rgba", "winW", "draw2d"}, script =
|
||||
"var h = window.scapeHud; if (!h || !h.minimapBezel.complete || !h.minimapHole.complete) return null;\n" +
|
||||
"var h = window.scapeHud; if (!h || !h.minimapBezel.complete || h.minimapBezel.naturalWidth <= 0 || !h.minimapHole.complete || h.minimapHole.naturalWidth <= 0) return null;\n" +
|
||||
"var id = h.mContentCtx.createImageData(172, 156); id.data.set(rgba); h.mContentCtx.putImageData(id, 0, 0);\n" +
|
||||
"var g = h.mcCtx; g.clearRect(0, 0, 249, 168);\n" +
|
||||
"g.globalCompositeOperation = 'source-over'; g.drawImage(h.mContent, 34, 4);\n" +
|
||||
@@ -467,7 +467,7 @@ public final class DesktopHooks {
|
||||
private static native HTMLCanvasElement jsDrawModernMinimap(HTMLCanvasElement canvas, Uint8ClampedArray rgba, int winW, boolean draw2d);
|
||||
|
||||
@JSBody(params = {"canvas", "contentRgba", "buttonsRgba", "winH", "draw2d"}, script =
|
||||
"var h = window.scapeHud; if (!h || !h.chatFrame.complete) return null;\n" +
|
||||
"var h = window.scapeHud; if (!h || !h.chatFrame.complete || h.chatFrame.naturalWidth <= 0) return null;\n" +
|
||||
"var g = h.ccCtx; g.clearRect(0, 0, 519, 165);\n" +
|
||||
"g.globalCompositeOperation = 'source-over'; g.drawImage(h.chatFrame, 0, 0);\n" +
|
||||
"if (contentRgba) { var id1 = h.cContentCtx.createImageData(479, 96); id1.data.set(contentRgba); h.cContentCtx.putImageData(id1, 0, 0); g.drawImage(h.cContent, 17, 19); }\n" +
|
||||
|
||||
@@ -594,6 +594,18 @@ public class RSApplet implements Runnable {
|
||||
}
|
||||
|
||||
while (anInt4 >= 0) {
|
||||
if (isPausedInBackground()) {
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException ignored) {}
|
||||
long resetNow = System.currentTimeMillis();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
aLongArray7[i] = resetNow;
|
||||
}
|
||||
count = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (anInt4 > 0) {
|
||||
anInt4--;
|
||||
if (anInt4 == 0) {
|
||||
@@ -844,6 +856,9 @@ public class RSApplet implements Runnable {
|
||||
return DesktopHooks.getParameter(s);
|
||||
}
|
||||
|
||||
@JSBody(script = "return !!(window.scapePauseInBackground && document.hidden);")
|
||||
private static native boolean isPausedInBackground();
|
||||
|
||||
@JSBody(params = {"we"}, script = "return !!(we && we.ctrlKey);")
|
||||
private static native boolean isWheelCtrlKey(WheelEvent we);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.FieldReader;
|
||||
import org.teavm.model.MethodDescriptor;
|
||||
import org.teavm.model.MethodReader;
|
||||
import org.teavm.model.ValueType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -108,6 +109,7 @@ public final class WebReflectionSupplier implements ReflectionSupplier {
|
||||
}
|
||||
List<MethodDescriptor> methods = new ArrayList<>();
|
||||
for (MethodReader m : cls.getMethods()) {
|
||||
if (hasUnscriptableParam(m.getDescriptor())) continue;
|
||||
String name = m.getName();
|
||||
if (isLangSys) {
|
||||
if (!"currentTimeMillis".equals(name) && !"nanoTime".equals(name)) continue;
|
||||
@@ -138,4 +140,22 @@ public final class WebReflectionSupplier implements ReflectionSupplier {
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
|
||||
private static boolean hasUnscriptableParam(MethodDescriptor desc) {
|
||||
ValueType[] params = desc.getParameterTypes();
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
ValueType vt = params[i];
|
||||
while (vt instanceof ValueType.Array) {
|
||||
vt = ((ValueType.Array) vt).getItemType();
|
||||
}
|
||||
if (vt instanceof ValueType.Object) {
|
||||
String clsName = ((ValueType.Object) vt).getClassName();
|
||||
if (clsName.startsWith("java.util.function.") || clsName.startsWith("java.lang.Thread")
|
||||
|| clsName.startsWith("java.io.") || clsName.startsWith("java.awt.")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -408,6 +408,10 @@
|
||||
<span>Show Classic Navbar</span>
|
||||
<input id="opt-navbar" type="checkbox" />
|
||||
</label>
|
||||
<label class="opt-row">
|
||||
<span>Pause in Background</span>
|
||||
<input id="opt-pause-bg" type="checkbox" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="options-footer">
|
||||
@@ -732,6 +736,7 @@
|
||||
document.getElementById('opt-mode').value = String(window.scapeDisplayMode !== undefined ? window.scapeDisplayMode : (o.displayMode || 0));
|
||||
const nav = document.getElementById('rs-navbar');
|
||||
document.getElementById('opt-navbar').checked = (o.navbar !== undefined) ? !!o.navbar : (nav ? nav.classList.contains('visible') : true);
|
||||
document.getElementById('opt-pause-bg').checked = !!o.pauseInBackground;
|
||||
}
|
||||
|
||||
function saveOpts(applyLive) {
|
||||
@@ -743,7 +748,8 @@
|
||||
world: parseInt(document.getElementById('opt-world').value, 10) || 1,
|
||||
hd: document.getElementById('opt-hd').checked,
|
||||
displayMode: parseInt(document.getElementById('opt-mode').value, 10) || 0,
|
||||
navbar: document.getElementById('opt-navbar').checked
|
||||
navbar: document.getElementById('opt-navbar').checked,
|
||||
pauseInBackground: document.getElementById('opt-pause-bg').checked
|
||||
};
|
||||
try {
|
||||
localStorage.setItem(OPT_KEY, JSON.stringify(o));
|
||||
@@ -760,6 +766,7 @@
|
||||
localStorage.setItem('2006scape_plugin_settings', lines.filter(Boolean).join('\n') + '\n');
|
||||
} catch (_) {}
|
||||
if (applyLive) {
|
||||
window.scapePauseInBackground = !!o.pauseInBackground;
|
||||
if (typeof window.scapeSetHd317 === 'function') {
|
||||
window.scapeSetHd317(o.hd);
|
||||
}
|
||||
@@ -786,6 +793,22 @@
|
||||
if (modal) modal.addEventListener('click', (e) => { if (e.target === modal) modal.classList.remove('open'); });
|
||||
if (btnSave) btnSave.addEventListener('click', () => { saveOpts(true); modal.classList.remove('open'); });
|
||||
if (btnSaveReload) btnSaveReload.addEventListener('click', () => { saveOpts(false); window.location.reload(); });
|
||||
|
||||
window.scapePauseInBackground = !!loadOpts().pauseInBackground;
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (!window.scapePauseInBackground) return;
|
||||
const audio = window.scapeWebAudio;
|
||||
if (!audio || !audio.ctx) return;
|
||||
if (document.hidden) {
|
||||
if (audio.ctx.state === 'running') {
|
||||
window.scapePausedAudio = true;
|
||||
audio.ctx.suspend().catch(() => {});
|
||||
}
|
||||
} else if (window.scapePausedAudio) {
|
||||
window.scapePausedAudio = false;
|
||||
audio.ctx.resume().catch(() => {});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
function updateCachedStageSize() {
|
||||
|
||||
Reference in new issue
Block a user