Adapt Always on Top module to use right settings and GPO

This commit is contained in:
Noraa Junker
2025-11-19 14:52:37 +01:00
parent 2ddf561f57
commit 6dd9617538
6 changed files with 44 additions and 5 deletions

View File

@@ -6,7 +6,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Windows.System;
using static RunnerV2.NativeMethods;
namespace RunnerV2.Helpers
@@ -15,6 +18,7 @@ namespace RunnerV2.Helpers
{
private static readonly Dictionary<HotkeyEx, Action> _hotkeyActions = [];
[STAThread]
public static void EnableHotkey(HotkeyEx hotkey, Action onHotkey)
{
if (_hotkeyActions.ContainsKey(hotkey))

View File

@@ -150,7 +150,7 @@ namespace RunnerV2.Helpers
case "powertoys":
foreach (var powertoysSettingsPart in property.Value.EnumerateObject())
{
_settingsUtils.SaveSettings(property.Value.ToString(), powertoysSettingsPart.Name);
_settingsUtils.SaveSettings(powertoysSettingsPart.Value.ToString(), powertoysSettingsPart.Name);
if (Runner.LoadedModules.Find(m => m.Name == powertoysSettingsPart.Name) is IPowerToysModule module)
{

View File

@@ -12,6 +12,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using ManagedCommon;
using RunnerV2.Helpers;
@@ -37,7 +38,12 @@ namespace RunnerV2
internal static bool Run(Action afterInitializationAction)
{
TrayIconManager.StartTrayIcon();
FrozenSet<string> modulesToLoad = ["PowerToys.AlwaysOnTopModuleInterface.dll", "WinUI3Apps\\PowerToys.Hosts.dll"];
FrozenSet<string> modulesToLoad =
[
"PowerToys.AlwaysOnTopModuleInterface.dll",
"WinUI3Apps\\PowerToys.Hosts.dll",
"PowerAccent.Core.dll",
];
List<string> failedModuleLoads = [];
@@ -152,6 +158,9 @@ namespace RunnerV2
}
}
public static Thread? WindowThread { get; set; }
[STAThread]
private static void InitializeTrayWindow()
{
IntPtr hInstance = Process.GetCurrentProcess().MainModule!.BaseAddress;

View File

@@ -15,7 +15,7 @@ namespace Hosts
{
public bool Enabled => new SettingsUtils().GetSettingsOrDefault<GeneralSettings>().Enabled.Hosts;
public GpoRuleConfigured GpoRuleConfigured => GpoRuleConfigured.NotConfigured;
public GpoRuleConfigured GpoRuleConfigured => GPOWrapper.GetConfiguredHostsFileEditorEnabledValue();
public string Name => "Hosts";

View File

@@ -18,7 +18,7 @@ namespace AlwaysOnTopModuleInterface
public string Name => "AlwaysOnTop";
public GpoRuleConfigured GpoRuleConfigured => GpoRuleConfigured.Unavailable;
public GpoRuleConfigured GpoRuleConfigured => GPOWrapper.GetConfiguredAlwaysOnTopEnabledValue();
private Process? _process;
@@ -48,7 +48,7 @@ namespace AlwaysOnTopModuleInterface
_process = Process.Start(psi);
}
public HotkeyEx HotkeyEx => new(0x2 | 0x1, 0x54); // Ctrl + Alt + T
public HotkeyEx HotkeyEx => new SettingsUtils().GetSettings<AlwaysOnTopSettings>(Name).Properties.Hotkey.Value;
public Action OnHotkey => () =>
{

View File

@@ -316,5 +316,31 @@ namespace Microsoft.PowerToys.Settings.UI.Library
result = result.Replace(" ", null);
return true;
}
public static implicit operator HotkeyEx(HotkeySettings settings)
{
ushort modifiers = 0;
if (settings.Ctrl)
{
modifiers += 0x0002;
}
if (settings.Alt)
{
modifiers += 0x0001;
}
if (settings.Shift)
{
modifiers += 0x0004;
}
if (settings.Win)
{
modifiers += 0x0008;
}
return new HotkeyEx(modifiers, (ushort)settings.Code);
}
}
}