mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[BugReport]Fix hang when bug report is launched (#28506)
* fix hang when bug report is launched from flyout * Normalize output dir for release
This commit is contained in:
committed by
GitHub
parent
51906e68a4
commit
b8a83fba1b
33
src/runner/bug_report.cpp
Normal file
33
src/runner/bug_report.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "pch.h"
|
||||
#include "bug_report.h"
|
||||
#include "Generated files/resource.h"
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/resources.h>
|
||||
|
||||
std::atomic_bool isBugReportThreadRunning = false;
|
||||
|
||||
void launch_bug_report() noexcept
|
||||
{
|
||||
std::wstring bug_report_path = get_module_folderpath();
|
||||
bug_report_path += L"\\Tools\\PowerToys.BugReportTool.exe";
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
3
src/runner/bug_report.h
Normal file
3
src/runner/bug_report.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void launch_bug_report() noexcept;
|
||||
@@ -48,6 +48,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\common\interop\two_way_pipe_message_ipc.cpp" />
|
||||
<ClCompile Include="auto_start_helper.cpp" />
|
||||
<ClCompile Include="bug_report.cpp" />
|
||||
<ClCompile Include="centralized_hotkeys.cpp" />
|
||||
<ClCompile Include="general_settings.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
@@ -67,6 +68,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ActionRunnerUtils.h" />
|
||||
<ClInclude Include="auto_start_helper.h" />
|
||||
<ClInclude Include="bug_report.h" />
|
||||
<ClInclude Include="centralized_hotkeys.h" />
|
||||
<ClInclude Include="general_settings.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
<ClCompile Include="centralized_hotkeys.cpp">
|
||||
<Filter>Utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bug_report.cpp">
|
||||
<Filter>Utils</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
@@ -87,6 +90,9 @@
|
||||
<ClInclude Include="centralized_hotkeys.h">
|
||||
<Filter>Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bug_report.h">
|
||||
<Filter>Utils</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Utils">
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <common/updating/updateState.h>
|
||||
#include <common/themes/windows_colors.h>
|
||||
#include "settings_window.h"
|
||||
#include "bug_report.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
@@ -108,7 +109,7 @@ std::optional<std::wstring> dispatch_json_action_to_module(const json::JsonObjec
|
||||
else if (action == L"check_for_updates")
|
||||
{
|
||||
bool expected_isUpdateCheckThreadRunning = false;
|
||||
if (isUpdateCheckThreadRunning.compare_exchange_strong(expected_isUpdateCheckThreadRunning,true))
|
||||
if (isUpdateCheckThreadRunning.compare_exchange_strong(expected_isUpdateCheckThreadRunning, true))
|
||||
{
|
||||
std::thread([]() {
|
||||
CheckForUpdatesCallback();
|
||||
@@ -222,19 +223,7 @@ void dispatch_received_json(const std::wstring& json_to_parse)
|
||||
}
|
||||
else if (name == L"bugreport")
|
||||
{
|
||||
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);
|
||||
}
|
||||
launch_bug_report();
|
||||
}
|
||||
else if (name == L"killrunner")
|
||||
{
|
||||
@@ -410,18 +399,18 @@ void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::op
|
||||
PTSettingsHelper::save_general_settings(save_settings.to_json());
|
||||
|
||||
std::wstring executable_args = fmt::format(L"\"{}\" {} {} {} {} {} {} {} {} {} {} {}",
|
||||
executable_path,
|
||||
powertoys_pipe_name,
|
||||
settings_pipe_name,
|
||||
std::to_wstring(powertoys_pid),
|
||||
settings_theme,
|
||||
settings_elevatedStatus,
|
||||
settings_isUserAnAdmin,
|
||||
settings_showOobe,
|
||||
settings_showScoobe,
|
||||
settings_showFlyout,
|
||||
settings_containsSettingsWindow,
|
||||
settings_containsFlyoutPosition);
|
||||
executable_path,
|
||||
powertoys_pipe_name,
|
||||
settings_pipe_name,
|
||||
std::to_wstring(powertoys_pid),
|
||||
settings_theme,
|
||||
settings_elevatedStatus,
|
||||
settings_isUserAnAdmin,
|
||||
settings_showOobe,
|
||||
settings_showScoobe,
|
||||
settings_showFlyout,
|
||||
settings_containsSettingsWindow,
|
||||
settings_containsFlyoutPosition);
|
||||
|
||||
if (settings_window.has_value())
|
||||
{
|
||||
|
||||
@@ -6,17 +6,18 @@
|
||||
#include "centralized_kb_hook.h"
|
||||
#include <Windows.h>
|
||||
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/resources.h>
|
||||
#include <common/version/version.h>
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/elevation.h>
|
||||
#include "bug_report.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
HWND tray_icon_hwnd = NULL;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
wm_icon_notify = WM_APP,
|
||||
wm_run_on_main_ui_thread,
|
||||
};
|
||||
@@ -44,8 +45,6 @@ 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)
|
||||
@@ -74,11 +73,11 @@ void handle_tray_command(HWND window, const WPARAM command_id, LPARAM lparam)
|
||||
switch (command_id)
|
||||
{
|
||||
case ID_SETTINGS_MENU_COMMAND:
|
||||
{
|
||||
std::wstring settings_window{ winrt::to_hstring(ESettingsWindowNames_to_string(static_cast<ESettingsWindowNames>(lparam))) };
|
||||
open_settings_window(settings_window, false);
|
||||
}
|
||||
break;
|
||||
{
|
||||
std::wstring settings_window{ winrt::to_hstring(ESettingsWindowNames_to_string(static_cast<ESettingsWindowNames>(lparam))) };
|
||||
open_settings_window(settings_window, false);
|
||||
}
|
||||
break;
|
||||
case ID_EXIT_MENU_COMMAND:
|
||||
if (h_menu)
|
||||
{
|
||||
@@ -97,29 +96,7 @@ void handle_tray_command(HWND window, const WPARAM command_id, LPARAM lparam)
|
||||
break;
|
||||
case ID_REPORT_BUG_COMMAND:
|
||||
{
|
||||
std::wstring bug_report_path = get_module_folderpath();
|
||||
bug_report_path += L"\\Tools\\PowerToys.BugReportTool.exe";
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
launch_bug_report();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -230,7 +207,7 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
|
||||
// start timer for detecting single or double click
|
||||
double_click_timer_running = true;
|
||||
double_clicked = false;
|
||||
|
||||
|
||||
UINT doubleClickTime = GetDoubleClickTime();
|
||||
std::thread([doubleClickTime]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(doubleClickTime));
|
||||
|
||||
@@ -13,6 +13,7 @@ using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using WinUIEx;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Flyout
|
||||
{
|
||||
@@ -141,6 +142,9 @@ namespace Microsoft.PowerToys.Settings.UI.Flyout
|
||||
private void ReportBugBtn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ViewModel.StartBugReport();
|
||||
|
||||
// Closing manually the flyout since no window will steal the focus
|
||||
App.GetFlyoutWindow()?.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user