Added logic to launch Browser from Windows
This commit is contained in:
parent
de9102f38a
commit
b8e71c9c66
|
@ -24,7 +24,8 @@ namespace Ooui
|
|||
x => x.GetName().Name);
|
||||
|
||||
asms.TryGetValue("Xamarin.iOS", out iosAssembly);
|
||||
if (iosAssembly != null) {
|
||||
if (iosAssembly != null)
|
||||
{
|
||||
iosUIViewControllerType = iosAssembly.GetType("UIKit.UIViewController");
|
||||
iosUIApplicationType = iosAssembly.GetType("UIKit.UIApplication");
|
||||
iosUIWebViewType = iosAssembly.GetType("UIKit.UIWebView");
|
||||
|
@ -33,7 +34,8 @@ namespace Ooui
|
|||
}
|
||||
|
||||
asms.TryGetValue("Mono.Android", out androidAssembly);
|
||||
if (androidAssembly != null) {
|
||||
if (androidAssembly != null)
|
||||
{
|
||||
androidActivityType = androidAssembly.GetType("Android.App.Activity");
|
||||
androidWebViewType = androidAssembly.GetType("Android.Webkit.WebView");
|
||||
}
|
||||
|
@ -41,13 +43,16 @@ namespace Ooui
|
|||
|
||||
public static void OpenBrowser(string url, object presenter)
|
||||
{
|
||||
if (iosAssembly != null) {
|
||||
if (iosAssembly != null)
|
||||
{
|
||||
OpenBrowserOniOS(url, presenter);
|
||||
}
|
||||
else if (androidAssembly != null) {
|
||||
else if (androidAssembly != null)
|
||||
{
|
||||
OpenBrowserOnAndroid(url, presenter);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
StartBrowserProcess(url);
|
||||
}
|
||||
}
|
||||
|
@ -57,11 +62,13 @@ namespace Ooui
|
|||
var presenterType = GetObjectType(presenter);
|
||||
|
||||
object presenterWebView = null;
|
||||
if (presenter != null && androidWebViewType.IsAssignableFrom (presenterType)) {
|
||||
if (presenter != null && androidWebViewType.IsAssignableFrom(presenterType))
|
||||
{
|
||||
presenterWebView = presenter;
|
||||
}
|
||||
|
||||
if (presenterWebView == null) {
|
||||
if (presenterWebView == null)
|
||||
{
|
||||
throw new ArgumentException("Presenter must be a WebView", nameof(presenter));
|
||||
}
|
||||
|
||||
|
@ -80,23 +87,28 @@ namespace Ooui
|
|||
// 3. Create a window?
|
||||
//
|
||||
object presenterViewController = null;
|
||||
if (presenter != null && iosUIViewControllerType.IsAssignableFrom (presenterType)) {
|
||||
if (presenter != null && iosUIViewControllerType.IsAssignableFrom(presenterType))
|
||||
{
|
||||
presenterViewController = presenter;
|
||||
}
|
||||
|
||||
if (presenterViewController == null) {
|
||||
if (presenterViewController == null)
|
||||
{
|
||||
var app = iosUIApplicationType.GetProperty("SharedApplication").GetValue(null, null);
|
||||
var window = iosUIApplicationType.GetProperty("KeyWindow").GetValue(app, null);
|
||||
if (window != null) {
|
||||
if (window != null)
|
||||
{
|
||||
var rvc = window.GetType().GetProperty("RootViewController").GetValue(window, null);
|
||||
if (rvc != null) {
|
||||
if (rvc != null)
|
||||
{
|
||||
var pvc = rvc.GetType().GetProperty("PresentedViewController").GetValue(rvc, null);
|
||||
presenterViewController = pvc ?? rvc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (presenterViewController == null) {
|
||||
if (presenterViewController == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot find a view controller from which to present");
|
||||
}
|
||||
|
||||
|
@ -121,10 +133,12 @@ namespace Ooui
|
|||
static Type GetObjectType(object o)
|
||||
{
|
||||
var t = typeof(object);
|
||||
if (o is IReflectableType rt) {
|
||||
if (o is IReflectableType rt)
|
||||
{
|
||||
t = rt.GetTypeInfo().AsType();
|
||||
}
|
||||
else if (o != null) {
|
||||
else if (o != null)
|
||||
{
|
||||
t = o.GetType();
|
||||
}
|
||||
return t;
|
||||
|
@ -133,21 +147,34 @@ namespace Ooui
|
|||
static Process StartBrowserProcess(string url)
|
||||
{
|
||||
var cmd = url;
|
||||
var args = "";
|
||||
var args = string.Empty;
|
||||
|
||||
var osv = Environment.OSVersion;
|
||||
if (osv.Platform == PlatformID.Unix) {
|
||||
|
||||
if (osv.Platform == PlatformID.Unix)
|
||||
{
|
||||
cmd = "open";
|
||||
args = url;
|
||||
}
|
||||
|
||||
var platform = (int)Environment.OSVersion.Platform;
|
||||
var isWindows = ((platform != 4) && (platform != 6) && (platform != 128));
|
||||
|
||||
if (isWindows)
|
||||
{
|
||||
cmd = "explorer.exe";
|
||||
args = url;
|
||||
}
|
||||
|
||||
// var vs = Environment.GetEnvironmentVariables ();
|
||||
// foreach (System.Collections.DictionaryEntry kv in vs) {
|
||||
// System.Console.WriteLine($"K={kv.Key}, V={kv.Value}");
|
||||
// }
|
||||
|
||||
// Console.WriteLine ($"Process.Start {cmd} {args}");
|
||||
|
||||
return Process.Start(cmd, args);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue