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:
Dark98 committed 2026-12-02 17:20:27 +00:00
1 parent ea04dfe196
commit e57315b785
4 files changed
+61 -3

No files matched your search

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