mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-09 07:57:00 +00:00
[MIRROR] Iframe fix (#12067)
Co-authored-by: Selis <12716288+ItsSelis@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
28a8d23bf6
commit
a42bdce47b
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -74,11 +74,13 @@ class IFrameIndexedDbBackend implements StorageBackend {
|
||||
|
||||
async ready(): Promise<boolean | null> {
|
||||
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<boolean> = 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<void> {
|
||||
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<void> {
|
||||
this.iframeWindow.postMessage(
|
||||
{ type: 'remove', key: `${KEY_NAME}-${key}` },
|
||||
'*',
|
||||
);
|
||||
this.iframeWindow.postMessage({ type: 'remove', key: key }, '*');
|
||||
}
|
||||
|
||||
async clear(): Promise<void> {
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user