Fix initial size js

This commit is contained in:
Frank A. Krueger 2018-03-12 22:14:37 -07:00
parent 8ef0a12ab4
commit 980b2880d7
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
1 changed files with 26 additions and 35 deletions

View File

@ -105,40 +105,27 @@ function ooui (rootElementPath) {
console.log("Web socket created"); console.log("Web socket created");
// Throttled window resize event monitorSizeChanges (1000/10);
(function() {
window.addEventListener("resize", resizeThrottler, false);
var resizeTimeout;
function resizeThrottler() {
if (!resizeTimeout) {
resizeTimeout = setTimeout(function() {
resizeTimeout = null;
resizeHandler();
}, 100);
}
}
function resizeHandler() {
const em = {
m: "event",
id: "window",
k: "resize",
v: getSize (),
};
saveSize (em.v);
const ems = JSON.stringify (em);
send (ems);
if (debug) console.log ("Event", em);
}
}());
} }
function oouiWasm (mainAsmName, mainNamspace, mainClassName, mainMethodNmae, assemblies) function oouiWasm (mainAsmName, mainNamspace, mainClassName, mainMethodNmae, assemblies)
{ {
Module.assemblies = assemblies; Module.assemblies = assemblies;
var initialSize = getSize (); monitorSizeChanges (1000/30);
}
function monitorSizeChanges (millis)
{
var resizeTimeout;
function resizeThrottler() {
if (!resizeTimeout) {
resizeTimeout = setTimeout(function() {
resizeTimeout = null;
resizeHandler();
}, millis);
}
}
function resizeHandler() { function resizeHandler() {
const em = { const em = {
@ -147,12 +134,13 @@ function oouiWasm (mainAsmName, mainNamspace, mainClassName, mainMethodNmae, ass
k: "resize", k: "resize",
v: getSize (), v: getSize (),
}; };
saveSize (em.v);
const ems = JSON.stringify (em); const ems = JSON.stringify (em);
send (ems); send (ems);
if (debug) console.log ("Event", em); if (debug) console.log ("Event", em);
} }
window.addEventListener ("resize", resizeHandler, false); window.addEventListener("resize", resizeThrottler, false);
} }
function getNode (id) { function getNode (id) {
@ -330,11 +318,13 @@ function fixupValue (v) {
window["__oouiReceiveMessages"] = function (sessionId, messages) window["__oouiReceiveMessages"] = function (sessionId, messages)
{ {
if (debug) console.log ("WebAssembly Receive", messages); if (debug) console.log ("WebAssembly Receive", messages);
messages.forEach (function (m) { if (wasmSession != null) {
// console.log ('Raw value from server', m.v); messages.forEach (function (m) {
m.v = fixupValue (m.v); // console.log ('Raw value from server', m.v);
processMessage (m); m.v = fixupValue (m.v);
}); processMessage (m);
});
}
}; };
var Module = { var Module = {
@ -433,8 +423,9 @@ var WebAssemblyApp = {
var sessionId = "main"; var sessionId = "main";
var rres = MonoRuntime.call_method (this.main_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]); var rres = MonoRuntime.call_method (this.main_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]);
var res = MonoRuntime.conv_string (rres); var res = MonoRuntime.conv_string (rres);
MonoRuntime.call_method (this.ooui_StartWebAssemblySession_method, null, [MonoRuntime.mono_string (sessionId), MonoRuntime.mono_string ("main")]);
wasmSession = sessionId; wasmSession = sessionId;
var initialSize = getSize ();
MonoRuntime.call_method (this.ooui_StartWebAssemblySession_method, null, [MonoRuntime.mono_string (sessionId), MonoRuntime.mono_string ("main"), MonoRuntime.mono_string (Math.round(initialSize.width) + " " + Math.round(initialSize.height))]);
return res; return res;
} catch (e) { } catch (e) {
return e.msg; return e.msg;