Repository: microsoft/PowerToys
File: src/runner/main.cpp (C++)

Code before:

void open_menu_from_another_instance(std::optional<std::string> settings_window)
{
    const HWND hwnd_main = FindWindowW(L"PToyTrayIconWindow", nullptr);
    LPARAM msg = static_cast<LPARAM>(ESettingsWindowNames::Dashboard);
    if (settings_window.has_value() && settings_window.value() != "")
    {
        msg = static_cast<LPARAM>(ESettingsWindowNames_from_string(settings_window.value()));
    }
    PostMessageW(hwnd_main, WM_COMMAND, ID_SETTINGS_MENU_COMMAND, msg);
    SetForegroundWindow(hwnd_main); // Bring the settings window to the front
}

int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow, bool openOobe, bool openScoobe, bool showRestartNotificationAfterUpdate)
{
    Logger::info("Runner is starting. Elevated={} openOobe={} openScoobe={} showRestartNotificationAfterUpdate={}", isProcessElevated, openOobe, openScoobe, showRestartNotificationAfterUpdate);
    DPIAware::EnableDPIAwarenessForThisProcess();

#if _DEBUG && _WIN64
//Global error handlers to diagnose errors.
//We prefer this not to show any longer until there's a bug to diagnose.
//init_global_error_handlers();
#endif
    Trace::RegisterProvider();
    start_tray_icon(isProcessElevated);
    set_tray_icon_visible(!get_general_settings().showSystemTrayIcon);
    CentralizedKeyboardHook::Start();

    int result = -1;
    try
    {
        if (!openOobe && showRestartNotificationAfterUpdate)
        {
            std::thread{
                [] {
                    // Wait a bit, because Windows has a delay until it picks up toast notification registration in the registry
                    Sleep(10000);
                    Logger::info("Showing toast notification asking to restart PC");
                    notifications::show_toast(GET_RESOURCE_STRING(IDS_PT_VERSION_CHANGE_ASK_FOR_COMPUTER_RESTART).c_str(), L"PowerToys");
                }
            }.detach();
        }

        std::thread{ [] {
            PeriodicUpdateWorker();
        } }.detach();

        std::thread{ [] {
            if (updating::uninstall_previous_msix_version_async().get())
            {
                notifications::show_toast(GET_RESOURCE_STRING(IDS_OLDER_MSIX_UNINSTALLED).c_str(), L"PowerToys");

Review comment (suggestion):
```cpp
set_tray_icon_visible(get_general_settings().showSystemTrayIcon);
```

This no longer needs to be inverted with the fix to `tray_icon.cpp` to correctly set state as the name suggests.

Code after:

void open_menu_from_another_instance(std::optional<std::string> settings_window)
{
    const HWND hwnd_main = FindWindowW(L"PToyTrayIconWindow", nullptr);
    LPARAM msg = static_cast<LPARAM>(ESettingsWindowNames::Dashboard);
    if (settings_window.has_value() && settings_window.value() != "")
    {
        msg = static_cast<LPARAM>(ESettingsWindowNames_from_string(settings_window.value()));
    }
    PostMessageW(hwnd_main, WM_COMMAND, ID_SETTINGS_MENU_COMMAND, msg);
    SetForegroundWindow(hwnd_main); // Bring the settings window to the front
}

int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow, bool openOobe, bool openScoobe, bool showRestartNotificationAfterUpdate)
{
    Logger::info("Runner is starting. Elevated={} openOobe={} openScoobe={} showRestartNotificationAfterUpdate={}", isProcessElevated, openOobe, openScoobe, showRestartNotificationAfterUpdate);
    DPIAware::EnableDPIAwarenessForThisProcess();

#if _DEBUG && _WIN64
//Global error handlers to diagnose errors.
//We prefer this not to show any longer until there's a bug to diagnose.
//init_global_error_handlers();
#endif
    Trace::RegisterProvider();
    start_tray_icon(isProcessElevated);
    set_tray_icon_visible(get_general_settings().showSystemTrayIcon);
    CentralizedKeyboardHook::Start();

    int result = -1;
    try
    {
        if (!openOobe && showRestartNotificationAfterUpdate)
        {
            std::thread{
                [] {
                    // Wait a bit, because Windows has a delay until it picks up toast notification registration in the registry
                    Sleep(10000);
                    Logger::info("Showing toast notification asking to restart PC");
                    notifications::show_toast(GET_RESOURCE_STRING(IDS_PT_VERSION_CHANGE_ASK_FOR_COMPUTER_RESTART).c_str(), L"PowerToys");
                }
            }.detach();
        }

        std::thread{ [] {
            PeriodicUpdateWorker();
        } }.detach();

        std::thread{ [] {
            if (updating::uninstall_previous_msix_version_async().get())
            {
                notifications::show_toast(GET_RESOURCE_STRING(IDS_OLDER_MSIX_UNINSTALLED).c_str(), L"PowerToys");