mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-29 16:36:40 +01:00
Compare commits
4 Commits
vanzue-pat
...
v0.91.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
712b31aecd | ||
|
|
99076697d0 | ||
|
|
f9fe88696b | ||
|
|
a71d7e9282 |
@@ -25,6 +25,7 @@ namespace AppLauncher
|
||||
const std::wstring ChromeFilename = L"chrome.exe";
|
||||
const std::wstring ChromePwaFilename = L"chrome_proxy.exe";
|
||||
const std::wstring PwaCommandLineAddition = L"--profile-directory=Default --app-id=";
|
||||
const std::wstring SteamProtocolPrefix = L"steam:";
|
||||
}
|
||||
|
||||
Result<SHELLEXECUTEINFO, std::wstring> LaunchApp(const std::wstring& appPath, const std::wstring& commandLineArgs, bool elevated)
|
||||
@@ -134,12 +135,11 @@ namespace AppLauncher
|
||||
}
|
||||
}
|
||||
|
||||
// win32 app with appUserModelId:
|
||||
// usage example: steam games
|
||||
if (!launched && !app.appUserModelId.empty())
|
||||
// protocol launch for steam
|
||||
if (!launched && !app.appUserModelId.empty() && app.appUserModelId.contains(NonLocalizable::SteamProtocolPrefix))
|
||||
{
|
||||
Logger::trace(L"Launching {} as {}", app.name, app.appUserModelId);
|
||||
auto res = LaunchApp(L"shell:AppsFolder\\" + app.appUserModelId, app.commandLineArgs, app.isElevated);
|
||||
auto res = LaunchApp(app.appUserModelId, app.commandLineArgs, app.isElevated);
|
||||
if (res.isOk())
|
||||
{
|
||||
launched = true;
|
||||
|
||||
@@ -217,7 +217,9 @@ public:
|
||||
CmdPal::m_enabled.store(true);
|
||||
|
||||
std::wstring packageName = L"Microsoft.CommandPalette";
|
||||
std::wstring launchPath = L"x-cmdpal://background";
|
||||
// Launch CmdPal as normal user using explorer
|
||||
std::wstring launchPath = L"explorer.exe";
|
||||
std::wstring launchArgs = L"x-cmdpal://background";
|
||||
#ifdef IS_DEV_BRANDING
|
||||
packageName = L"Microsoft.CommandPalette.Dev";
|
||||
#endif
|
||||
@@ -268,13 +270,13 @@ public:
|
||||
if (!firstEnableCall)
|
||||
{
|
||||
Logger::trace("Not first attempt, try to launch");
|
||||
LaunchApp(launchPath, L"", false /*no elevated*/, false /*error pop up*/);
|
||||
LaunchApp(launchPath, launchArgs, false /*no elevated*/, false /*error pop up*/);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If first time enable, do retry launch.
|
||||
Logger::trace("First attempt, try to launch");
|
||||
std::thread launchThread(&CmdPal::RetryLaunch, launchPath);
|
||||
std::thread launchThread(&CmdPal::RetryLaunch, launchPath, launchArgs);
|
||||
launchThread.detach();
|
||||
}
|
||||
|
||||
@@ -289,14 +291,14 @@ public:
|
||||
CmdPal::m_enabled.store(false);
|
||||
}
|
||||
|
||||
static void RetryLaunch(std::wstring path)
|
||||
static void RetryLaunch(std::wstring path, std::wstring cmdArgs)
|
||||
{
|
||||
const int base_delay_milliseconds = 1000;
|
||||
int max_retry = 9; // 2**9 - 1 seconds. Control total wait time within 10 min.
|
||||
int retry = 0;
|
||||
do
|
||||
{
|
||||
auto launch_result = LaunchApp(path, L"", false, retry < max_retry);
|
||||
auto launch_result = LaunchApp(path, cmdArgs, false, retry < max_retry);
|
||||
if (launch_result)
|
||||
{
|
||||
Logger::info(L"CmdPal launched successfully after {} retries.", retry);
|
||||
@@ -348,4 +350,4 @@ std::atomic<bool> CmdPal::m_launched{ false };
|
||||
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
|
||||
{
|
||||
return new CmdPal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ public partial class PowerAccent : IDisposable
|
||||
|
||||
private void SetEvents()
|
||||
{
|
||||
_keyboardListener.SetShowToolbarEvent(new PowerToys.PowerAccentKeyboardService.ShowToolbar((LetterKey letterKey, TriggerKey trigger ) =>
|
||||
_keyboardListener.SetShowToolbarEvent(new PowerToys.PowerAccentKeyboardService.ShowToolbar((LetterKey letterKey) =>
|
||||
{
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
ShowToolbar(letterKey, trigger);
|
||||
ShowToolbar(letterKey);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -92,15 +92,23 @@ public partial class PowerAccent : IDisposable
|
||||
}));
|
||||
}
|
||||
|
||||
private void ShowToolbar(LetterKey letterKey, TriggerKey trigger)
|
||||
private void ShowToolbar(LetterKey letterKey)
|
||||
{
|
||||
_visible = true;
|
||||
|
||||
_characters = GetCharacters(letterKey);
|
||||
_characterDescriptions = GetCharacterDescriptions(_characters);
|
||||
_showUnicodeDescription = _settingService.ShowUnicodeDescription;
|
||||
OnChangeDisplay?.Invoke(true, _characters);
|
||||
ProcessNextChar(trigger, false);
|
||||
|
||||
Task.Delay(_settingService.InputTime).ContinueWith(
|
||||
t =>
|
||||
{
|
||||
if (_visible)
|
||||
{
|
||||
OnChangeDisplay?.Invoke(true, _characters);
|
||||
}
|
||||
},
|
||||
TaskScheduler.FromCurrentSynchronizationContext());
|
||||
}
|
||||
|
||||
private string[] GetCharacters(LetterKey letterKey)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
{
|
||||
KeyboardListener::KeyboardListener() :
|
||||
m_toolbarVisible(false), m_activationKeyHold(false), m_triggeredWithSpace(false), m_leftShiftPressed(false), m_rightShiftPressed(false), m_triggeredWithLeftArrow(false), m_triggeredWithRightArrow(false)
|
||||
m_toolbarVisible(false), m_triggeredWithSpace(false), m_leftShiftPressed(false), m_rightShiftPressed(false), m_triggeredWithLeftArrow(false), m_triggeredWithRightArrow(false)
|
||||
{
|
||||
s_instance = this;
|
||||
LoggerHelpers::init_logger(L"PowerAccent", L"PowerAccentKeyboardService", "PowerAccent");
|
||||
@@ -53,8 +53,8 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
|
||||
void KeyboardListener::SetShowToolbarEvent(ShowToolbar showToolbarEvent)
|
||||
{
|
||||
m_showToolbarCb = [trigger = std::move(showToolbarEvent)](LetterKey key, TriggerKey triggerKey) {
|
||||
trigger(key, triggerKey);
|
||||
m_showToolbarCb = [trigger = std::move(showToolbarEvent)](LetterKey key) {
|
||||
trigger(key);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -152,17 +152,6 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
return false;
|
||||
}
|
||||
|
||||
void KeyboardListener::BeginShowToolbar(std::chrono::milliseconds delay, LetterKey key, TriggerKey trigger)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(toolbarMutex);
|
||||
auto result = toolbarCV.wait_for(lock, delay);
|
||||
if (result == std::cv_status::timeout)
|
||||
{
|
||||
m_toolbarVisible = true;
|
||||
m_showToolbarCb(key, trigger);
|
||||
}
|
||||
}
|
||||
|
||||
bool KeyboardListener::OnKeyDown(KBDLLHOOKSTRUCT info) noexcept
|
||||
{
|
||||
auto letterKey = static_cast<LetterKey>(info.vkCode);
|
||||
@@ -210,7 +199,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_toolbarVisible && !m_activationKeyHold && letterPressed != LetterKey::None && triggerPressed && !IsSuppressedByGameMode() && !IsForegroundAppExcluded())
|
||||
if (!m_toolbarVisible && letterPressed != LetterKey::None && triggerPressed && !IsSuppressedByGameMode() && !IsForegroundAppExcluded())
|
||||
{
|
||||
Logger::debug(L"Show toolbar. Letter: {}, Trigger: {}", letterPressed, triggerPressed);
|
||||
|
||||
@@ -218,21 +207,11 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
m_triggeredWithSpace = triggerPressed == VK_SPACE;
|
||||
m_triggeredWithLeftArrow = triggerPressed == VK_LEFT;
|
||||
m_triggeredWithRightArrow = triggerPressed == VK_RIGHT;
|
||||
m_activationKeyHold = true;
|
||||
m_bothKeysPressed = true;
|
||||
if (toolbarThread != nullptr)
|
||||
{
|
||||
toolbarCV.notify_all();
|
||||
toolbarThread->join();
|
||||
}
|
||||
toolbarThread = std::make_unique<std::thread>(std::bind(&KeyboardListener::BeginShowToolbar, this, m_settings.inputTime, letterPressed,static_cast<TriggerKey>(triggerPressed)));
|
||||
m_toolbarVisible = true;
|
||||
m_showToolbarCb(letterPressed);
|
||||
}
|
||||
|
||||
if (m_activationKeyHold && triggerPressed && !m_toolbarVisible)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (m_toolbarVisible && triggerPressed)
|
||||
if (m_toolbarVisible && triggerPressed)
|
||||
{
|
||||
if (triggerPressed == VK_LEFT)
|
||||
{
|
||||
@@ -272,9 +251,8 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
{
|
||||
letterPressed = LetterKey::None;
|
||||
|
||||
if (m_toolbarVisible || m_bothKeysPressed)
|
||||
if (m_toolbarVisible)
|
||||
{
|
||||
m_bothKeysPressed = false;
|
||||
if (m_stopwatch.elapsed() < m_settings.inputTime)
|
||||
{
|
||||
Logger::debug(L"Activation too fast. Do nothing.");
|
||||
@@ -302,18 +280,11 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
Logger::debug(L"Hide toolbar event and input char");
|
||||
|
||||
m_hideToolbarCb(InputType::Char);
|
||||
|
||||
m_toolbarVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
auto triggerPressed = info.vkCode;
|
||||
|
||||
if (m_activationKeyHold && (letterPressed == LetterKey::None || (triggerPressed == VK_SPACE || triggerPressed == VK_LEFT || triggerPressed == VK_RIGHT)))
|
||||
{
|
||||
m_activationKeyHold = false;
|
||||
toolbarCV.notify_all();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "KeyboardListener.g.h"
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <spdlog/stopwatch.h>
|
||||
|
||||
namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
@@ -45,7 +44,6 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
private:
|
||||
void BeginShowToolbar(std::chrono::milliseconds delay, LetterKey key, TriggerKey trigger);
|
||||
bool OnKeyDown(KBDLLHOOKSTRUCT info) noexcept;
|
||||
bool OnKeyUp(KBDLLHOOKSTRUCT info) noexcept;
|
||||
bool IsSuppressedByGameMode();
|
||||
@@ -53,14 +51,9 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
|
||||
static inline KeyboardListener* s_instance;
|
||||
HHOOK s_llKeyboardHook = nullptr;
|
||||
std::atomic<bool> m_toolbarVisible;
|
||||
bool m_activationKeyHold;
|
||||
bool m_bothKeysPressed = false;
|
||||
std::unique_ptr<std::thread> toolbarThread;
|
||||
std::mutex toolbarMutex;
|
||||
std::condition_variable toolbarCV;
|
||||
bool m_toolbarVisible;
|
||||
PowerAccentSettings m_settings;
|
||||
std::function<void(LetterKey, TriggerKey)> m_showToolbarCb;
|
||||
std::function<void(LetterKey)> m_showToolbarCb;
|
||||
std::function<void(InputType)> m_hideToolbarCb;
|
||||
std::function<void(TriggerKey, bool)> m_nextCharCb;
|
||||
std::function<bool(LetterKey)> m_isLanguageLetterCb;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace PowerToys
|
||||
Char
|
||||
};
|
||||
|
||||
[version(1.0), uuid(37197089-5438-4479-af57-30ab3f3c8be4)] delegate void ShowToolbar(LetterKey key, TriggerKey trigger);
|
||||
[version(1.0), uuid(37197089-5438-4479-af57-30ab3f3c8be4)] delegate void ShowToolbar(LetterKey key);
|
||||
[version(1.0), uuid(8eb79d6b-1826-424f-9fbc-af21ae19725e)] delegate void HideToolbar(InputType inputType);
|
||||
[version(1.0), uuid(db72d45c-a5a2-446f-bdc1-506e9121764a)] delegate void NextChar(TriggerKey inputSpace, boolean shiftPressed);
|
||||
[version(1.0), uuid(20be2919-2b91-4313-b6e0-4c3484fe91ef)] delegate void IsLanguageLetter(LetterKey key, [out] boolean* result);
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
ViewModel.RefreshEnabledState();
|
||||
}
|
||||
|
||||
private void LaunchApp(string appPath)
|
||||
private void LaunchApp(string appPath, string args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -43,7 +43,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
var processStartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = appPath,
|
||||
Arguments = string.Empty,
|
||||
Arguments = args,
|
||||
WorkingDirectory = dir,
|
||||
UseShellExecute = true,
|
||||
Verb = "open",
|
||||
@@ -64,9 +64,10 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
|
||||
private void CmdPalSettingsDeeplink_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
{
|
||||
// Launch CmdPal settings window
|
||||
string launchPath = "x-cmdpal://settings";
|
||||
LaunchApp(launchPath);
|
||||
// Launch CmdPal settings window as normal user using explorer
|
||||
string launchPath = "explorer.exe";
|
||||
string launchArgs = "x-cmdpal://settings";
|
||||
LaunchApp(launchPath, launchArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user