mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
[Runner]Check for updates and bug report on background thread (#25978)
* [Runner] CheckForUpdatesCallback function and ID_REPORT_BUG_COMMAND case in tray_icon moved to threads. * [Runner] Bool flag added to bug report thread. * [Runner] Bool flag added to CheckForUpdatesCallback thread. * [Runner] Review comments added. Uncessary mutex removed. compare_exchange_strong is used for atomic_bool variable checks.
This commit is contained in:
@@ -276,6 +276,7 @@ void CheckForUpdatesCallback()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProcessNewVersionInfo(*new_version_info, state, download_update, false);
|
ProcessNewVersionInfo(*new_version_info, state, download_update, false);
|
||||||
|
|
||||||
UpdateState::store([&](UpdateState& v) {
|
UpdateState::store([&](UpdateState& v) {
|
||||||
v = std::move(state);
|
v = std::move(state);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
TwoWayPipeMessageIPC* current_settings_ipc = NULL;
|
TwoWayPipeMessageIPC* current_settings_ipc = NULL;
|
||||||
std::mutex ipc_mutex;
|
std::mutex ipc_mutex;
|
||||||
std::atomic_bool g_isLaunchInProgress = false;
|
std::atomic_bool g_isLaunchInProgress = false;
|
||||||
|
std::atomic_bool isUpdateCheckThreadRunning = false;
|
||||||
|
|
||||||
json::JsonObject get_power_toys_settings()
|
json::JsonObject get_power_toys_settings()
|
||||||
{
|
{
|
||||||
@@ -106,7 +107,14 @@ std::optional<std::wstring> dispatch_json_action_to_module(const json::JsonObjec
|
|||||||
}
|
}
|
||||||
else if (action == L"check_for_updates")
|
else if (action == L"check_for_updates")
|
||||||
{
|
{
|
||||||
CheckForUpdatesCallback();
|
bool expected_isUpdateCheckThreadRunning = false;
|
||||||
|
if (isUpdateCheckThreadRunning.compare_exchange_strong(expected_isUpdateCheckThreadRunning,true))
|
||||||
|
{
|
||||||
|
std::thread([]() {
|
||||||
|
CheckForUpdatesCallback();
|
||||||
|
isUpdateCheckThreadRunning.store(false);
|
||||||
|
}).detach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (action == L"request_update_state_date")
|
else if (action == L"request_update_state_date")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ struct run_on_main_ui_thread_msg
|
|||||||
PVOID data;
|
PVOID data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::atomic_bool isBugReportThreadRunning = false;
|
||||||
|
|
||||||
bool dispatch_run_on_main_ui_thread(main_loop_callback_function _callback, PVOID data)
|
bool dispatch_run_on_main_ui_thread(main_loop_callback_function _callback, PVOID data)
|
||||||
{
|
{
|
||||||
if (tray_icon_hwnd == NULL)
|
if (tray_icon_hwnd == NULL)
|
||||||
@@ -96,16 +98,25 @@ void handle_tray_command(HWND window, const WPARAM command_id, LPARAM lparam)
|
|||||||
{
|
{
|
||||||
std::wstring bug_report_path = get_module_folderpath();
|
std::wstring bug_report_path = get_module_folderpath();
|
||||||
bug_report_path += L"\\Tools\\PowerToys.BugReportTool.exe";
|
bug_report_path += L"\\Tools\\PowerToys.BugReportTool.exe";
|
||||||
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
|
||||||
sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE };
|
bool expected_isBugReportThreadRunning = false;
|
||||||
sei.lpFile = bug_report_path.c_str();
|
if (isBugReportThreadRunning.compare_exchange_strong(expected_isBugReportThreadRunning, true))
|
||||||
sei.nShow = SW_HIDE;
|
{
|
||||||
if (ShellExecuteExW(&sei))
|
std::thread([bug_report_path]() {
|
||||||
{
|
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
||||||
WaitForSingleObject(sei.hProcess, INFINITE);
|
sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE };
|
||||||
CloseHandle(sei.hProcess);
|
sei.lpFile = bug_report_path.c_str();
|
||||||
static const std::wstring bugreport_success = GET_RESOURCE_STRING(IDS_BUGREPORT_SUCCESS);
|
sei.nShow = SW_HIDE;
|
||||||
MessageBoxW(nullptr, bugreport_success.c_str(), L"PowerToys", MB_OK);
|
if (ShellExecuteExW(&sei))
|
||||||
|
{
|
||||||
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
||||||
|
CloseHandle(sei.hProcess);
|
||||||
|
static const std::wstring bugreport_success = GET_RESOURCE_STRING(IDS_BUGREPORT_SUCCESS);
|
||||||
|
MessageBoxW(nullptr, bugreport_success.c_str(), L"PowerToys", MB_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
isBugReportThreadRunning.store(false);
|
||||||
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user