mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Fix Cmdpal launch without admin mode - both runner and setting. (#39494)
* Change to path and args * Fix both Setting launch and runner launch
This commit is contained in:
@@ -217,7 +217,9 @@ public:
|
|||||||
CmdPal::m_enabled.store(true);
|
CmdPal::m_enabled.store(true);
|
||||||
|
|
||||||
std::wstring packageName = L"Microsoft.CommandPalette";
|
std::wstring packageName = L"Microsoft.CommandPalette";
|
||||||
std::wstring launchPath = L"explorer.exe 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
|
#ifdef IS_DEV_BRANDING
|
||||||
packageName = L"Microsoft.CommandPalette.Dev";
|
packageName = L"Microsoft.CommandPalette.Dev";
|
||||||
#endif
|
#endif
|
||||||
@@ -268,13 +270,13 @@ public:
|
|||||||
if (!firstEnableCall)
|
if (!firstEnableCall)
|
||||||
{
|
{
|
||||||
Logger::trace("Not first attempt, try to launch");
|
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
|
else
|
||||||
{
|
{
|
||||||
// If first time enable, do retry launch.
|
// If first time enable, do retry launch.
|
||||||
Logger::trace("First attempt, try to launch");
|
Logger::trace("First attempt, try to launch");
|
||||||
std::thread launchThread(&CmdPal::RetryLaunch, launchPath);
|
std::thread launchThread(&CmdPal::RetryLaunch, launchPath, launchArgs);
|
||||||
launchThread.detach();
|
launchThread.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,14 +291,14 @@ public:
|
|||||||
CmdPal::m_enabled.store(false);
|
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;
|
const int base_delay_milliseconds = 1000;
|
||||||
int max_retry = 9; // 2**9 - 1 seconds. Control total wait time within 10 min.
|
int max_retry = 9; // 2**9 - 1 seconds. Control total wait time within 10 min.
|
||||||
int retry = 0;
|
int retry = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
auto launch_result = LaunchApp(path, L"", false, retry < max_retry);
|
auto launch_result = LaunchApp(path, cmdArgs, false, retry < max_retry);
|
||||||
if (launch_result)
|
if (launch_result)
|
||||||
{
|
{
|
||||||
Logger::info(L"CmdPal launched successfully after {} retries.", retry);
|
Logger::info(L"CmdPal launched successfully after {} retries.", retry);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
ViewModel.RefreshEnabledState();
|
ViewModel.RefreshEnabledState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LaunchApp(string appPath)
|
private void LaunchApp(string appPath, string args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -43,7 +43,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
var processStartInfo = new ProcessStartInfo
|
var processStartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = appPath,
|
FileName = appPath,
|
||||||
Arguments = string.Empty,
|
Arguments = args,
|
||||||
WorkingDirectory = dir,
|
WorkingDirectory = dir,
|
||||||
UseShellExecute = true,
|
UseShellExecute = true,
|
||||||
Verb = "open",
|
Verb = "open",
|
||||||
@@ -64,9 +64,10 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
|
|
||||||
private void CmdPalSettingsDeeplink_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
private void CmdPalSettingsDeeplink_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// Launch CmdPal settings window
|
// Launch CmdPal settings window as normal user using explorer
|
||||||
string launchPath = "x-cmdpal://settings";
|
string launchPath = "explorer.exe";
|
||||||
LaunchApp(launchPath);
|
string launchArgs = "x-cmdpal://settings";
|
||||||
|
LaunchApp(launchPath, launchArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user