diff --git a/Example/Example.csproj b/Example/Example.csproj index b3c5cd6..b2841e6 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -1,16 +1,16 @@ - - + + - - + + Exe - net7.0 + net8.0 enable enable diff --git a/Example/Program.cs b/Example/Program.cs index d005c66..18adf1d 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -9,5 +9,17 @@ btn.Click += (sender,e)=>{ btn.Text = $"Clicked {++i} time(s)"; }; ui.Publish("/",btn); - +ui.Publish("/query",(ctx)=>{ + Ooui.List list=new List(); + foreach(var item in ctx.QueryParams) + { + foreach(var v in item.Value) + { + Ooui.ListItem listItem=new ListItem(); + listItem.Text = $"{item.Key}: {v}"; + list.AppendChild(listItem); + } + } + return list; +}); ui.StartServer(45252); \ No newline at end of file diff --git a/Ooui/Client.js b/Ooui/Client.js index 1045e5e..d614aea 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -125,7 +125,7 @@ function connectWebSocket() { saveSize (initialSize); var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") + - "w=" + initialSize.width + "&h=" + initialSize.height; + "w=" + initialSize.width + "&h=" + initialSize.height + window.location.search.replace('?','&'); var proto = "ws"; if (location.protocol == "https:") { diff --git a/Ooui/UI.cs b/Ooui/UI.cs index 3071a18..56039a2 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -489,6 +489,7 @@ namespace Ooui bool disposeElementWhenDone = true; try { var context = UIContext.ForListenerContext (listenerContext, variables); + context.QueryParams = listenerContext.QueryParams; element = elementHandler.GetElement (context); disposeElementWhenDone = elementHandler.DisposeElementWhenDone; @@ -609,6 +610,7 @@ namespace Ooui public class UIContext { + public Dictionary> QueryParams {get;set;}=new Dictionary>(); readonly Dictionary variables = new Dictionary (); public string RequestUrl { get; }