mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 05:00:55 +01:00
Prefetch state
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
var/list/initial_data
|
||||
/// The static data used to initialize the UI.
|
||||
var/list/initial_static_data
|
||||
/// Holder for the json string, that is sent during the initial update
|
||||
var/_initial_update
|
||||
/// The status/visibility of the UI.
|
||||
var/status = UI_INTERACTIVE
|
||||
/// Topic state used to determine status/interactability.
|
||||
@@ -118,7 +120,7 @@
|
||||
// Replace template tokens with important UI data
|
||||
// NOTE: Intentional \ref usage; tgui datums can't/shouldn't
|
||||
// be tagged, so this is an effective unwrap
|
||||
html = replacetextEx(html, "\[ref]", "\ref[src]")
|
||||
html = replacetextEx(html, "\[tgui:ref]", "\ref[src]")
|
||||
|
||||
// Open the window.
|
||||
user << browse(html, "window=[window_id];can_minimize=0;auto_format=0;[window_size][have_title_bar]")
|
||||
@@ -128,10 +130,17 @@
|
||||
// be tagged, so this is an effective unwrap
|
||||
winset(user, window_id, "on-close=\"uiclose \ref[src]\"")
|
||||
|
||||
if(!initial_data)
|
||||
// Pre-fetch initial state while browser is still loading in
|
||||
// another thread
|
||||
if(!initial_data) {
|
||||
initial_data = src_object.ui_data(user)
|
||||
if(!initial_static_data)
|
||||
}
|
||||
if(!initial_static_data) {
|
||||
initial_static_data = src_object.ui_static_data(user)
|
||||
}
|
||||
_initial_update = url_encode(get_json(
|
||||
initial_data,
|
||||
initial_static_data))
|
||||
|
||||
SStgui.on_open(src)
|
||||
|
||||
@@ -232,9 +241,7 @@
|
||||
|
||||
switch(action)
|
||||
if("tgui:initialize")
|
||||
user << output(
|
||||
url_encode(get_json(initial_data, initial_static_data)),
|
||||
"[window_id].browser:initialize")
|
||||
user << output(_initial_update, "[window_id].browser:update")
|
||||
initialized = TRUE
|
||||
if("tgui:view")
|
||||
if(params["screen"])
|
||||
|
||||
@@ -115,16 +115,12 @@ const setupApp = () => {
|
||||
});
|
||||
|
||||
// Subscribe for bankend updates
|
||||
window.update = window.initialize = stateJson => {
|
||||
window.update = stateJson => {
|
||||
// NOTE: stateJson can be an object only if called manually from console.
|
||||
// This is useful for debugging tgui in proper browsers, like Chrome.
|
||||
const state = typeof stateJson === 'string'
|
||||
? parseStateJson(stateJson)
|
||||
: stateJson;
|
||||
// Set window ref if it was not defined inline on the page
|
||||
if (!window.__ref__) {
|
||||
window.__ref__ = state?.config?.ref;
|
||||
}
|
||||
// Backend update dispatches a store action
|
||||
store.dispatch(backendUpdate(state));
|
||||
};
|
||||
|
||||
@@ -3,18 +3,20 @@
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta charset="utf-8">
|
||||
<meta id="tgui:ref" content="[ref]">
|
||||
|
||||
<!-- Inlined data -->
|
||||
<meta id="tgui:ref" content="[tgui:ref]">
|
||||
|
||||
<!-- Early setup -->
|
||||
<script type="text/javascript">
|
||||
// Mark the beginning of initialization
|
||||
window.__inception__ = new Date().getTime();
|
||||
// Make window ref global
|
||||
// Read tgui object ref into a global
|
||||
window.__ref__ = document
|
||||
.getElementById('tgui:ref')
|
||||
.getAttribute('content');
|
||||
// Null the ref if it wasn't replaced by the BYOND
|
||||
if (window.__ref__.indexOf('ref') >= 0) {
|
||||
// Null if template marker was not replaced
|
||||
if (window.__ref__ === '[' + 'tgui:ref' + ']') {
|
||||
window.__ref__ = null;
|
||||
}
|
||||
// Global error handling
|
||||
@@ -48,13 +50,13 @@ window.onerror = function (msg, url, line, col, error) {
|
||||
+ '&log=' + encodeURIComponent(stack);
|
||||
// Short-circuit further updates
|
||||
window.__updateQueue__ = [];
|
||||
window.update = window.initialize = function () {};
|
||||
window.update = function () {};
|
||||
// Prevent default action
|
||||
return true;
|
||||
};
|
||||
// Early initialization
|
||||
window.__updateQueue__ = [];
|
||||
window.update = window.initialize = function (stateJson) {
|
||||
window.update = function (stateJson) {
|
||||
window.__updateQueue__.push(stateJson);
|
||||
};
|
||||
location.href = 'byond://?src=' + window.__ref__
|
||||
|
||||
Reference in New Issue
Block a user