diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index e2448a9fbd..6d9f33a32f 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -2009,6 +2009,7 @@ stdlib STDMETHODCALLTYPE STDMETHODIMP stdout +stefan STEPIT stgm STGMEDIUM diff --git a/src/common/Microsoft.PowerToys.Common.UI/SettingsDeepLink.cs b/src/common/Microsoft.PowerToys.Common.UI/SettingsDeepLink.cs new file mode 100644 index 0000000000..383ea31245 --- /dev/null +++ b/src/common/Microsoft.PowerToys.Common.UI/SettingsDeepLink.cs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; + +namespace Microsoft.PowerToys.Common.UI +{ + public static class SettingsDeepLink + { + public enum SettingsWindow + { + Overview = 0, + Awake, + ColorPicker, + FancyZones, + Run, + ImageResizer, + KBM, + PowerRename, + FileExplorer, + ShortcutGuide, + VideoConference, + } + + private static string SettingsWindowNameToString(SettingsWindow value) + { + switch (value) + { + case SettingsWindow.Overview: + return "Overview"; + case SettingsWindow.Awake: + return "Awake"; + case SettingsWindow.ColorPicker: + return "ColorPicker"; + case SettingsWindow.FancyZones: + return "FancyZones"; + case SettingsWindow.Run: + return "Run"; + case SettingsWindow.ImageResizer: + return "ImageResizer"; + case SettingsWindow.KBM: + return "KBM"; + case SettingsWindow.PowerRename: + return "PowerRename"; + case SettingsWindow.FileExplorer: + return "FileExplorer"; + case SettingsWindow.ShortcutGuide: + return "ShortcutGuide"; + case SettingsWindow.VideoConference: + return "VideoConference"; + default: + { + return string.Empty; + } + } + } + + public static void OpenSettings(SettingsWindow window) + { + try + { + Process.Start(new ProcessStartInfo(Environment.CurrentDirectory + "\\PowerToys.exe") { Arguments = "--open-settings=" + SettingsWindowNameToString(window) }); + } +#pragma warning disable CA1031 // Do not catch general exception types + catch +#pragma warning restore CA1031 // Do not catch general exception types + { + // TODO(stefan): Log exception once unified logging is implemented + } + } + } +} diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs index f878300f28..09a31131a0 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs @@ -4,11 +4,10 @@ using System; using System.ComponentModel.Composition; -using System.Diagnostics; -using System.IO; using System.Windows; using ColorPicker.Settings; using ColorPicker.ViewModelContracts; +using Microsoft.PowerToys.Common.UI; using Microsoft.PowerToys.Settings.UI.Library.Enumerations; namespace ColorPicker.Helpers @@ -189,17 +188,7 @@ namespace ColorPicker.Helpers private void ColorEditorViewModel_OpenSettingsRequested(object sender, EventArgs e) { - try - { - var assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); - var fullPath = Directory.GetParent(assemblyPath).FullName; - Process.Start(new ProcessStartInfo(fullPath + "\\..\\PowerToys.exe") { Arguments = "--open-settings=ColorPicker" }); - } -#pragma warning disable CA1031 // Do not catch general exception types - catch -#pragma warning restore CA1031 // Do not catch general exception types - { - } + SettingsDeepLink.OpenSettings(SettingsDeepLink.SettingsWindow.ColorPicker); } } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs index 9fcec8e527..db920bd935 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Controls; using System.Windows.Input; using FancyZonesEditor.Models; using FancyZonesEditor.Utils; +using Microsoft.PowerToys.Common.UI; using ModernWpf.Controls; namespace FancyZonesEditor @@ -521,15 +522,7 @@ namespace FancyZonesEditor private void SettingsBtn_Click(object sender, RoutedEventArgs e) { - try - { - var assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); - var fullPath = Directory.GetParent(assemblyPath).FullName; - Process.Start(new ProcessStartInfo(fullPath + "\\..\\PowerToys.exe") { Arguments = "--open-settings=FancyZones" }); - } - catch - { - } + SettingsDeepLink.OpenSettings(SettingsDeepLink.SettingsWindow.FancyZones); } } }