From a42bdce47b53ad02e3aec938e246822562d3bc9f Mon Sep 17 00:00:00 2001 From: CHOMPStation2StaffMirrorBot <94713762+CHOMPStation2StaffMirrorBot@users.noreply.github.com> Date: Thu, 4 Dec 2025 18:18:52 -0700 Subject: [PATCH] [MIRROR] Iframe fix (#12067) Co-authored-by: Selis <12716288+ItsSelis@users.noreply.github.com> --- code/__defines/_compile_options.dm | 2 +- code/controllers/subsystems/tgui.dm | 11 +++++++---- code/modules/admin/verbs/debug.dm | 5 +++++ tgui/packages/common/storage.ts | 24 +++++++++--------------- tgui/public/iframe.html | 5 ++++- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/code/__defines/_compile_options.dm b/code/__defines/_compile_options.dm index d44e8c9a7c..0631d97c63 100644 --- a/code/__defines/_compile_options.dm +++ b/code/__defines/_compile_options.dm @@ -58,4 +58,4 @@ #endif //ifdef REFERENCE_TRACKING // Standard flags to use for browser-options -#define DEFAULT_CLIENT_BROWSER_OPTIONS "byondstorage,find" +#define DEFAULT_CLIENT_BROWSER_OPTIONS "find" diff --git a/code/controllers/subsystems/tgui.dm b/code/controllers/subsystems/tgui.dm index fbf9cd0ba8..91cce577cd 100644 --- a/code/controllers/subsystems/tgui.dm +++ b/code/controllers/subsystems/tgui.dm @@ -15,9 +15,12 @@ SUBSYSTEM_DEF(tgui) wait = 9 flags = SS_NO_INIT priority = FIRE_PRIORITY_TGUI - init_stage = INITSTAGE_EARLY runlevels = RUNLEVEL_LOBBY | RUNLEVELS_DEFAULT + dependencies = list( + /datum/controller/subsystem/assets + ) + /// A list of UIs scheduled to process var/list/current_run = list() /// A list of all open UIs @@ -44,20 +47,20 @@ SUBSYSTEM_DEF(tgui) var/storage_iframe = CONFIG_GET(string/storage_cdn_iframe) if(storage_iframe && storage_iframe != /datum/config_entry/string/storage_cdn_iframe::default) - basehtml = replacetext(basehtml, "\[tgui:storagecdn\]", storage_iframe) + basehtml = replacetextEx(basehtml, "\[tgui:storagecdn]", storage_iframe) return if(CONFIG_GET(string/asset_transport) == "webroot") var/datum/asset_transport/webroot/webroot = SSassets.transport var/datum/asset_cache_item/item = webroot.register_asset("iframe.html", file("tgui/public/iframe.html")) - basehtml = replacetext(basehtml, "\[tgui:storagecdn\]", webroot.get_asset_url("iframe.html", item)) + basehtml = replacetextEx(basehtml, "\[tgui:storagecdn]", webroot.get_asset_url("iframe.html", item)) return if(!storage_iframe) return - basehtml = replacetext(basehtml, "\[tgui:storagecdn\]", storage_iframe) + basehtml = replacetextEx(basehtml, "\[tgui:storagecdn]", storage_iframe) /datum/controller/subsystem/tgui/Shutdown() close_all_uis() diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index e217ab3b82..3112b6aa3e 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -782,3 +782,8 @@ ADMIN_VERB(quick_nif, R_ADMIN, "Quick NIF", "Spawns a NIF into someone in quick- log_and_message_admins("Quick NIF'd [H.real_name] with a [input_NIF].", user) feedback_add_details("admin_verb","QNIF") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! + +ADMIN_VERB(reload_configuration, R_DEBUG, "Reload Configuration", "Reloads the configuration from the default path on the disk, wiping any in-round modifications.", ADMIN_CATEGORY_DEBUG) + if(tgui_alert(user, "Are you absolutely sure you want to reload the configuration from the default path on the disk, wiping any in-round modifications?", "Really reset?", list("No", "Yes")) != "Yes") + return + config.admin_reload() diff --git a/tgui/packages/common/storage.ts b/tgui/packages/common/storage.ts index c842a4c732..f149c6ff54 100644 --- a/tgui/packages/common/storage.ts +++ b/tgui/packages/common/storage.ts @@ -74,11 +74,13 @@ class IFrameIndexedDbBackend implements StorageBackend { async ready(): Promise { const iframe = document.createElement('iframe'); + const iframeStore = `${Byond.storageCdn}?store=${KEY_NAME}`; iframe.style.display = 'none'; - iframe.src = Byond.storageCdn; + this.documentElement = document.body.appendChild(iframe); + iframe.src = iframeStore; const completePromise: Promise = new Promise((resolve) => { - fetch(Byond.storageCdn, { method: 'HEAD' }) + fetch(iframeStore, { method: 'HEAD' }) .then((response) => { if (response.status !== 200) { resolve(false); @@ -95,7 +97,6 @@ class IFrameIndexedDbBackend implements StorageBackend { }); }); - this.documentElement = document.body.appendChild(iframe); if (!this.documentElement.contentWindow) { return new Promise((res) => res(false)); } @@ -114,25 +115,16 @@ class IFrameIndexedDbBackend implements StorageBackend { }); }); - this.iframeWindow.postMessage( - { type: 'get', key: `${KEY_NAME}-${key}` }, - '*', - ); + this.iframeWindow.postMessage({ type: 'get', key: key }, '*'); return promise; } async set(key: string, value: any): Promise { - this.iframeWindow.postMessage( - { type: 'set', key: `${KEY_NAME}-${key}`, value: value }, - '*', - ); + this.iframeWindow.postMessage({ type: 'set', key: key, value: value }, '*'); } async remove(key: string): Promise { - this.iframeWindow.postMessage( - { type: 'remove', key: `${KEY_NAME}-${key}` }, - '*', - ); + this.iframeWindow.postMessage({ type: 'remove', key: key }, '*'); } async clear(): Promise { @@ -156,9 +148,11 @@ class StorageProxy implements StorageBackend { this.backendPromise = (async () => { // If we have not enabled byondstorage yet, we need to check // if we can use the IFrame, or if we need to enable byondstorage + console.log(`testHubStorage ${testHubStorage()}`); if (!testHubStorage()) { // If we have an IFrame URL we can use, and we haven't already enabled // byondstorage, we should use the IFrame backend + console.log(`storageCdn: ${Byond.storageCdn}`); if (Byond.storageCdn) { const iframe = new IFrameIndexedDbBackend(); diff --git a/tgui/public/iframe.html b/tgui/public/iframe.html index c6369f9230..a90d9c65f9 100644 --- a/tgui/public/iframe.html +++ b/tgui/public/iframe.html @@ -14,9 +14,12 @@ const MAX_MESSAGES = 1000; + const urlParams = new URLSearchParams(window.location.search); + const storeValue = `${urlParams.get('store')}-${INDEXED_DB_NAME}`; + const dbPromise = new Promise((resolve, reject) => { const indexedDB = window.indexedDB; - const req = indexedDB.open(INDEXED_DB_NAME, INDEXED_DB_VERSION); + const req = indexedDB.open(storeValue, INDEXED_DB_VERSION); req.onupgradeneeded = (event) => { try { if (event.oldVersion < 1) {