doc/devdocs/core/runner.md
The PowerToys Runner is the main executable (PowerToys.exe) that loads and manages all PowerToys modules.
The Runner is responsible for:
The system tray icon is one of the first components that starts when calling the render_main function:
tray_icon.h and tray_icon.cppstart_tray_icon()tray_icon_window_proc()WM_COMMAND and tray icon notifications for handling menu optionsshell_notify_icon to register with the system traystart_tray_icon() initializes the tray icon by:
tray_icon_window_proc() processes window messages, including:
wm_icon_notify messages from tray icon interactionsWhen the tray icon is clicked or a menu option is selected, the Runner communicates with the Settings UI:
For quick access flyout (left-click):
current_settings_ipc->send(L"{\"ShowYourself\":\"flyout\"}");
For the main dashboard (menu option or double-click):
current_settings_ipc->send(L"{\"ShowYourself\":\"Dashboard\"}");
ipcmanager = new TwoWayPipeMessageIPCManaged(cmdArgs[(int)Arguments.SettingsPipeName],
cmdArgs[(int)Arguments.PTPipeName],
(string message) => {
if (IPCMessageReceivedCallback != null && message.Length > 0) {
IPCMessageReceivedCallback(message);
}
});
The Settings UI processes incoming IPC messages through a callback chain:
ShellPage.ShellHandler.IPCResponseHandleList process the messagesReceiveMessage method in ShellPage interprets commands:
"ShowYourself": "flyout""ShowYourself": "Dashboard" or other page namesWhen showing the flyout, the tray icon can also send position coordinates to place the flyout near the tray icon:
{
"ShowYourself": "flyout",
"x_position": 1234,
"y_position": 567
}
The flyout window is then activated and brought to the foreground using native Windows APIs to ensure visibility.
.RC files (Resource files)base.h defines IDsresources.resx contains localized stringsThe tray icon class is used when sending messages to the runner. For example, to close the runner:
// Find the window with the PowerToys tray icon class and send it a close message
WM_CLOSE
main.cppContains the executable starting point, initialization code and the list of known PowerToys. All singletons are also initialized here at the start. Loads all the powertoys by scanning the ./modules folder and enable()s those marked as enabled in %LOCALAPPDATA%\Microsoft\PowerToys\settings.json config. Then it runs a message loop for the tray UI. Note that this message loop also handles lowlevel_keyboard_hook events.
powertoy_module.h and powertoy_module.cppContains code for initializing and managing the PowerToy modules. PowertoyModule is a RAII-style holder for the PowertoyModuleIface pointer, which we got by invoking module DLL's powertoy_create function.
tray_icon.cppContains code for managing the PowerToys tray icon and its menu commands. Note that dispatch_run_on_main_ui_thread is used to
transfer received json message from the Settings window to the main thread, since we're communicating with it from a dedicated thread.
settings_window.cppContains code for starting the PowerToys settings window and communicating with it. Settings window is a separate process, so we're using Windows pipes as a transport for json messages.
general_settings.cppContains code for loading, saving and applying the general settings.
auto_start_helper.cppContains helper code for registering and unregistering PowerToys to run when the user logs in.
unhandled_exception_handler.cppContains helper code to get stack traces in builds. Can be used by adding a call to init_global_error_handlers in WinMain.
trace.cppContains code for telemetry.
svgsContains the SVG assets used by the PowerToys modules.
bug_report.cppContains logic to start bug report tool.
centralized_hotkeys.cppContains hot key logic registration and un-registration.
centralized_kb_hook.cppContains logic to handle PowerToys' keyboard shortcut functionality.
restart_elevated.cppContains logic for restarting the current process with different elevation levels.
RestartManagement.cppContains code for restarting a process.
settings_telemetry.cppContains logic that periodically triggers module-specific setting's telemetry delivery and manages timing and error handling for the process.
UpdateUtils.cppContains code to handle the automatic update checking, notification, and installation process for PowerToys.