[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:
gokcekantarci 2023-06-05 13:42:06 +03:00 committed by GitHub
parent 0f6305f5fa
commit 4d5152f78a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 11 deletions

View File

@ -276,6 +276,7 @@ void CheckForUpdatesCallback()
}
ProcessNewVersionInfo(*new_version_info, state, download_update, false);
UpdateState::store([&](UpdateState& v) {
v = std::move(state);
});

View File

@ -32,6 +32,7 @@
TwoWayPipeMessageIPC* current_settings_ipc = NULL;
std::mutex ipc_mutex;
std::atomic_bool g_isLaunchInProgress = false;
std::atomic_bool isUpdateCheckThreadRunning = false;
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")
{
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")
{

View File

@ -43,6 +43,8 @@ struct run_on_main_ui_thread_msg
PVOID data;
};
std::atomic_bool isBugReportThreadRunning = false;
bool dispatch_run_on_main_ui_thread(main_loop_callback_function _callback, PVOID data)
{
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();
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 };
sei.lpFile = bug_report_path.c_str();
sei.nShow = SW_HIDE;
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);
bool expected_isBugReportThreadRunning = false;
if (isBugReportThreadRunning.compare_exchange_strong(expected_isBugReportThreadRunning, true))
{
std::thread([bug_report_path]() {
SHELLEXECUTEINFOW sei{ sizeof(sei) };
sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE };
sei.lpFile = bug_report_path.c_str();
sei.nShow = SW_HIDE;
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;