Set window size for self-hosted apps

This commit is contained in:
Frank A. Krueger 2017-12-09 15:34:48 -08:00
parent b0311ec22d
commit c1721e7727
2 changed files with 25 additions and 3 deletions

View File

@ -86,9 +86,10 @@ namespace Ooui.AspNetCore
BadRequest ("Missing `h`"); BadRequest ("Missing `h`");
return; return;
} }
if (!double.TryParse (wValues.Last (), out var w)) var icult = System.Globalization.CultureInfo.InvariantCulture;
if (!double.TryParse (wValues.Last (), System.Globalization.NumberStyles.Any, icult, out var w))
w = 640; w = 640;
if (!double.TryParse (hValues.Last (), out var h)) if (!double.TryParse (hValues.Last (), System.Globalization.NumberStyles.Any, icult, out var h))
h = 480; h = 480;
// //

View File

@ -432,11 +432,32 @@ namespace Ooui
return; return;
} }
//
// Set the element's dimensions
//
var query =
(from part in listenerContext.Request.Url.Query.Split (new[] { '?', '&' })
where part.Length > 0
let kvs = part.Split ('=')
where kvs.Length == 2
select kvs).ToDictionary (x => Uri.UnescapeDataString (x[0]), x => Uri.UnescapeDataString (x[1]));
if (!query.TryGetValue ("w", out var wValue) || string.IsNullOrEmpty (wValue)) {
wValue = "640";
}
if (!query.TryGetValue ("h", out var hValue) || string.IsNullOrEmpty (hValue)) {
hValue = "480";
}
var icult = System.Globalization.CultureInfo.InvariantCulture;
if (!double.TryParse (wValue, System.Globalization.NumberStyles.Any, icult, out var w))
w = 640;
if (!double.TryParse (hValue, System.Globalization.NumberStyles.Any, icult, out var h))
h = 480;
// //
// Create a new session and let it handle everything from here // Create a new session and let it handle everything from here
// //
try { try {
var session = new Session (webSocket, element, 1024, 768, serverToken); var session = new Session (webSocket, element, w, h, serverToken);
await session.RunAsync ().ConfigureAwait (false); await session.RunAsync ().ConfigureAwait (false);
} }
catch (WebSocketException ex) when (ex.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely) { catch (WebSocketException ex) when (ex.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely) {