feat(ads/seo/release): v1.2.0 with live Google Ads, isolated ad profile, ads.txt, and SEO/AEO/GEO optimization
This commit is contained in:
parent
a88aafa1e5
commit
0e568f1f0a
975 changed files with 130593 additions and 16783 deletions
82
src/Paca.App/Core/GlobalHotkeyManager.cs
Normal file
82
src/Paca.App/Core/GlobalHotkeyManager.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Paca.App.Core;
|
||||
|
||||
public static class GlobalHotkeyParser
|
||||
{
|
||||
public static bool TryParse(string rawShortcut, out ModifierKeys modifiers, out Key key)
|
||||
{
|
||||
modifiers = ModifierKeys.None;
|
||||
key = Key.None;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(rawShortcut)) return false;
|
||||
|
||||
var parts = rawShortcut.Split('+', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 0) return false;
|
||||
|
||||
for (int i = 0; i < parts.Length; i++)
|
||||
{
|
||||
var p = parts[i];
|
||||
if (string.Equals(p, "Ctrl", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(p, "Control", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modifiers |= ModifierKeys.Control;
|
||||
}
|
||||
else if (string.Equals(p, "Alt", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modifiers |= ModifierKeys.Alt;
|
||||
}
|
||||
else if (string.Equals(p, "Shift", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modifiers |= ModifierKeys.Shift;
|
||||
}
|
||||
else if (string.Equals(p, "Win", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(p, "Windows", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modifiers |= ModifierKeys.Windows;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Enum.TryParse<Key>(p, true, out var parsedKey))
|
||||
{
|
||||
key = parsedKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return key != Key.None;
|
||||
}
|
||||
}
|
||||
|
||||
public class GlobalHotkeyManager
|
||||
{
|
||||
private readonly Dictionary<string, Action> _callbacks = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static uint GetWin32ModifierFlags(ModifierKeys modifiers)
|
||||
{
|
||||
uint flags = 0;
|
||||
if (modifiers.HasFlag(ModifierKeys.Alt)) flags |= 0x0001;
|
||||
if (modifiers.HasFlag(ModifierKeys.Control)) flags |= 0x0002;
|
||||
if (modifiers.HasFlag(ModifierKeys.Shift)) flags |= 0x0004;
|
||||
if (modifiers.HasFlag(ModifierKeys.Windows)) flags |= 0x0008;
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void RegisterVirtualHotkey(string shortcut, Action callback)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(shortcut) || callback == null) return;
|
||||
_callbacks[shortcut] = callback;
|
||||
}
|
||||
|
||||
public bool SimulateHotkeyTrigger(string shortcut)
|
||||
{
|
||||
if (_callbacks.TryGetValue(shortcut, out var action))
|
||||
{
|
||||
action();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue