mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Implemented shortcut
Signed-off-by: Shawn Yuan (from Dev Box) <shuaiyuan@microsoft.com>
This commit is contained in:
@@ -36,5 +36,6 @@ namespace ManagedCommon
|
|||||||
PowerOCR,
|
PowerOCR,
|
||||||
Workspaces,
|
Workspaces,
|
||||||
ZoomIt,
|
ZoomIt,
|
||||||
|
GeneralSettings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,6 +189,12 @@ GeneralSettings get_general_settings()
|
|||||||
|
|
||||||
void apply_general_settings(const json::JsonObject& general_configs, bool save)
|
void apply_general_settings(const json::JsonObject& general_configs, bool save)
|
||||||
{
|
{
|
||||||
|
std::wstring old_settings_json_string;
|
||||||
|
if (save)
|
||||||
|
{
|
||||||
|
old_settings_json_string = get_general_settings().to_json().Stringify().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
Logger::info(L"apply_general_settings: {}", std::wstring{ general_configs.ToString() });
|
Logger::info(L"apply_general_settings: {}", std::wstring{ general_configs.ToString() });
|
||||||
run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false);
|
run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false);
|
||||||
|
|
||||||
@@ -355,8 +361,12 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
|
|||||||
if (save)
|
if (save)
|
||||||
{
|
{
|
||||||
GeneralSettings save_settings = get_general_settings();
|
GeneralSettings save_settings = get_general_settings();
|
||||||
PTSettingsHelper::save_general_settings(save_settings.to_json());
|
std::wstring new_settings_json_string = save_settings.to_json().Stringify().c_str();
|
||||||
Trace::SettingsChanged(save_settings);
|
if (old_settings_json_string != new_settings_json_string)
|
||||||
|
{
|
||||||
|
PTSettingsHelper::save_general_settings(save_settings.to_json());
|
||||||
|
Trace::SettingsChanged(save_settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -190,12 +190,12 @@ void dispatch_received_json(const std::wstring& json_to_parse)
|
|||||||
if (name == L"general")
|
if (name == L"general")
|
||||||
{
|
{
|
||||||
apply_general_settings(value.GetObjectW());
|
apply_general_settings(value.GetObjectW());
|
||||||
const std::wstring settings_string{ get_all_settings().Stringify().c_str() };
|
// const std::wstring settings_string{ get_all_settings().Stringify().c_str() };
|
||||||
{
|
// {
|
||||||
std::unique_lock lock{ ipc_mutex };
|
// std::unique_lock lock{ ipc_mutex };
|
||||||
if (current_settings_ipc)
|
// if (current_settings_ipc)
|
||||||
current_settings_ipc->send(settings_string);
|
// current_settings_ipc->send(settings_string);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
else if (name == L"powertoys")
|
else if (name == L"powertoys")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "centralized_hotkeys.h"
|
#include "centralized_hotkeys.h"
|
||||||
#include "centralized_kb_hook.h"
|
#include "centralized_kb_hook.h"
|
||||||
#include "quick_access_host.h"
|
#include "quick_access_host.h"
|
||||||
|
#include "hotkey_conflict_detector.h"
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#include <common/utils/resources.h>
|
#include <common/utils/resources.h>
|
||||||
@@ -357,18 +358,31 @@ void update_quick_access_hotkey(bool enabled, PowerToysSettings::HotkeyObject ho
|
|||||||
{
|
{
|
||||||
static PowerToysSettings::HotkeyObject current_hotkey;
|
static PowerToysSettings::HotkeyObject current_hotkey;
|
||||||
static bool is_registered = false;
|
static bool is_registered = false;
|
||||||
|
auto& hkmng = HotkeyConflictDetector::HotkeyConflictManager::GetInstance();
|
||||||
|
|
||||||
if (is_registered)
|
if (is_registered)
|
||||||
{
|
{
|
||||||
CentralizedHotkeys::UnregisterHotkeysForModule(L"QuickAccess");
|
CentralizedKeyboardHook::ClearModuleHotkeys(L"QuickAccess");
|
||||||
|
hkmng.RemoveHotkeyByModule(L"GeneralSettings");
|
||||||
is_registered = false;
|
is_registered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabled && hotkey.get_code() != 0)
|
if (enabled && hotkey.get_code() != 0)
|
||||||
{
|
{
|
||||||
CentralizedHotkeys::AddHotkeyAction({ static_cast<WORD>(hotkey.get_modifiers()), static_cast<WORD>(hotkey.get_code()) }, { L"QuickAccess", [](WORD, WORD) {
|
HotkeyConflictDetector::Hotkey hk = {
|
||||||
|
hotkey.win_pressed(),
|
||||||
|
hotkey.ctrl_pressed(),
|
||||||
|
hotkey.shift_pressed(),
|
||||||
|
hotkey.alt_pressed(),
|
||||||
|
static_cast<unsigned char>(hotkey.get_code())
|
||||||
|
};
|
||||||
|
|
||||||
|
hkmng.AddHotkey(hk, L"GeneralSettings", 0, true);
|
||||||
|
CentralizedKeyboardHook::SetHotkeyAction(L"QuickAccess", hk, []() {
|
||||||
open_quick_access_flyout_window();
|
open_quick_access_flyout_window();
|
||||||
}});
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
current_hotkey = hotkey;
|
current_hotkey = hotkey;
|
||||||
is_registered = true;
|
is_registered = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,9 @@
|
|||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||||
<ResourceDictionary Source="ms-appx:///Resources/Styles/Button.xaml" />
|
<ResourceDictionary Source="/Resources/Styles/Button.xaml" />
|
||||||
<ResourceDictionary Source="ms-appx:///Resources/Styles/TextBlock.xaml" />
|
<ResourceDictionary Source="/Resources/Styles/TextBlock.xaml" />
|
||||||
<ResourceDictionary Source="ms-appx:///Resources/Themes/Colors.xaml" />
|
<ResourceDictionary Source="/Resources/Themes/Colors.xaml" />
|
||||||
<ResourceDictionary Source="ms-appx:///Resources/Themes/Generic.xaml" />
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
<ResourceDictionary.ThemeDictionaries>
|
<ResourceDictionary.ThemeDictionaries>
|
||||||
@@ -20,21 +19,29 @@
|
|||||||
x:Key="LayerOnAcrylicFillColorDefaultBrush"
|
x:Key="LayerOnAcrylicFillColorDefaultBrush"
|
||||||
Opacity="0.7"
|
Opacity="0.7"
|
||||||
Color="#FFFFFFFF" />
|
Color="#FFFFFFFF" />
|
||||||
|
<SolidColorBrush x:Key="CardStrokeColorDefaultBrush" Color="#0F000000" />
|
||||||
|
<SolidColorBrush x:Key="CardBackgroundFillColorDefaultBrush" Color="#B3FFFFFF" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
<ResourceDictionary x:Key="Light">
|
<ResourceDictionary x:Key="Light">
|
||||||
<SolidColorBrush
|
<SolidColorBrush
|
||||||
x:Key="LayerOnAcrylicFillColorDefaultBrush"
|
x:Key="LayerOnAcrylicFillColorDefaultBrush"
|
||||||
Opacity="0.7"
|
Opacity="0.7"
|
||||||
Color="#FFFFFFFF" />
|
Color="#FFFFFFFF" />
|
||||||
|
<SolidColorBrush x:Key="CardStrokeColorDefaultBrush" Color="#0F000000" />
|
||||||
|
<SolidColorBrush x:Key="CardBackgroundFillColorDefaultBrush" Color="#B3FFFFFF" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
<ResourceDictionary x:Key="Dark">
|
<ResourceDictionary x:Key="Dark">
|
||||||
<SolidColorBrush
|
<SolidColorBrush
|
||||||
x:Key="LayerOnAcrylicFillColorDefaultBrush"
|
x:Key="LayerOnAcrylicFillColorDefaultBrush"
|
||||||
Opacity="0.6"
|
Opacity="0.6"
|
||||||
Color="#FF000000" />
|
Color="#FF000000" />
|
||||||
|
<SolidColorBrush x:Key="CardStrokeColorDefaultBrush" Color="#0FFFFFFF" />
|
||||||
|
<SolidColorBrush x:Key="CardBackgroundFillColorDefaultBrush" Color="#0DFFFFFF" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
<ResourceDictionary x:Key="HighContrast">
|
<ResourceDictionary x:Key="HighContrast">
|
||||||
<SolidColorBrush x:Key="LayerOnAcrylicFillColorDefaultBrush" Color="{ThemeResource SystemColorWindowColor}" />
|
<SolidColorBrush x:Key="LayerOnAcrylicFillColorDefaultBrush" Color="{ThemeResource SystemColorWindowColor}" />
|
||||||
|
<SolidColorBrush x:Key="CardStrokeColorDefaultBrush" Color="{ThemeResource SystemColorWindowTextColor}" />
|
||||||
|
<SolidColorBrush x:Key="CardBackgroundFillColorDefaultBrush" Color="{ThemeResource SystemColorWindowColor}" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</ResourceDictionary.ThemeDictionaries>
|
</ResourceDictionary.ThemeDictionaries>
|
||||||
|
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ public sealed partial class MainWindow : WindowEx, IDisposable
|
|||||||
_exitEvent?.Dispose();
|
_exitEvent?.Dispose();
|
||||||
_exitEvent = null;
|
_exitEvent = null;
|
||||||
|
|
||||||
if (_hwnd != IntPtr.Zero)
|
if (_hwnd != IntPtr.Zero && IsWindow(_hwnd))
|
||||||
{
|
{
|
||||||
UncloakWindow();
|
UncloakWindow();
|
||||||
}
|
}
|
||||||
@@ -385,6 +385,10 @@ public sealed partial class MainWindow : WindowEx, IDisposable
|
|||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
private static extern bool IsWindow(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
|
[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
|
||||||
private static extern bool ShowWindowNative(IntPtr hWnd, int nCmdShow);
|
private static extern bool ShowWindowNative(IntPtr hWnd, int nCmdShow);
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,11 @@ public sealed class AllAppsViewModel : Observable
|
|||||||
|
|
||||||
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
|
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
|
||||||
{
|
{
|
||||||
|
if (moduleType == ModuleType.GeneralSettings)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
var gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
||||||
var isLocked = gpo is GpoRuleConfigured.Enabled or GpoRuleConfigured.Disabled;
|
var isLocked = gpo is GpoRuleConfigured.Enabled or GpoRuleConfigured.Disabled;
|
||||||
var isEnabled = gpo == GpoRuleConfigured.Enabled || (!isLocked && ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType));
|
var isEnabled = gpo == GpoRuleConfigured.Enabled || (!isLocked && ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Text.Json;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||||
using Settings.UI.Library.Attributes;
|
using Settings.UI.Library.Attributes;
|
||||||
@@ -19,7 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
ByStatus,
|
ByStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GeneralSettings : ISettingsConfig
|
public class GeneralSettings : ISettingsConfig, IHotkeyConfig
|
||||||
{
|
{
|
||||||
// Gets or sets a value indicating whether run powertoys on start-up.
|
// Gets or sets a value indicating whether run powertoys on start-up.
|
||||||
[JsonPropertyName("startup")]
|
[JsonPropertyName("startup")]
|
||||||
@@ -126,6 +127,22 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
IgnoredConflictProperties = new ShortcutConflictProperties();
|
IgnoredConflictProperties = new ShortcutConflictProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HotkeyAccessor[] GetAllHotkeyAccessors()
|
||||||
|
{
|
||||||
|
return new HotkeyAccessor[]
|
||||||
|
{
|
||||||
|
new HotkeyAccessor(
|
||||||
|
() => QuickAccessShortcut,
|
||||||
|
(hotkey) => { QuickAccessShortcut = hotkey; },
|
||||||
|
"GeneralPage_QuickAccessShortcut"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleType GetModuleType()
|
||||||
|
{
|
||||||
|
return ModuleType.GeneralSettings;
|
||||||
|
}
|
||||||
|
|
||||||
// converts the current to a json string.
|
// converts the current to a json string.
|
||||||
public string ToJsonString()
|
public string ToJsonString()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,6 +68,11 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
|||||||
if (settingsInstance != null)
|
if (settingsInstance != null)
|
||||||
{
|
{
|
||||||
var moduleName = settingsInstance.GetModuleName();
|
var moduleName = settingsInstance.GetModuleName();
|
||||||
|
if (string.IsNullOrEmpty(moduleName) && type == typeof(GeneralSettings))
|
||||||
|
{
|
||||||
|
moduleName = "GeneralSettings";
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(moduleName))
|
if (!string.IsNullOrEmpty(moduleName))
|
||||||
{
|
{
|
||||||
settingsTypes[moduleName] = type;
|
settingsTypes[moduleName] = type;
|
||||||
@@ -104,7 +109,13 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
|||||||
var genericMethod = getSettingsMethod?.MakeGenericMethod(settingsType);
|
var genericMethod = getSettingsMethod?.MakeGenericMethod(settingsType);
|
||||||
|
|
||||||
// Call GetSettingsOrDefault<T>(moduleKey) to get fresh settings from file
|
// Call GetSettingsOrDefault<T>(moduleKey) to get fresh settings from file
|
||||||
var freshSettings = genericMethod?.Invoke(_settingsUtils, new object[] { moduleKey, "settings.json" });
|
string actualModuleKey = moduleKey;
|
||||||
|
if (moduleKey == "GeneralSettings")
|
||||||
|
{
|
||||||
|
actualModuleKey = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var freshSettings = genericMethod?.Invoke(_settingsUtils, new object[] { actualModuleKey, "settings.json" });
|
||||||
|
|
||||||
return freshSettings as IHotkeyConfig;
|
return freshSettings as IHotkeyConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
case ModuleType.MouseJump:
|
case ModuleType.MouseJump:
|
||||||
case ModuleType.MousePointerCrosshairs:
|
case ModuleType.MousePointerCrosshairs:
|
||||||
case ModuleType.CursorWrap: return $"MouseUtils_{moduleType}/Header";
|
case ModuleType.CursorWrap: return $"MouseUtils_{moduleType}/Header";
|
||||||
|
case ModuleType.GeneralSettings: return "QuickAccessTitle/Title";
|
||||||
default: return $"{moduleType}/ModuleTitle";
|
default: return $"{moduleType}/ModuleTitle";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +40,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
case ModuleType.MousePointerCrosshairs: return "ms-appx:///Assets/Settings/Icons/MouseCrosshairs.png";
|
case ModuleType.MousePointerCrosshairs: return "ms-appx:///Assets/Settings/Icons/MouseCrosshairs.png";
|
||||||
case ModuleType.MeasureTool: return "ms-appx:///Assets/Settings/Icons/ScreenRuler.png";
|
case ModuleType.MeasureTool: return "ms-appx:///Assets/Settings/Icons/ScreenRuler.png";
|
||||||
case ModuleType.PowerLauncher: return $"ms-appx:///Assets/Settings/Icons/PowerToysRun.png";
|
case ModuleType.PowerLauncher: return $"ms-appx:///Assets/Settings/Icons/PowerToysRun.png";
|
||||||
|
case ModuleType.GeneralSettings: return "ms-appx:///Assets/Settings/Icons/PowerToys.png";
|
||||||
default: return $"ms-appx:///Assets/Settings/Icons/{moduleType}.png";
|
default: return $"ms-appx:///Assets/Settings/Icons/{moduleType}.png";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +79,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
case ModuleType.ShortcutGuide: return generalSettingsConfig.Enabled.ShortcutGuide;
|
case ModuleType.ShortcutGuide: return generalSettingsConfig.Enabled.ShortcutGuide;
|
||||||
case ModuleType.PowerOCR: return generalSettingsConfig.Enabled.PowerOcr;
|
case ModuleType.PowerOCR: return generalSettingsConfig.Enabled.PowerOcr;
|
||||||
case ModuleType.ZoomIt: return generalSettingsConfig.Enabled.ZoomIt;
|
case ModuleType.ZoomIt: return generalSettingsConfig.Enabled.ZoomIt;
|
||||||
|
case ModuleType.GeneralSettings: return generalSettingsConfig.EnableQuickAccess;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,6 +118,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
case ModuleType.ShortcutGuide: generalSettingsConfig.Enabled.ShortcutGuide = isEnabled; break;
|
case ModuleType.ShortcutGuide: generalSettingsConfig.Enabled.ShortcutGuide = isEnabled; break;
|
||||||
case ModuleType.PowerOCR: generalSettingsConfig.Enabled.PowerOcr = isEnabled; break;
|
case ModuleType.PowerOCR: generalSettingsConfig.Enabled.PowerOcr = isEnabled; break;
|
||||||
case ModuleType.ZoomIt: generalSettingsConfig.Enabled.ZoomIt = isEnabled; break;
|
case ModuleType.ZoomIt: generalSettingsConfig.Enabled.ZoomIt = isEnabled; break;
|
||||||
|
case ModuleType.GeneralSettings: generalSettingsConfig.EnableQuickAccess = isEnabled; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +175,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
ModuleType.FancyZones => typeof(FancyZonesPage),
|
ModuleType.FancyZones => typeof(FancyZonesPage),
|
||||||
ModuleType.FileLocksmith => typeof(FileLocksmithPage),
|
ModuleType.FileLocksmith => typeof(FileLocksmithPage),
|
||||||
ModuleType.FindMyMouse => typeof(MouseUtilsPage),
|
ModuleType.FindMyMouse => typeof(MouseUtilsPage),
|
||||||
|
ModuleType.GeneralSettings => typeof(GeneralPage),
|
||||||
ModuleType.Hosts => typeof(HostsPage),
|
ModuleType.Hosts => typeof(HostsPage),
|
||||||
ModuleType.ImageResizer => typeof(ImageResizerPage),
|
ModuleType.ImageResizer => typeof(ImageResizerPage),
|
||||||
ModuleType.KeyboardManager => typeof(KeyboardManagerPage),
|
ModuleType.KeyboardManager => typeof(KeyboardManagerPage),
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
CheckBugReportStatus();
|
CheckBugReportStatus();
|
||||||
|
|
||||||
doRefreshBackupRestoreStatus(100);
|
doRefreshBackupRestoreStatus(100);
|
||||||
|
|
||||||
|
this.Loaded += (s, e) => ViewModel.OnPageLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenColorsSettings_Click(object sender, RoutedEventArgs e)
|
private void OpenColorsSettings_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
// Flag to prevent circular updates when a UI toggle triggers settings changes.
|
// Flag to prevent circular updates when a UI toggle triggers settings changes.
|
||||||
private bool _isUpdatingFromUI;
|
private bool _isUpdatingFromUI;
|
||||||
|
private bool _isUpdatingFromSettings;
|
||||||
|
|
||||||
private AllHotkeyConflictsData _allHotkeyConflictsData = new AllHotkeyConflictsData();
|
private AllHotkeyConflictsData _allHotkeyConflictsData = new AllHotkeyConflictsData();
|
||||||
|
|
||||||
@@ -164,6 +165,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
|
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
|
||||||
{
|
{
|
||||||
|
if (moduleType == ModuleType.GeneralSettings)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
||||||
var newItem = new DashboardListItem()
|
var newItem = new DashboardListItem()
|
||||||
{
|
{
|
||||||
@@ -263,6 +269,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void EnabledChangedOnUI(DashboardListItem dashboardListItem)
|
private void EnabledChangedOnUI(DashboardListItem dashboardListItem)
|
||||||
{
|
{
|
||||||
|
if (_isUpdatingFromSettings)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_isUpdatingFromUI = true;
|
_isUpdatingFromUI = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -306,6 +317,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isUpdatingFromSettings = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RefreshModuleList();
|
RefreshModuleList();
|
||||||
@@ -320,6 +332,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
{
|
{
|
||||||
Logger.LogError($"Updating active/disabled modules list failed: {ex.Message}");
|
Logger.LogError($"Updating active/disabled modules list failed: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isUpdatingFromSettings = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -731,5 +747,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
NavigationService.Navigate(ModuleHelper.GetModulePageType(moduleType));
|
NavigationService.Navigate(ModuleHelper.GetModulePageType(moduleType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
base.Dispose();
|
||||||
|
if (_settingsRepository != null)
|
||||||
|
{
|
||||||
|
_settingsRepository.SettingsChanged -= OnSettingsChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ using Windows.System.Profile;
|
|||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||||
{
|
{
|
||||||
public partial class GeneralViewModel : Observable
|
public partial class GeneralViewModel : PageViewModelBase
|
||||||
{
|
{
|
||||||
public enum InstallScope
|
public enum InstallScope
|
||||||
{
|
{
|
||||||
@@ -39,6 +39,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
PerUser,
|
PerUser,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override string ModuleName => "GeneralSettings";
|
||||||
|
|
||||||
|
public override Dictionary<string, HotkeySettings[]> GetAllHotkeySettings()
|
||||||
|
{
|
||||||
|
return new Dictionary<string, HotkeySettings[]>
|
||||||
|
{
|
||||||
|
{ ModuleName, new HotkeySettings[] { QuickAccessShortcut } },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||||
|
|
||||||
private UpdatingSettings UpdatingSettingsConfig { get; set; }
|
private UpdatingSettings UpdatingSettingsConfig { get; set; }
|
||||||
@@ -75,6 +85,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
private string _settingsConfigFileFolder = string.Empty;
|
private string _settingsConfigFileFolder = string.Empty;
|
||||||
|
|
||||||
|
private ISettingsRepository<GeneralSettings> _settingsRepository;
|
||||||
|
private Microsoft.UI.Dispatching.DispatcherQueue _dispatcherQueue;
|
||||||
|
|
||||||
private IFileSystemWatcher _fileWatcher;
|
private IFileSystemWatcher _fileWatcher;
|
||||||
|
|
||||||
private Func<Task<string>> PickSingleFolderDialog { get; }
|
private Func<Task<string>> PickSingleFolderDialog { get; }
|
||||||
@@ -100,6 +113,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
// To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
|
// To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
|
||||||
ArgumentNullException.ThrowIfNull(settingsRepository);
|
ArgumentNullException.ThrowIfNull(settingsRepository);
|
||||||
|
|
||||||
|
_settingsRepository = settingsRepository;
|
||||||
|
_settingsRepository.SettingsChanged += OnSettingsChanged;
|
||||||
|
_dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
|
||||||
|
|
||||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||||
UpdatingSettingsConfig = UpdatingSettings.LoadSettings();
|
UpdatingSettingsConfig = UpdatingSettings.LoadSettings();
|
||||||
if (UpdatingSettingsConfig == null)
|
if (UpdatingSettingsConfig == null)
|
||||||
@@ -1493,5 +1510,30 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
Process.Start("explorer.exe", etwDirPath);
|
Process.Start("explorer.exe", etwDirPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSettingsChanged(GeneralSettings newSettings)
|
||||||
|
{
|
||||||
|
_dispatcherQueue?.TryEnqueue(() =>
|
||||||
|
{
|
||||||
|
GeneralSettingsConfig = newSettings;
|
||||||
|
|
||||||
|
if (_enableQuickAccess != newSettings.EnableQuickAccess)
|
||||||
|
{
|
||||||
|
_enableQuickAccess = newSettings.EnableQuickAccess;
|
||||||
|
OnPropertyChanged(nameof(EnableQuickAccess));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
base.Dispose();
|
||||||
|
if (_settingsRepository != null)
|
||||||
|
{
|
||||||
|
_settingsRepository.SettingsChanged -= OnSettingsChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user