Implements byondStorage for 516 browsers (#25363)

* Add 516 storage that doesnt break 515

* tgui rebuild

* TGUI Bundle Rebuild

* TGUI Bundle Rebuild

---------

Co-authored-by: paradisess13[bot] <165046124+paradisess13[bot]@users.noreply.github.com>
This commit is contained in:
S34N
2024-05-22 21:26:47 +02:00
committed by GitHub
parent 38fb21c467
commit 269be6bc97
6 changed files with 225 additions and 246 deletions
+1 -1
View File
@@ -928,7 +928,7 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention)
return
to_chat(src, "<span class='info'>You can now right click to use inspect on browsers.</span>")
winset(src, "", "browser-options=find,devtools")
winset(src, "", "browser-options=byondstorage,find,devtools")
/client/proc/visualise_active_turfs()
set category = "Debug"
+4
View File
@@ -257,6 +257,10 @@
//CONNECT//
///////////
/client/New(TopicData)
// TODO: Remove with 516
if(byond_version >= 516) // Enable 516 compat browser storage mechanisms
winset(src, "", "browser-options=byondstorage")
var/tdata = TopicData //save this for later use
// Instantiate stat panel
stat_panel = new(src, "statbrowser")
+24 -49
View File
@@ -6,9 +6,8 @@
* @license MIT
*/
export const IMPL_MEMORY = 0;
export const IMPL_LOCAL_STORAGE = 1;
export const IMPL_INDEXED_DB = 2;
export const IMPL_HUB_STORAGE = 0;
export const IMPL_INDEXED_DB = 1;
const INDEXED_DB_VERSION = 1;
const INDEXED_DB_NAME = 'para-tgui';
@@ -25,69 +24,44 @@ const testGeneric = (testFn) => () => {
}
};
// Localstorage can sometimes throw an error, even if DOM storage is not
// disabled in IE11 settings.
// See: https://superuser.com/questions/1080011
// prettier-ignore
const testLocalStorage = testGeneric(() => (
window.localStorage && window.localStorage.getItem
));
const testHubStorage = testGeneric(
() => window.hubStorage && window.hubStorage.getItem
);
// TODO: Remove with 516
// prettier-ignore
const testIndexedDb = testGeneric(() => (
(window.indexedDB || window.msIndexedDB)
&& (window.IDBTransaction || window.msIDBTransaction)
));
class MemoryBackend {
class HubStorageBackend {
constructor() {
this.impl = IMPL_MEMORY;
this.store = {};
this.impl = IMPL_HUB_STORAGE;
}
get(key) {
return this.store[key];
}
set(key, value) {
this.store[key] = value;
}
remove(key) {
this.store[key] = undefined;
}
clear() {
this.store = {};
}
}
class LocalStorageBackend {
constructor() {
this.impl = IMPL_LOCAL_STORAGE;
}
get(key) {
const value = localStorage.getItem(key);
const value = window.hubStorage.getItem('paradise-' + key);
if (typeof value === 'string') {
return JSON.parse(value);
}
}
set(key, value) {
localStorage.setItem(key, JSON.stringify(value));
window.hubStorage.setItem('paradise-' + key, JSON.stringify(value));
}
remove(key) {
localStorage.removeItem(key);
window.hubStorage.removeItem('paradise-' + key);
}
clear() {
localStorage.clear();
window.hubStorage.clear();
}
}
class IndexedDbBackend {
// TODO: Remove with 516
constructor() {
this.impl = IMPL_INDEXED_DB;
/** @type {Promise<IDBDatabase>} */
@@ -157,17 +131,18 @@ class IndexedDbBackend {
class StorageProxy {
constructor() {
this.backendPromise = (async () => {
if (testIndexedDb()) {
try {
const backend = new IndexedDbBackend();
await backend.dbPromise;
return backend;
} catch {}
if (Byond.TRIDENT) {
// fuckin IE users, TODO: Remove with 516
if (testIndexedDb()) {
try {
const backend = new IndexedDbBackend();
await backend.dbPromise;
return backend;
} catch {}
}
} else if (testHubStorage()) {
return new HubStorageBackend();
}
if (testLocalStorage()) {
return new LocalStorageBackend();
}
return new MemoryBackend();
})();
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long