SettingsDeepLink.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Diagnostics; 7 using System.IO; 8 using ManagedCommon; 9 10 namespace Common.UI 11 { 12 public static class SettingsDeepLink 13 { 14 public enum SettingsWindow 15 { 16 Dashboard = 0, 17 Overview, 18 AlwaysOnTop, 19 Awake, 20 ColorPicker, 21 CmdNotFound, 22 LightSwitch, 23 FancyZones, 24 FileLocksmith, 25 Run, 26 ImageResizer, 27 KBM, 28 MouseUtils, 29 MouseWithoutBorders, 30 Peek, 31 PowerAccent, 32 PowerLauncher, 33 PowerPreview, 34 PowerRename, 35 FileExplorer, 36 ShortcutGuide, 37 Hosts, 38 MeasureTool, 39 PowerOCR, 40 Workspaces, 41 RegistryPreview, 42 CropAndLock, 43 EnvironmentVariables, 44 AdvancedPaste, 45 NewPlus, 46 CmdPal, 47 ZoomIt, 48 PowerDisplay, 49 } 50 51 private static string SettingsWindowNameToString(SettingsWindow value) 52 { 53 switch (value) 54 { 55 case SettingsWindow.Dashboard: 56 return "Dashboard"; 57 case SettingsWindow.Overview: 58 return "Overview"; 59 case SettingsWindow.AlwaysOnTop: 60 return "AlwaysOnTop"; 61 case SettingsWindow.Awake: 62 return "Awake"; 63 case SettingsWindow.ColorPicker: 64 return "ColorPicker"; 65 case SettingsWindow.CmdNotFound: 66 return "CmdNotFound"; 67 case SettingsWindow.LightSwitch: 68 return "LightSwitch"; 69 case SettingsWindow.FancyZones: 70 return "FancyZones"; 71 case SettingsWindow.FileLocksmith: 72 return "FileLocksmith"; 73 case SettingsWindow.Run: 74 return "Run"; 75 case SettingsWindow.ImageResizer: 76 return "ImageResizer"; 77 case SettingsWindow.KBM: 78 return "KBM"; 79 case SettingsWindow.MouseUtils: 80 return "MouseUtils"; 81 case SettingsWindow.MouseWithoutBorders: 82 return "MouseWithoutBorders"; 83 case SettingsWindow.Peek: 84 return "Peek"; 85 case SettingsWindow.PowerAccent: 86 return "PowerAccent"; 87 case SettingsWindow.PowerLauncher: 88 return "PowerLauncher"; 89 case SettingsWindow.PowerPreview: 90 return "PowerPreview"; 91 case SettingsWindow.PowerRename: 92 return "PowerRename"; 93 case SettingsWindow.FileExplorer: 94 return "FileExplorer"; 95 case SettingsWindow.ShortcutGuide: 96 return "ShortcutGuide"; 97 case SettingsWindow.Hosts: 98 return "Hosts"; 99 case SettingsWindow.MeasureTool: 100 return "MeasureTool"; 101 case SettingsWindow.PowerOCR: 102 return "PowerOcr"; 103 case SettingsWindow.Workspaces: 104 return "Workspaces"; 105 case SettingsWindow.RegistryPreview: 106 return "RegistryPreview"; 107 case SettingsWindow.CropAndLock: 108 return "CropAndLock"; 109 case SettingsWindow.EnvironmentVariables: 110 return "EnvironmentVariables"; 111 case SettingsWindow.AdvancedPaste: 112 return "AdvancedPaste"; 113 case SettingsWindow.NewPlus: 114 return "NewPlus"; 115 case SettingsWindow.CmdPal: 116 return "CmdPal"; 117 case SettingsWindow.ZoomIt: 118 return "ZoomIt"; 119 case SettingsWindow.PowerDisplay: 120 return "PowerDisplay"; 121 default: 122 { 123 return string.Empty; 124 } 125 } 126 } 127 128 // What about debug build? Should also consider debug build, maybe tray window message? 129 public static void OpenSettings(SettingsWindow window) 130 { 131 try 132 { 133 var exePath = Path.Combine( 134 PowerToysPathResolver.GetPowerToysInstallPath(), 135 "PowerToys.exe"); 136 137 if (exePath == null || !File.Exists(exePath)) 138 { 139 Logger.LogError($"Failed to find powertoys exe path, {exePath}"); 140 return; 141 } 142 143 var args = "--open-settings=" + SettingsWindowNameToString(window); 144 145 Process.Start(new ProcessStartInfo 146 { 147 FileName = exePath, 148 Arguments = args, 149 UseShellExecute = false, 150 }); 151 } 152 catch (Exception ex) 153 { 154 Logger.LogError(ex.Message); 155 } 156 } 157 } 158 }