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.
This commit is contained in:
1 parent
6737a936df
commit
558243a3b7
3 files changed
+71
-1
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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" +
|
||||
|
||||
Reference in new issue
Block a user