From 558243a3b7b8452e2681ef51ef6315dc2e707b7d Mon Sep 17 00:00:00 2001 From: Dark98 Date: Wed, 2 Dec 2026 00:36:05 +0000 Subject: [PATCH] fix(hd): sync web Client Options 317HD state with Plugin Hub 317 HD config Keeps the webclient's Client Options modal (2006scape_web_options.hd), startup URL/option state, and Plugin Hub's plugin.317_HD.enabled property synchronized in both directions and at runtime. ### Web HD State Synchronization - src/main/java/org/scape2006/web/WebLauncher.java: - Added syncHdStorageState(boolean) on startup when ?hd= or saved web options specify HD so plugin.317_HD.enabled in 2006scape_plugin_settings matches ClientSettings.HD_317 before PluginManager boots. - Registered window.scapeSetHd317 callback forwarding live HD toggles to game.setHD317Enabled(boolean). - src/main/java/org/scape2006/web/DesktopHooks.java: - Added jsSyncWebOptionHdFromPluginConfig(String) in savePluginConfig(String) so toggling 317 HD in Plugin Hub or via ::hd updates 2006scape_web_options.hd in localStorage. - src/main/webapp/index.html: - Updated saveOpts(applyLive) to mirror o.hd into plugin.317_HD.enabled in 2006scape_plugin_settings and invoke window.scapeSetHd317(o.hd) when saving live. --- .../java/org/scape2006/web/DesktopHooks.java | 17 +++++++++ .../java/org/scape2006/web/WebLauncher.java | 37 +++++++++++++++++++ src/main/webapp/index.html | 18 ++++++++- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/scape2006/web/DesktopHooks.java b/src/main/java/org/scape2006/web/DesktopHooks.java index ffc7fb3..74703cb 100644 --- a/src/main/java/org/scape2006/web/DesktopHooks.java +++ b/src/main/java/org/scape2006/web/DesktopHooks.java @@ -573,6 +573,7 @@ public final class DesktopHooks { public static boolean savePluginConfig(String content) { if (content == null) return false; jsSavePluginConfig(content); + jsSyncWebOptionHdFromPluginConfig(content); return true; } @@ -583,6 +584,22 @@ public final class DesktopHooks { "if (window.localStorage) window.localStorage.setItem('2006scape_plugin_settings', content);") private static native void jsSavePluginConfig(String content); + @JSBody(params = {"content"}, script = + "try {\n" + + " if (!window.localStorage || !content) return;\n" + + " var m = content.match(/(?:^|\\r?\\n)plugin\\.317_HD\\.enabled\\s*=\\s*(true|false)/i);\n" + + " if (!m) return;\n" + + " var hdEnabled = m[1].toLowerCase() === 'true';\n" + + " var raw = window.localStorage.getItem('2006scape_web_options');\n" + + " var opts = raw ? JSON.parse(raw) : {};\n" + + " if (!opts || typeof opts !== 'object') opts = {};\n" + + " if (opts.hd !== hdEnabled) {\n" + + " opts.hd = hdEnabled;\n" + + " window.localStorage.setItem('2006scape_web_options', JSON.stringify(opts));\n" + + " }\n" + + "} catch (_) {}") + private static native void jsSyncWebOptionHdFromPluginConfig(String content); + public static void yieldUi() { try { Thread.sleep(1L); diff --git a/src/main/java/org/scape2006/web/WebLauncher.java b/src/main/java/org/scape2006/web/WebLauncher.java index dd94919..df3d6c9 100644 --- a/src/main/java/org/scape2006/web/WebLauncher.java +++ b/src/main/java/org/scape2006/web/WebLauncher.java @@ -50,10 +50,16 @@ public final class WebLauncher { String optHd = getSavedOption("hd"); if ("true".equalsIgnoreCase(hdParam) || "1".equals(hdParam)) { ClientSettings.HD_317 = true; + syncHdStorageState(true); } else if ("false".equalsIgnoreCase(hdParam) || "0".equals(hdParam)) { ClientSettings.HD_317 = false; + syncHdStorageState(false); } else if ("true".equalsIgnoreCase(optHd)) { ClientSettings.HD_317 = true; + syncHdStorageState(true); + } else if ("false".equalsIgnoreCase(optHd)) { + ClientSettings.HD_317 = false; + syncHdStorageState(false); } String resizeParam = DesktopHooks.getParameter("resize"); String optMode = getSavedOption("displayMode"); @@ -107,6 +113,7 @@ public final class WebLauncher { RSApplet.updateLoadingOverlay(100, "Starting 2006Scape..."); setStatusBadge("WS Port " + (overrideWsPort > 0 ? overrideWsPort : (ClientSettings.SERVER_WORLD == 1 ? 44594 : 44596 + ClientSettings.SERVER_WORLD))); Game game = new Game(); + registerHdToggle(enabled -> game.setHD317Enabled(enabled)); Game.server = ClientSettings.SERVER_IP; if ("true".equalsIgnoreCase(getSavedOption("autoLogin"))) { String u = getSavedOption("username"); @@ -147,6 +154,36 @@ public final class WebLauncher { "if (window.scapeInitNavbar) window.scapeInitNavbar(visible, mainMenuUrl, worldMapUrl, manualUrl, rulesUrl);") private static native void initNavbar(boolean visible, String mainMenuUrl, String worldMapUrl, String manualUrl, String rulesUrl); + @JSFunctor + public interface HdToggleCallback extends JSObject { + void onToggle(boolean enabled); + } + + @JSBody(params = {"cb"}, script = "window.scapeSetHd317 = cb;") + private static native void registerHdToggle(HdToggleCallback cb); + + @JSBody(params = {"enabled"}, script = + "try {\n" + + " if (!window.localStorage) return;\n" + + " var rawOpts = window.localStorage.getItem('2006scape_web_options');\n" + + " var opts = rawOpts ? JSON.parse(rawOpts) : {};\n" + + " if (!opts || typeof opts !== 'object') opts = {};\n" + + " opts.hd = !!enabled;\n" + + " window.localStorage.setItem('2006scape_web_options', JSON.stringify(opts));\n" + + " var props = window.localStorage.getItem('2006scape_plugin_settings') || '';\n" + + " var lines = props ? props.split(/\\r?\\n/) : [];\n" + + " var updated = false;\n" + + " for (var i = 0; i < lines.length; i++) {\n" + + " if (lines[i].indexOf('plugin.317_HD.enabled=') === 0) {\n" + + " lines[i] = 'plugin.317_HD.enabled=' + (!!enabled);\n" + + " updated = true;\n" + + " }\n" + + " }\n" + + " if (!updated) lines.push('plugin.317_HD.enabled=' + (!!enabled));\n" + + " window.localStorage.setItem('2006scape_plugin_settings', lines.filter(Boolean).join('\\n') + '\\n');\n" + + "} catch (_) {}") + private static native void syncHdStorageState(boolean enabled); + @JSBody(params = {"key"}, script = "try {\n" + " var raw = window.localStorage ? window.localStorage.getItem('2006scape_web_options') : null;\n" + diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index f2beae8..fe5f35e 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -718,8 +718,24 @@ displayMode: parseInt(document.getElementById('opt-mode').value, 10) || 0, navbar: document.getElementById('opt-navbar').checked }; - try { localStorage.setItem(OPT_KEY, JSON.stringify(o)); } catch (_) {} + try { + localStorage.setItem(OPT_KEY, JSON.stringify(o)); + const props = localStorage.getItem('2006scape_plugin_settings') || ''; + const lines = props ? props.split(/\r?\n/) : []; + let found = false; + for (let i = 0; i < lines.length; i++) { + if (lines[i].startsWith('plugin.317_HD.enabled=')) { + lines[i] = 'plugin.317_HD.enabled=' + o.hd; + found = true; + } + } + if (!found) lines.push('plugin.317_HD.enabled=' + o.hd); + localStorage.setItem('2006scape_plugin_settings', lines.filter(Boolean).join('\n') + '\n'); + } catch (_) {} if (applyLive) { + if (typeof window.scapeSetHd317 === 'function') { + window.scapeSetHd317(o.hd); + } const nav = document.getElementById('rs-navbar'); if (nav) nav.classList.toggle('visible', o.navbar); if (typeof window.scapeDisplayMode === 'number' && window.scapeDisplayMode !== o.displayMode) {