Skip to content

Commit

Permalink
[Settings][runner]Quick access system tray launcher (#22408)
Browse files Browse the repository at this point in the history
* Init

* Fix running settings

* UI design

* Left click trigger
Wire up colorpicker and pt run

* Wire up others

* Update FlyoutWindow.xaml.cs

* Removed comments

* Update FlyoutWindow.xaml

* More work

* Open Settings page

* More UI work

* Resolve conflicts

* [General] SystemTray Flyout: Add update on tray items' visibility when module gets enabled/disabled
Also remove context menu opening on tray icon.

* Adding app list

* Adding more buttons, resolving conflicts

* [General] Flyout: improving opening, closing flyout/settings window. Implementing basic bahaviour on enabling/disabling modules.

* [General] FlyoutWindow: proceed with implementation. GPO works. Main functionallity works (launching and enabling apps).

* [general] flyout: fix exit button

* [general] flyout: implement double click handling

* Localization

* [Generel] Flyout: Re-implement flyout launching, add workaround: disable flyout hiding in case the user switches on modules on the all apps page
+ minor changes

* [general] flyout: restore the context menu when right clicking on system tray icon

* Fix spellchecker

* [installer] fixing missing dll files + suppress error on not signed script

* Fix spell checker

* Fix flyout not focusing when activated

* Refresh Settings UI enabled state when flyout changes

* fix spellcheck

* Remove VCM from the list

* [General] flyout: fix settings window opening. Switch to general page only if there is no page opened

* [general] flyout: add launching hosts app

* Fix CI build

* adding check on elevation when launching hosts

* Use localization strings that already exist

* Remove dll not present in arm64 build

* Adding GPO policy check for the launcher page items

* fix hosts launching

* Add telemetry

* Also hide from all apps list when gpo is force enabling

* fix spellchecker

* Improve focus issues

* Fix flickering Bitmap Icons

* Fix telemetry error

* Fix telemetry call

* Fix wrong comment

---------

Co-authored-by: Stefan Markovic <[email protected]>
Co-authored-by: Laszlo Nemeth <[email protected]>
Co-authored-by: Jaime Bernardo <[email protected]>
  • Loading branch information
4 people authored Jan 30, 2023
1 parent fb2b150 commit c1c14b4
Show file tree
Hide file tree
Showing 79 changed files with 2,881 additions and 426 deletions.
1 change: 1 addition & 0 deletions .github/actions/spell-check/excludes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
^\Q.pipelines/ESRPSigning_core.json\E$
^\Qsrc/modules/colorPicker/ColorPickerUI/Shaders/GridShader.cso\E$
^\Qsrc/common/ManagedCommon/ColorFormatHelper.cs\E$
^\Qinstaller/PowerToysSetup/Settings.wxs\E$
^\Qsrc/settings-ui/Settings.UI.UnitTests/BackwardsCompatibility/TestFiles/CorruptJson/Microsoft/PowerToys/settings.json\E$
^\Qsrc/settings-ui/Settings.UI.UnitTests/BackwardsCompatibility/TestFiles/v0.18.2/Microsoft/PowerToys/PowerRename/power-rename-ui-flags\E$
^\Qsrc/settings-ui/Settings.UI.UnitTests/BackwardsCompatibility/TestFiles/v0.19.2/Microsoft/PowerToys/PowerRename/power-rename-ui-flags\E$
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ CHILDACTIVATE
CHILDWINDOW
Choibalsan
chrdavis
chromaticities
Chrzan
cht
Chukotka
Expand Down Expand Up @@ -848,6 +849,7 @@ Khakassia
Khanty
Khovd
KILLFOCUS
killrunner
Kitts
Knownfolders
Krai
Expand Down Expand Up @@ -1446,6 +1448,7 @@ reencoded
REFCLSID
REFGUID
REFIID
Refreshable
REGCLS
regedit
regfile
Expand Down
2 changes: 1 addition & 1 deletion installer/PowerToysSetup/Settings.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<?include $(sys.CURRENTDIR)\Common.wxi?>

<?define SettingsV2Files=backup_restore_settings.json;Ijwhost.dll;ColorCode.Core.dll;ColorCode.WinUI.dll;CommunityToolkit.Common.dll;CommunityToolkit.Labs.WinUI.SettingsControls.dll;CommunityToolkit.WinUI.dll;CommunityToolkit.WinUI.UI.Controls.Core.dll;CommunityToolkit.WinUI.UI.Controls.DataGrid.dll;CommunityToolkit.WinUI.UI.Controls.Input.dll;CommunityToolkit.WinUI.UI.Controls.Layout.dll;CommunityToolkit.WinUI.UI.Controls.Markdown.dll;CommunityToolkit.WinUI.UI.Controls.Media.dll;CommunityToolkit.WinUI.UI.Controls.Primitives.dll;CommunityToolkit.WinUI.UI.dll;icon.ico;Microsoft.Graphics.Canvas.Interop.dll;Microsoft.InteractiveExperiences.Projection.dll;Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll;Microsoft.Windows.ApplicationModel.Resources.Projection.dll;Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll;Microsoft.Windows.AppLifecycle.Projection.dll;Microsoft.Windows.SDK.NET.dll;Microsoft.Windows.System.Power.Projection.dll;Microsoft.WindowsAppRuntime.Bootstrap.Net.dll;Microsoft.WinUI.dll;Microsoft.Xaml.Interactions.dll;Microsoft.Xaml.Interactivity.dll;PowerToys.ManagedCommon.dll;PowerToys.ManagedTelemetry.dll;PowerToys.Settings.deps.json;PowerToys.Settings.dll;PowerToys.Settings.exe;PowerToys.Settings.runtimeconfig.json;PowerToys.Settings.UI.Lib.dll;resources.pri;System.CodeDom.dll;System.IO.Abstractions.dll;WinRT.Runtime.dll;Microsoft.Graphics.Canvas.dll;System.Management.dll;PowerToys.GPOWrapper.dll;System.Text.Json.dll;WindowsBase.dll?>
<?define SettingsV2Files=WinUIEx.dll;backup_restore_settings.json;Ijwhost.dll;ColorCode.Core.dll;ColorCode.WinUI.dll;CommunityToolkit.Common.dll;CommunityToolkit.Labs.WinUI.SettingsControls.dll;CommunityToolkit.WinUI.dll;CommunityToolkit.WinUI.UI.Controls.Core.dll;CommunityToolkit.WinUI.UI.Controls.DataGrid.dll;CommunityToolkit.WinUI.UI.Controls.Input.dll;CommunityToolkit.WinUI.UI.Controls.Layout.dll;CommunityToolkit.WinUI.UI.Controls.Markdown.dll;CommunityToolkit.WinUI.UI.Controls.Media.dll;CommunityToolkit.WinUI.UI.Controls.Primitives.dll;CommunityToolkit.WinUI.UI.dll;icon.ico;Microsoft.Graphics.Canvas.Interop.dll;Microsoft.InteractiveExperiences.Projection.dll;Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll;Microsoft.Windows.ApplicationModel.Resources.Projection.dll;Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll;Microsoft.Windows.AppLifecycle.Projection.dll;Microsoft.Windows.SDK.NET.dll;Microsoft.Windows.System.Power.Projection.dll;Microsoft.WindowsAppRuntime.Bootstrap.Net.dll;Microsoft.WinUI.dll;Microsoft.Xaml.Interactions.dll;Microsoft.Xaml.Interactivity.dll;PowerToys.ManagedCommon.dll;PowerToys.ManagedTelemetry.dll;PowerToys.Settings.deps.json;PowerToys.Settings.dll;PowerToys.Settings.exe;PowerToys.Settings.runtimeconfig.json;PowerToys.Settings.UI.Lib.dll;resources.pri;System.CodeDom.dll;System.IO.Abstractions.dll;WinRT.Runtime.dll;Microsoft.Graphics.Canvas.dll;System.Management.dll;PowerToys.GPOWrapper.dll;System.Text.Json.dll;WindowsBase.dll?>
<?define SettingsV2AssetsModulesFiles=ColorPicker.png;FancyZones.png;FileLocksmith.png;AlwaysOnTop.png;HostsFileEditor.png;Awake.png;ImageResizer.png;KBM.png;MouseUtils.png;PowerAccent.png;PowerOCR.png;PowerLauncher.png;PowerPreview.png;PowerRename.png;PT.png;ScreenRuler.png;ShortcutGuide.png;VideoConference.png?>
<?define SettingsV2OOBEAssetsModulesFiles=ColorPicker.gif;AlwaysOnTop.png;HostsFileEditor.png;Awake.png;FancyZones.gif;FileExplorer.png;FileLocksmith.gif;ImageResizer.gif;KBM.gif;MouseUtils.gif;PowerAccent.gif;PowerOCR.gif;PowerRename.gif;Run.gif;ScreenRuler.gif;OOBEShortcutGuide.png;VideoConferenceMute.png;OOBEPTHero.png?>
<?define SettingsV2OOBEAssetsFluentIconsFiles=ColorPicker.png;FancyZones.png;FileLocksmith.png;AlwaysOnTop.png;Awake.png;FileExplorerPreview.png;FindMyMouse.png;Hosts.png;ImageResizer.png;KeyboardManager.png;MouseHighlighter.png;MouseCrosshairs.png;MouseUtils.png;PowerAccent.png;PowerOcr.png;PowerRename.png;PowerToys.png;PowerToysRun.png;ScreenRuler.png;Settings.png;ShortcutGuide.png;VideoConferenceMute.png?>
Expand Down
12 changes: 12 additions & 0 deletions src/common/interop/interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public
return gcnew String(CommonSharedConstants::FZE_EXIT_EVENT);
}

static String ^ FZEToggleEvent() {
return gcnew String(CommonSharedConstants::FANCY_ZONES_EDITOR_TOGGLE_EVENT);
}

static String ^ ColorPickerSendSettingsTelemetryEvent() {
return gcnew String(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
}
Expand All @@ -207,6 +211,14 @@ public
return gcnew String(CommonSharedConstants::POWERACCENT_EXIT_EVENT);
}

static String ^ ShortcutGuideTriggerEvent() {
return gcnew String(CommonSharedConstants::SHORTCUT_GUIDE_TRIGGER_EVENT);
}

static String
^ MeasureToolTriggerEvent() {
return gcnew String(CommonSharedConstants::MEASURE_TOOL_TRIGGER_EVENT);
}
static String ^ GcodePreviewResizeEvent() {
return gcnew String(CommonSharedConstants::GCODE_PREVIEW_RESIZE_EVENT);
}
Expand Down
5 changes: 5 additions & 0 deletions src/common/interop/shared_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace CommonSharedConstants
// Path to the event used to show Color Picker
const wchar_t SHOW_COLOR_PICKER_SHARED_EVENT[] = L"Local\\ShowColorPickerEvent-8c46be2a-3e05-4186-b56b-4ae986ef2525";

const wchar_t SHORTCUT_GUIDE_TRIGGER_EVENT[] = L"Local\\ShortcutGuide-TriggerEvent-d4275ad3-2531-4d19-9252-c0becbd9b496";

const wchar_t SHORTCUT_GUIDE_EXIT_EVENT[] = L"Local\\ShortcutGuide-ExitEvent-35697cdd-a3d2-47d6-a246-34efcc73eac0";

const wchar_t FANCY_ZONES_EDITOR_TOGGLE_EVENT[] = L"Local\\FancyZones-ToggleEditorEvent-1e174338-06a3-472b-874d-073b21c62f14";
Expand All @@ -44,6 +46,9 @@ namespace CommonSharedConstants
// Path to the event used by PowerOCR
const wchar_t SHOW_POWEROCR_SHARED_EVENT[] = L"Local\\PowerOCREvent-dc864e06-e1af-4ecc-9078-f98bee745e3a";

// Path to the event used by MeasureTool
const wchar_t MEASURE_TOOL_TRIGGER_EVENT[] = L"Local\\MeasureToolEvent-3d46745f-09b3-4671-a577-236be7abd199";

// Path to the event used by GcodePreviewHandler
const wchar_t GCODE_PREVIEW_RESIZE_EVENT[] = L"Local\\PowerToysGcodePreviewResizeEvent-6ff1f9bd-ccbd-4b24-a79f-40a34fb0317d";

Expand Down
10 changes: 10 additions & 0 deletions src/modules/MeasureTool/MeasureToolModuleInterface/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <interface/powertoy_module_interface.h>
#include <common/SettingsAPI/settings_objects.h>
#include "trace.h"
#include <common/interop/shared_constants.h>
#include <common/utils/string_utils.h>
#include <common/utils/winapi_error.h>
#include <common/utils/logger_helper.h>
#include <common/utils/EventWaiter.h>

extern "C" IMAGE_DOS_HEADER __ImageBase;

Expand Down Expand Up @@ -49,6 +51,9 @@ class MeasureTool : public PowertoyModuleIface
Hotkey m_hotkey;
HANDLE m_hProcess;

HANDLE triggerEvent;
EventWaiter triggerEventWaiter;

void parse_hotkey(PowerToysSettings::PowerToyValues& settings)
{
auto settingsObject = settings.get_raw_json();
Expand Down Expand Up @@ -142,6 +147,11 @@ class MeasureTool : public PowertoyModuleIface
{
LoggerHelpers::init_logger(L"Measure Tool", L"ModuleInterface", "Measure Tool");
init_settings();

triggerEvent = CreateEvent(nullptr, false, false, CommonSharedConstants::MEASURE_TOOL_TRIGGER_EVENT);
triggerEventWaiter = EventWaiter(CommonSharedConstants::MEASURE_TOOL_TRIGGER_EVENT, [this](int) {
on_hotkey(0);
});
}

~MeasureTool()
Expand Down
2 changes: 1 addition & 1 deletion src/modules/MeasureTool/MeasureToolUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
xmlns:contract7NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,7)"
xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:p="using:PowerToys.MeasureToolUI.Properties"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:p="using:PowerToys.MeasureToolUI.Properties"
xmlns:winuiex="using:WinUIEx"
IsAlwaysOnTop="True"
IsMaximizable="False"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../interface/powertoy_module_interface.h"
#include "Generated Files/resource.h"
#include <common/SettingsAPI/settings_objects.h>
#include <common/utils/EventWaiter.h>

BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD /*ul_reason_for_call*/, LPVOID /*lpReserved*/)
{
Expand All @@ -35,6 +36,11 @@ class ShortcutGuideModule : public PowertoyModuleIface
Logger::warn(L"Failed to create {} event. {}", CommonSharedConstants::SHORTCUT_GUIDE_EXIT_EVENT, get_last_error_or_default(GetLastError()));
}

triggerEvent = CreateEvent(nullptr, false, false, CommonSharedConstants::SHORTCUT_GUIDE_TRIGGER_EVENT);
triggerEventWaiter = EventWaiter(CommonSharedConstants::SHORTCUT_GUIDE_TRIGGER_EVENT, [this](int) {
OnHotkeyEx();
});

InitSettings();
}

Expand Down Expand Up @@ -191,7 +197,9 @@ class ShortcutGuideModule : public PowertoyModuleIface
UINT m_millisecondsWinKeyPressTimeForGlobalWindowsShortcuts = DEFAULT_MILLISECONDS_WIN_KEY_PRESS_TIME_FOR_GLOBAL_WINDOWS_SHORTCUTS;
UINT m_millisecondsWinKeyPressTimeForTaskbarIconShortcuts = DEFAULT_MILLISECONDS_WIN_KEY_PRESS_TIME_FOR_TASKBAR_ICON_SHORTCUTS;

HANDLE triggerEvent;
HANDLE exitEvent;
EventWaiter triggerEventWaiter;

bool StartProcess(std::wstring args = L"")
{
Expand Down
2 changes: 1 addition & 1 deletion src/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow
{
window = winrt::to_hstring(settingsWindow);
}
open_settings_window(window);
open_settings_window(window, false);
}

if (openOobe)
Expand Down
74 changes: 63 additions & 11 deletions src/runner/settings_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#include "restart_elevated.h"
#include "UpdateUtils.h"
#include "centralized_kb_hook.h"
#include "Generated files/resource.h"

#include <common/utils/json.h>
#include <common/SettingsAPI/settings_helpers.cpp>
#include <common/version/version.h>
#include <common/version/helper.h>
#include <common/logger/logger.h>
#include <common/utils/resources.h>
#include <common/utils/elevation.h>
#include <common/utils/process_path.h>
#include <common/utils/timeutil.h>
Expand Down Expand Up @@ -175,7 +177,7 @@ void dispatch_received_json(const std::wstring& json_to_parse)
const std::wstring settings_string{ get_all_settings().Stringify().c_str() };
{
std::unique_lock lock{ ipc_mutex };
if(current_settings_ipc)
if (current_settings_ipc)
current_settings_ipc->send(settings_string);
}
}
Expand All @@ -185,7 +187,7 @@ void dispatch_received_json(const std::wstring& json_to_parse)
const std::wstring settings_string{ get_all_settings().Stringify().c_str() };
{
std::unique_lock lock{ ipc_mutex };
if(current_settings_ipc)
if (current_settings_ipc)
current_settings_ipc->send(settings_string);
}
}
Expand All @@ -194,7 +196,7 @@ void dispatch_received_json(const std::wstring& json_to_parse)
const std::wstring settings_string{ get_all_settings().Stringify().c_str() };
{
std::unique_lock lock{ ipc_mutex };
if(current_settings_ipc)
if (current_settings_ipc)
current_settings_ipc->send(settings_string);
}
}
Expand All @@ -205,11 +207,35 @@ void dispatch_received_json(const std::wstring& json_to_parse)
{
{
std::unique_lock lock{ ipc_mutex };
if(current_settings_ipc)
if (current_settings_ipc)
current_settings_ipc->send(result.value());
}
}
}
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);
}
}
else if (name == L"killrunner")
{
const auto pt_main_window = FindWindowW(pt_tray_icon_window_class, nullptr);
if (pt_main_window != nullptr)
{
SendMessageW(pt_main_window, WM_CLOSE, 0, 0);
}
}
}
return;
}
Expand Down Expand Up @@ -290,7 +316,7 @@ BOOL run_settings_non_elevated(LPCWSTR executable_path, LPWSTR executable_args,

DWORD g_settings_process_id = 0;

void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::optional<std::wstring> settings_window)
void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::optional<std::wstring> settings_window, bool show_flyout = false)
{
g_isLaunchInProgress = true;

Expand Down Expand Up @@ -360,11 +386,14 @@ void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::op
// Arg 9: should scoobe window be shown
std::wstring settings_showScoobe = show_scoobe_window ? L"true" : L"false";

// Arg 10: should flyout be shown
std::wstring settings_showFlyout = show_flyout ? L"true" : L"false";

// create general settings file to initialize the settings file with installation configurations like :
// 1. Run on start up.
PTSettingsHelper::save_general_settings(save_settings.to_json());

std::wstring executable_args = fmt::format(L"\"{}\" {} {} {} {} {} {} {} {}",
std::wstring executable_args = fmt::format(L"\"{}\" {} {} {} {} {} {} {} {} {}",
executable_path,
powertoys_pipe_name,
settings_pipe_name,
Expand All @@ -373,7 +402,8 @@ void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::op
settings_elevatedStatus,
settings_isUserAnAdmin,
settings_showOobe,
settings_showScoobe);
settings_showScoobe,
settings_showFlyout);

if (settings_window.has_value())
{
Expand Down Expand Up @@ -520,18 +550,33 @@ void bring_settings_to_front()
EnumWindows(callback, 0);
}

void open_settings_window(std::optional<std::wstring> settings_window)
void open_settings_window(std::optional<std::wstring> settings_window, bool show_flyout = false)
{
if (g_settings_process_id != 0)
{
bring_settings_to_front();
if (show_flyout)
{
if (current_settings_ipc)
{
current_settings_ipc->send(L"{\"ShowYourself\":\"flyout\"}");
}
}
else
{
// nl instead of showing the window, send message to it (flyout might need to be hidden, main setting window activated)
// bring_settings_to_front();
if (current_settings_ipc)
{
current_settings_ipc->send(L"{\"ShowYourself\":\"main_page\"}");
}
}
}
else
{
if (!g_isLaunchInProgress)
{
std::thread([settings_window]() {
run_settings_window(false, false, settings_window);
std::thread([settings_window, show_flyout]() {
run_settings_window(false, false, settings_window, show_flyout);
}).detach();
}
}
Expand Down Expand Up @@ -563,6 +608,13 @@ void open_scoobe_window()
}).detach();
}

void open_flyout()
{
std::thread([]() {
run_settings_window(false, false, std::nullopt, true);
}).detach();
}

std::string ESettingsWindowNames_to_string(ESettingsWindowNames value)
{
switch (value)
Expand Down
3 changes: 2 additions & 1 deletion src/runner/settings_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ enum class ESettingsWindowNames
std::string ESettingsWindowNames_to_string(ESettingsWindowNames value);
ESettingsWindowNames ESettingsWindowNames_from_string(std::string value);

void open_settings_window(std::optional<std::wstring> settings_window);
void open_settings_window(std::optional<std::wstring> settings_window, bool show_flyout);
void close_settings_window();

void open_oobe_window();
void open_scoobe_window();
void open_flyout();
Loading

0 comments on commit c1c14b4

Please sign in to comment.