Store window height in cookies so initial html is the right size
This commit is contained in:
parent
4148ea17be
commit
28c8fac046
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Ooui.AspNetCore
|
||||
|
@ -21,9 +22,14 @@ namespace Ooui.AspNetCore
|
|||
var response = context.HttpContext.Response;
|
||||
response.StatusCode = 200;
|
||||
response.ContentType = "text/html; charset=utf-8";
|
||||
|
||||
if (element.WantsFullScreen) {
|
||||
element.Style.Width = GetCookieDouble (context.HttpContext.Request.Cookies, "oouiWindowWidth", 32, 640, 10000);
|
||||
element.Style.Height = GetCookieDouble (context.HttpContext.Request.Cookies, "oouiWindowHeight", 24, 480, 10000);
|
||||
}
|
||||
|
||||
var sessionId = WebSocketHandler.BeginSession (context.HttpContext, element);
|
||||
var initialHtml = element.OuterHtml;
|
||||
Console.WriteLine(initialHtml);
|
||||
var html = UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId, title: title, initialHtml: initialHtml);
|
||||
var htmlBytes = Encoding.UTF8.GetBytes (html);
|
||||
response.ContentLength = htmlBytes.Length;
|
||||
|
@ -31,5 +37,20 @@ namespace Ooui.AspNetCore
|
|||
await s.WriteAsync (htmlBytes, 0, htmlBytes.Length).ConfigureAwait (false);
|
||||
}
|
||||
}
|
||||
|
||||
static double GetCookieDouble (IRequestCookieCollection cookies, string key, double min, double def, double max)
|
||||
{
|
||||
if (cookies.TryGetValue (key, out var s)) {
|
||||
if (double.TryParse (s, out var d)) {
|
||||
if (d < min) return min;
|
||||
if (d > max) return max;
|
||||
return d;
|
||||
}
|
||||
return def;
|
||||
}
|
||||
else {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,12 +35,29 @@ function getSize () {
|
|||
};
|
||||
}
|
||||
|
||||
function setCookie (name, value, days) {
|
||||
var expires = "";
|
||||
if (days) {
|
||||
var date = new Date ();
|
||||
date.setTime(date.getTime () + (days*24*60*60*1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
}
|
||||
|
||||
function saveSize (s) {
|
||||
setCookie ("oouiWindowWidth", s.width, 7);
|
||||
setCookie ("oouiWindowHeight", s.height, 7);
|
||||
}
|
||||
|
||||
// Main entrypoint
|
||||
function ooui (rootElementPath) {
|
||||
|
||||
var initialSize = getSize ();
|
||||
saveSize (initialSize);
|
||||
|
||||
return;
|
||||
|
||||
var initialSize = getSize ();
|
||||
var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") +
|
||||
"w=" + initialSize.width + "&h=" + initialSize.height;
|
||||
|
||||
|
|
Loading…
Reference in New Issue