mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-22 22:50:03 +01:00
FZ: warn w/ a toast if an elevated window cannot be dragged and offer learning more
This commit is contained in:
committed by
Andrey Nekrasov
parent
c2e219b446
commit
60fa6071b9
@@ -25,6 +25,7 @@
|
||||
#if _DEBUG && _WIN64
|
||||
#include "unhandled_exception_handler.h"
|
||||
#endif
|
||||
#include <common/notifications/fancyzones_notifications.h>
|
||||
|
||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
@@ -39,6 +40,8 @@ namespace
|
||||
{
|
||||
const wchar_t MSI_VERSION_MUTEX_NAME[] = L"Local\\PowerToyRunMutex";
|
||||
const wchar_t MSIX_VERSION_MUTEX_NAME[] = L"Local\\PowerToyMSIXRunMutex";
|
||||
|
||||
const wchar_t PT_URI_PROTOCOL_SCHEME[] = L"powertoys://";
|
||||
}
|
||||
|
||||
void chdir_current_executable()
|
||||
@@ -116,7 +119,7 @@ std::future<void> check_github_updates()
|
||||
std::wstring contents = GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
||||
contents += new_version->version_string;
|
||||
contents += L'.';
|
||||
notifications::show_toast_with_activations(contents, {}, { notifications::link_button{ GITHUB_NEW_VERSION_AGREE, new_version->release_page_uri.ToString() } });
|
||||
notifications::show_toast_with_activations(std::move(contents), {}, { notifications::link_button{ GITHUB_NEW_VERSION_AGREE, new_version->release_page_uri.ToString().c_str() } });
|
||||
}
|
||||
|
||||
void github_update_checking_worker()
|
||||
@@ -228,17 +231,22 @@ int runner(bool isProcessElevated)
|
||||
enum class SpecialMode
|
||||
{
|
||||
None,
|
||||
Win32ToastNotificationCOMServer
|
||||
Win32ToastNotificationCOMServer,
|
||||
ToastNotificationHandler
|
||||
};
|
||||
|
||||
SpecialMode should_run_in_special_mode()
|
||||
SpecialMode should_run_in_special_mode(const int n_cmd_args, LPWSTR* cmd_arg_list)
|
||||
{
|
||||
int nArgs;
|
||||
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
|
||||
for (size_t i = 1; i < nArgs; ++i)
|
||||
for (size_t i = 1; i < n_cmd_args; ++i)
|
||||
{
|
||||
if (!wcscmp(notifications::TOAST_ACTIVATED_LAUNCH_ARG, szArglist[i]))
|
||||
if (!wcscmp(notifications::TOAST_ACTIVATED_LAUNCH_ARG, cmd_arg_list[i]))
|
||||
{
|
||||
return SpecialMode::Win32ToastNotificationCOMServer;
|
||||
}
|
||||
else if (n_cmd_args == 2 && !wcsncmp(PT_URI_PROTOCOL_SCHEME, cmd_arg_list[i], wcslen(PT_URI_PROTOCOL_SCHEME)))
|
||||
{
|
||||
return SpecialMode::ToastNotificationHandler;
|
||||
}
|
||||
}
|
||||
|
||||
return SpecialMode::None;
|
||||
@@ -250,14 +258,42 @@ int win32_toast_notification_COM_server_mode()
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum class toast_notification_handler_result
|
||||
{
|
||||
exit_success,
|
||||
exit_error
|
||||
};
|
||||
|
||||
toast_notification_handler_result toast_notification_handler(const std::wstring_view param)
|
||||
{
|
||||
if (param == L"cant_drag_elevated_disable/")
|
||||
{
|
||||
return disable_cant_drag_elevated_warning() ? toast_notification_handler_result::exit_success : toast_notification_handler_result::exit_error;
|
||||
}
|
||||
else
|
||||
{
|
||||
return toast_notification_handler_result::exit_error;
|
||||
}
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
winrt::init_apartment();
|
||||
|
||||
switch (should_run_in_special_mode())
|
||||
int n_cmd_args = 0;
|
||||
LPWSTR* cmd_arg_list = CommandLineToArgvW(GetCommandLineW(), &n_cmd_args);
|
||||
switch (should_run_in_special_mode(n_cmd_args, cmd_arg_list))
|
||||
{
|
||||
case SpecialMode::Win32ToastNotificationCOMServer:
|
||||
return win32_toast_notification_COM_server_mode();
|
||||
case SpecialMode::ToastNotificationHandler:
|
||||
switch (toast_notification_handler(cmd_arg_list[1] + wcslen(PT_URI_PROTOCOL_SCHEME)))
|
||||
{
|
||||
case toast_notification_handler_result::exit_error:
|
||||
return 1;
|
||||
case toast_notification_handler_result::exit_success:
|
||||
return 0;
|
||||
}
|
||||
case SpecialMode::None:
|
||||
// continue as usual
|
||||
break;
|
||||
@@ -339,12 +375,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
auto general_settings = load_general_settings();
|
||||
int rvalue = 0;
|
||||
bool isProcessElevated = is_process_elevated();
|
||||
if (isProcessElevated ||
|
||||
general_settings.GetNamedBoolean(L"run_elevated", false) == false ||
|
||||
strcmp(lpCmdLine, "--dont-elevate") == 0)
|
||||
const bool elevated = is_process_elevated();
|
||||
if ((elevated ||
|
||||
general_settings.GetNamedBoolean(L"run_elevated", false) == false ||
|
||||
strcmp(lpCmdLine, "--dont-elevate") == 0))
|
||||
{
|
||||
result = runner(isProcessElevated);
|
||||
result = runner(elevated);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user