From 8be19451456d961049393ac3a1120eb42799e200 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 14 Oct 2020 20:50:16 +0200 Subject: [PATCH] Core - Added utility for opening URLs in the default browser --- src/Artemis.Core/Constants.cs | 2 +- .../Utilities/CurrentProcessUtilities.cs | 19 +++++++++++++++++-- src/Artemis.UI/Screens/Home/HomeViewModel.cs | 11 ++--------- .../Tabs/Plugins/PluginSettingsViewModel.cs | 4 ++-- src/Artemis.UI/Screens/TrayViewModel.cs | 2 +- .../ColorMatrixConfigurationViewModel.cs | 10 ++++------ .../Views/ColorMatrixConfigurationView.xaml | 2 +- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/Artemis.Core/Constants.cs b/src/Artemis.Core/Constants.cs index 267ec0b76..5de642452 100644 --- a/src/Artemis.Core/Constants.cs +++ b/src/Artemis.Core/Constants.cs @@ -17,7 +17,7 @@ namespace Artemis.Core /// /// The full path to the Artemis executable /// - public static readonly string ExecutablePath = ApplicationUtilities.GetCurrentLocation(); + public static readonly string ExecutablePath = Utilities.GetCurrentLocation(); /// /// The full path to the Artemis data folder diff --git a/src/Artemis.Core/Utilities/CurrentProcessUtilities.cs b/src/Artemis.Core/Utilities/CurrentProcessUtilities.cs index 9e49da20c..2df30677b 100644 --- a/src/Artemis.Core/Utilities/CurrentProcessUtilities.cs +++ b/src/Artemis.Core/Utilities/CurrentProcessUtilities.cs @@ -5,9 +5,9 @@ using Stylet; namespace Artemis.Core { /// - /// Provides utilities to manage the application + /// Provides a few general utilities for ease of use /// - public static class ApplicationUtilities + public static class Utilities { /// /// Attempts to gracefully shut down the application with a delayed kill to ensure the application shut down @@ -39,6 +39,21 @@ namespace Artemis.Core Execute.OnUIThread(() => Application.Current.Shutdown()); } + /// + /// Opens the provided URL in the default web browser + /// + /// The URL to open + /// The process created to open the URL + public static Process OpenUrl(string url) + { + ProcessStartInfo processInfo = new ProcessStartInfo + { + FileName = url, + UseShellExecute = true + }; + return Process.Start(processInfo); + } + /// /// Gets the current application location /// diff --git a/src/Artemis.UI/Screens/Home/HomeViewModel.cs b/src/Artemis.UI/Screens/Home/HomeViewModel.cs index 409be9527..d84c275a9 100644 --- a/src/Artemis.UI/Screens/Home/HomeViewModel.cs +++ b/src/Artemis.UI/Screens/Home/HomeViewModel.cs @@ -1,6 +1,4 @@ -using System; -using System.Diagnostics; -using Stylet; +using Stylet; namespace Artemis.UI.Screens.Home { @@ -13,12 +11,7 @@ namespace Artemis.UI.Screens.Home public void OpenUrl(string url) { - // Don't open anything but valid URIs - if (Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute)) - { - url = url.Replace("&", "^&"); - Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") {CreateNoWindow = true}); - } + Core.Utilities.OpenUrl(url); } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs index 96ca0a119..4887fdbc0 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs @@ -131,7 +131,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins // Give the logger a chance to write, might not always be enough but oh well await Task.Delay(500); - ApplicationUtilities.Shutdown(2, true); + Core.Utilities.Shutdown(2, true); } private PackIconKind GetIconKind() @@ -227,7 +227,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins // Give the logger a chance to write, might not always be enough but oh well await Task.Delay(500); - ApplicationUtilities.Shutdown(2, true); + Core.Utilities.Shutdown(2, true); } NotifyOfPropertyChange(nameof(IsEnabled)); diff --git a/src/Artemis.UI/Screens/TrayViewModel.cs b/src/Artemis.UI/Screens/TrayViewModel.cs index ce3fa134e..76b792bc4 100644 --- a/src/Artemis.UI/Screens/TrayViewModel.cs +++ b/src/Artemis.UI/Screens/TrayViewModel.cs @@ -68,7 +68,7 @@ namespace Artemis.UI.Screens public void TrayExit() { - ApplicationUtilities.Shutdown(2, false); + Core.Utilities.Shutdown(2, false); } public void TrayOpenDebugger() diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ViewModels/ColorMatrixConfigurationViewModel.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ViewModels/ColorMatrixConfigurationViewModel.cs index e6c54bb1b..f2aac83a9 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ViewModels/ColorMatrixConfigurationViewModel.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ViewModels/ColorMatrixConfigurationViewModel.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System.Windows.Navigation; +using Artemis.Core; using Artemis.Core.LayerEffects; namespace Artemis.Plugins.LayerEffects.Filter.ViewModels @@ -12,12 +13,9 @@ namespace Artemis.Plugins.LayerEffects.Filter.ViewModels public ColorMatrixEffectProperties Properties { get; set; } - public void OpenGuide() + public void OpenHyperlink(object sender, RequestNavigateEventArgs e) { - Process.Start(new ProcessStartInfo("cmd", "/c start https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/effects/color-filters") - { - CreateNoWindow = true - }); + Utilities.OpenUrl(e.Uri.AbsoluteUri); } } } \ No newline at end of file diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/Views/ColorMatrixConfigurationView.xaml b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/Views/ColorMatrixConfigurationView.xaml index 96b85b457..91a30736d 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/Views/ColorMatrixConfigurationView.xaml +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/Views/ColorMatrixConfigurationView.xaml @@ -16,7 +16,7 @@ If you are still not deterred, + RequestNavigate="{s:Action OpenHyperlink}"> click here for a full explanation of color transforms in SkiaSharp, the rendering library Artemis uses.