Skip to content

Commit

Permalink
[runner] bug report could be created from tray (#9191)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyoyuppe committed Jan 21, 2021
1 parent a0faf4c commit da6fc54
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
12 changes: 4 additions & 8 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ appxmanifest
APSTUDIO
AQS
arcosh
arsinh
artanh
ARemapped
argb
argc
Expand All @@ -100,6 +98,8 @@ arjunbalgovind
ARPINSTALLLOCATION
ARPPRODUCTICON
ARRAYSIZE
arsinh
artanh
Artboard
asdf
AShortcut
Expand All @@ -119,7 +119,6 @@ atlfile
atlstr
attr
Attribs
AUMID
aumid
AUTHN
AUTOAPPEND
Expand Down Expand Up @@ -195,6 +194,7 @@ BTNFACE
Bto
buf
BUFSIZE
bugreport
Buid
buildcommand
buildtools
Expand Down Expand Up @@ -469,7 +469,6 @@ DISPIDAMBIENTDLCONTROL
DISPINFO
Displayandhidethedesktop
DISPLAYCHANGE
DISPLAYNAME
displayname
divyan
DLACTIVEXCTLS
Expand Down Expand Up @@ -862,7 +861,6 @@ HLSL
hmenu
hmodule
hmon
HMONITOR
hmonitor
HOLDENTER
HOLDESC
Expand Down Expand Up @@ -981,7 +979,6 @@ IJson
IList
ILogon
IMAGEHLP
IMAGENAME
imageresizer
IMAGERESIZEREXT
imageresizersettings
Expand Down Expand Up @@ -1852,7 +1849,7 @@ RUNLEVEL
runsettings
runtimeclass
runtimeconfig
Runtimes
runtimes
rv
rvalue
rvm
Expand Down Expand Up @@ -2492,7 +2489,6 @@ XOffset
xpath
XResource
xsd
xsi
XSmall
XStr
XToolset
Expand Down
6 changes: 6 additions & 0 deletions src/runner/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
<value>Exit</value>
<comment>Exit as a verb, as in Exit the application</comment>
</data>
<data name="SUBMIT_BUG_TEXT" xml:space="preserve">
<value>Report Bug</value>
</data>
<data name="BUGREPORT_SUCCESS" xml:space="preserve">
<value>Bug report .zip file has been created on your Desktop.</value>
</data>
<data name="GITHUB_NEW_VERSION_USING_LOCAL_BUILD_ERROR" xml:space="preserve">
<value>Updating from a local build is not supported.</value>
<comment>User cannot autoupdate from a locally-built PowerToys version</comment>
Expand Down
3 changes: 2 additions & 1 deletion src/runner/resource.base.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

#define ID_EXIT_MENU_COMMAND 40001
#define ID_SETTINGS_MENU_COMMAND 40002
#define ID_ABOUT_MENU_COMMAND 40003
#define ID_ABOUT_MENU_COMMAND 40003
#define ID_REPORT_BUG_COMMAND 40004
Binary file modified src/runner/runner.base.rc
Binary file not shown.
69 changes: 47 additions & 22 deletions src/runner/tray_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "tray_icon.h"
#include <Windows.h>

#include <common/utils/process_path.h>
#include <common/utils/resources.h>
#include <common/version/version.h>

Expand Down Expand Up @@ -57,6 +58,48 @@ void change_menu_item_text(const UINT item_id, wchar_t* new_text)
SetMenuItemInfoW(h_menu, item_id, false, &menuitem);
}

void handle_tray_command(HWND window, const WPARAM command_id)
{
switch (command_id)
{
case ID_SETTINGS_MENU_COMMAND:
open_settings_window();
break;
case ID_EXIT_MENU_COMMAND:
if (h_menu)
{
DestroyMenu(h_menu);
}
DestroyWindow(window);
break;
case ID_ABOUT_MENU_COMMAND:
if (!about_box_shown)
{
about_box_shown = true;
std::wstring about_msg = L"PowerToys\nVersion " + get_product_version() + L"\n\xa9 2019 Microsoft Corporation";
MessageBoxW(nullptr, about_msg.c_str(), L"About PowerToys", MB_OK);
about_box_shown = false;
}
break;
case ID_REPORT_BUG_COMMAND:
std::wstring bug_report_path = get_module_folderpath();
bug_report_path += L"\\Tools\\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);
}

break;
}
}

LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message)
Expand All @@ -82,28 +125,7 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
DestroyWindow(window);
break;
case WM_COMMAND:
switch (wparam)
{
case ID_SETTINGS_MENU_COMMAND:
open_settings_window();
break;
case ID_EXIT_MENU_COMMAND:
if (h_menu)
{
DestroyMenu(h_menu);
}
DestroyWindow(window);
break;
case ID_ABOUT_MENU_COMMAND:
if (!about_box_shown)
{
about_box_shown = true;
std::wstring about_msg = L"PowerToys\nVersion " + get_product_version() + L"\n\xa9 2019 Microsoft Corporation";
MessageBox(nullptr, about_msg.c_str(), L"About PowerToys", MB_OK);
about_box_shown = false;
}
break;
}
handle_tray_command(window, wparam);
break;
// Shell_NotifyIcon can fail when we invoke it during the time explorer.exe isn't present/ready to handle it.
// We'll also never receive wm_taskbar_restart message if the first call to Shell_NotifyIcon failed, so we use
Expand Down Expand Up @@ -137,8 +159,11 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
{
static std::wstring settings_menuitem_label = GET_RESOURCE_STRING(IDS_SETTINGS_MENU_TEXT);
static std::wstring exit_menuitem_label = GET_RESOURCE_STRING(IDS_EXIT_MENU_TEXT);
static std::wstring submit_bug_menuitem_label = GET_RESOURCE_STRING(IDS_SUBMIT_BUG_TEXT);

change_menu_item_text(ID_SETTINGS_MENU_COMMAND, settings_menuitem_label.data());
change_menu_item_text(ID_EXIT_MENU_COMMAND, exit_menuitem_label.data());
change_menu_item_text(ID_REPORT_BUG_COMMAND, submit_bug_menuitem_label.data());
}
if (!h_sub_menu)
{
Expand Down

0 comments on commit da6fc54

Please sign in to comment.