From c1721e7727bd4ec64b764e1ecba2af4b107bbca3 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sat, 9 Dec 2017 15:34:48 -0800 Subject: [PATCH] Set window size for self-hosted apps --- Ooui.AspNetCore/WebSocketHandler.cs | 5 +++-- Ooui/UI.cs | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Ooui.AspNetCore/WebSocketHandler.cs b/Ooui.AspNetCore/WebSocketHandler.cs index ce6f417..a483e01 100644 --- a/Ooui.AspNetCore/WebSocketHandler.cs +++ b/Ooui.AspNetCore/WebSocketHandler.cs @@ -86,9 +86,10 @@ namespace Ooui.AspNetCore BadRequest ("Missing `h`"); 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; - if (!double.TryParse (hValues.Last (), out var h)) + if (!double.TryParse (hValues.Last (), System.Globalization.NumberStyles.Any, icult, out var h)) h = 480; // diff --git a/Ooui/UI.cs b/Ooui/UI.cs index b3a3ac9..6b2faee 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -432,11 +432,32 @@ namespace Ooui 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 // try { - var session = new Session (webSocket, element, 1024, 768, serverToken); + var session = new Session (webSocket, element, w, h, serverToken); await session.RunAsync ().ConfigureAwait (false); } catch (WebSocketException ex) when (ex.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely) {