Skip to content

Commit

Permalink
Move Settings deep link logic to Microsoft.PowerToys.Common.UI (#13749)
Browse files Browse the repository at this point in the history
* Move Settings deep link logic to Microsoft.PowerToys.Common.UI

* Spellcheck

* Introduce enum

* Remove PT path arg
  • Loading branch information
stefansjfw committed Oct 12, 2021
1 parent 0ca9b1b commit 7e8e954
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,7 @@ stdlib
STDMETHODCALLTYPE
STDMETHODIMP
stdout
stefan
STEPIT
stgm
STGMEDIUM
Expand Down
74 changes: 74 additions & 0 deletions src/common/Microsoft.PowerToys.Common.UI/SettingsDeepLink.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
15 changes: 2 additions & 13 deletions src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -189,17 +188,7 @@ private void ColorEditorViewModel_OpenColorPickerRequested(object sender, EventA

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Input;
using FancyZonesEditor.Models;
using FancyZonesEditor.Utils;
using Microsoft.PowerToys.Common.UI;
using ModernWpf.Controls;

namespace FancyZonesEditor
Expand Down Expand Up @@ -521,15 +522,7 @@ private void NumberBox_Loaded(object sender, RoutedEventArgs e)

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);
}
}
}

0 comments on commit 7e8e954

Please sign in to comment.