Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalWindow.cpp (C++)

Code before:
    // - <none>
    // Return Value:
    // - <none>
    void TerminalWindow::Create()
    {
        _root->DialogPresenter(*this);

        // Pay attention, that even if some command line arguments were parsed (like launch mode),
        // we will not use the startup actions from settings.
        // While this simplifies the logic, we might want to reconsider this behavior in the future.
        //
        // Obviously, don't use the `startupActions` from the settings in the
        // case of a tear-out / reattach. GH#16050
        if (!_hasCommandLineArguments &&
            _initialContentArgs.empty() &&
            _gotSettingsStartupActions)
        {
            _root->SetStartupActions(_settingsStartupArgs);
        }

        _root->SetSettings(_settings, false); // We're on our UI thread right now, so this is safe
        _root->Loaded({ get_weak(), &TerminalWindow::_OnLoaded });
        _root->Initialized({ get_weak(), &TerminalWindow::_pageInitialized });
        _root->WindowSizeChanged({ get_weak(), &TerminalWindow::_WindowSizeChanged });
        _root->RenameWindowRequested({ get_weak(), &TerminalWindow::_RenameWindowRequested });
        _root->ShowLoadWarningsDialog([weakThis{ get_weak() }](auto&& /*s*/, const Windows::Foundation::Collections::IVectorView<Microsoft::Terminal::Settings::Model::SettingsLoadWarnings>& warnings) {
            if (auto strongThis{ weakThis.get() })
            {
                strongThis->_ShowLoadWarningsDialog(warnings);
            }
        });
        _root->Create();

        AppLogic::Current()->SettingsChanged({ get_weak(), &TerminalWindow::UpdateSettingsHandler });

        _RefreshThemeRoutine();

        auto args = winrt::make_self<SystemMenuChangeArgs>(RS_(L"SettingsMenuItem"),
                                                           SystemMenuChangeAction::Add,
                                                           SystemMenuItemHandler(this, &TerminalWindow::_OpenSettingsUI));
        SystemMenuChangeRequested.raise(*this, *args);

        TraceLoggingWrite(
            g_hTerminalAppProvider,
            "WindowCreated",
            TraceLoggingDescription("Event emitted when the window is started"),
            TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
            TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
    }

    void TerminalWindow::_pageInitialized(const IInspectable&, const IInspectable&)

Review comment (security):
in general, this should follow the same pattern as above. Use `{get_weak(), &Foo::Function}` instead of authoring your own weak reference resolver. :)

It will require adding a useless argument to `_ShowLoadWarningsDialog`, but perhaps that's fine

Code after:
    // - <none>
    // Return Value:
    // - <none>
    void TerminalWindow::Create()
    {
        _root->DialogPresenter(*this);

        // Pay attention, that even if some command line arguments were parsed (like launch mode),
        // we will not use the startup actions from settings.
        // While this simplifies the logic, we might want to reconsider this behavior in the future.
        //
        // Obviously, don't use the `startupActions` from the settings in the
        // case of a tear-out / reattach. GH#16050
        if (!_hasCommandLineArguments &&
            _initialContentArgs.empty() &&
            _gotSettingsStartupActions)
        {
            _root->SetStartupActions(_settingsStartupArgs);
        }

        _root->SetSettings(_settings, false); // We're on our UI thread right now, so this is safe
        _root->Loaded({ get_weak(), &TerminalWindow::_OnLoaded });
        _root->Initialized({ get_weak(), &TerminalWindow::_pageInitialized });
        _root->WindowSizeChanged({ get_weak(), &TerminalWindow::_WindowSizeChanged });
        _root->RenameWindowRequested({ get_weak(), &TerminalWindow::_RenameWindowRequested });
        _root->ShowLoadWarningsDialog({ get_weak(), &TerminalWindow::_ShowLoadWarningsDialog });
        _root->Create();

        AppLogic::Current()->SettingsChanged({ get_weak(), &TerminalWindow::UpdateSettingsHandler });

        _RefreshThemeRoutine();

        auto args = winrt::make_self<SystemMenuChangeArgs>(RS_(L"SettingsMenuItem"),
                                                           SystemMenuChangeAction::Add,
                                                           SystemMenuItemHandler(this, &TerminalWindow::_OpenSettingsUI));
        SystemMenuChangeRequested.raise(*this, *args);

        TraceLoggingWrite(
            g_hTerminalAppProvider,
            "WindowCreated",
            TraceLoggingDescription("Event emitted when the window is started"),
            TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
            TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
    }

    void TerminalWindow::_pageInitialized(const IInspectable&, const IInspectable&)
    {
        // GH#288 - When we finish initialization, if the user wanted us
        // launched _fullscreen_, toggle fullscreen mode. This will make sure
        // that the window size is _first_ set up as something sensible, so
        // leaving fullscreen returns to a reasonable size.