From 1e16f91e766052ae4cee2908b6c9310e91deac9f Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Thu, 6 Jul 2017 15:39:44 -0700 Subject: [PATCH] Present pages on Mac and Windows Working on #14 --- Ooui/UI.cs | 30 ++++++++++++++++++++++++++++++ Samples/Program.cs | 2 ++ 2 files changed, 32 insertions(+) diff --git a/Ooui/UI.cs b/Ooui/UI.cs index 38e8ec3..744e5c4 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -87,6 +87,36 @@ namespace Ooui Publish (path, () => element); } + public static void Present (string path, object presenter = null) + { + var localHost = host == "*" ? "localhost" : host; + var url = $"http://{localHost}:{port}{path}"; + Console.WriteLine ($"PRESENT {url}"); + + var cmd = url; + var args = ""; + + var osv = Environment.OSVersion; + if (osv.Platform == PlatformID.Unix) { + cmd = "open"; + args = url; + } + + // var vs = Environment.GetEnvironmentVariables (); + // foreach (System.Collections.DictionaryEntry kv in vs) { + // System.Console.WriteLine($"K={kv.Key}, V={kv.Value}"); + // } + + Console.WriteLine ($"EXEC {cmd} {args}"); + try { + System.Diagnostics.Process.Start (cmd, args); + } + catch (Exception ex) { + System.Console.WriteLine("FAILED TO EXEC"); + System.Console.WriteLine(ex); + } + } + static void Start () { if (serverCts != null) return; diff --git a/Samples/Program.cs b/Samples/Program.cs index de79efb..6a6be46 100644 --- a/Samples/Program.cs +++ b/Samples/Program.cs @@ -26,6 +26,8 @@ namespace Samples new ButtonSample ().Publish (); new TodoSample ().Publish (); + UI.Present ("/todo"); + Console.ReadLine (); } }