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

Code before:
        _ApplyLanguageSettingChange();
        _RefreshThemeRoutine();
        _ApplyStartupTaskStateChange();

        auto args = winrt::make_self<SystemMenuChangeArgs>(RS_(L"SettingsMenuItem"), SystemMenuChangeAction::Add, SystemMenuItemHandler(this, &AppLogic::_OpenSettingsUI));
        _SystemMenuChangeRequestedHandlers(*this, *args);

        TraceLoggingWrite(
            g_hTerminalAppProvider,
            "AppCreated",
            TraceLoggingDescription("Event emitted when the application is started"),
            TraceLoggingBool(_settings.GlobalSettings().ShowTabsInTitlebar(), "TabsInTitlebar"),
            TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
            TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));

        _onCreateResearch();
    }

    void AppLogic::_onCreateResearch()
    {
        // ----------------------------- RE: Themes ----------------------------
        const auto numThemes = _settings.GlobalSettings().Themes().Size();
        const auto themeInUse = _settings.GlobalSettings().CurrentTheme();
        const auto usingDefaultTheme = themeInUse.Name() == L"light" ||
                                       themeInUse.Name() == L"dark" ||
                                       themeInUse.Name() == L"system";

        TraceLoggingWrite(
            g_hTerminalAppProvider,
            "ThemesInUse",
            TraceLoggingDescription("Data about the themes in use"),
            TraceLoggingBool(usingDefaultTheme, "UsingDefaultTheme"),
            TraceLoggingInt32(numThemes, "NumThemes"),
            TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
            TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));

        // --------------------------- RE: sendInput ---------------------------

        auto totalSendInput = 0;
        const auto& allActions = _settings.GlobalSettings().ActionMap().AvailableActions();
        for (const auto&& [name, actionAndArgs] : allActions)
        {
            if (actionAndArgs.Action() == ShortcutAction::SendInput)
                totalSendInput++;
        }

        TraceLoggingWrite(
            g_hTerminalAppProvider,
            "SendInputUsage",
            TraceLoggingDescription("Data about usage of sendInput"),
            TraceLoggingInt32(totalSendInput, "NumSendInputActions"),

Review comment (bug):
```suggestion
        const auto themeInUse = _settings.GlobalSettings().CurrentTheme().Name();
        const auto usingDefaultTheme = themeInUse == L"light" ||
                                       themeInUse == L"dark" ||
                                       themeInUse == L"system";
```

I'm a bit concerned about what happens if `CurrentTheme()` returns `nullptr`. Can it do that?

Code after:
        _ApplyLanguageSettingChange();
        _RefreshThemeRoutine();
        _ApplyStartupTaskStateChange();

        auto args = winrt::make_self<SystemMenuChangeArgs>(RS_(L"SettingsMenuItem"), SystemMenuChangeAction::Add, SystemMenuItemHandler(this, &AppLogic::_OpenSettingsUI));
        _SystemMenuChangeRequestedHandlers(*this, *args);

        TraceLoggingWrite(
            g_hTerminalAppProvider,
            "AppCreated",
            TraceLoggingDescription("Event emitted when the application is started"),
            TraceLoggingBool(_settings.GlobalSettings().ShowTabsInTitlebar(), "TabsInTitlebar"),
            TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
            TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
    }

    void AppLogic::Quit()
    {
        if (_root)
        {
            _root->CloseWindow(true);
        }
    }

    // Method Description:
    // - Show a ContentDialog with buttons to take further action. Uses the
    //   FrameworkElements provided as the title and content of this dialog, and
    //   displays buttons (or a single button). Two buttons (primary and secondary)
    //   will be displayed if this is an warning dialog for closing the terminal,
    //   this allows the users to abandon the closing action. Otherwise, a single
    //   close button will be displayed.
    // - Only one dialog can be visible at a time. If another dialog is visible
    //   when this is called, nothing happens.
    // Arguments:
    // - dialog: the dialog object that is going to show up
    // Return value:
    // - an IAsyncOperation with the dialog result
    winrt::Windows::Foundation::IAsyncOperation<ContentDialogResult> AppLogic::ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog)
    {
        // DON'T release this lock in a wil::scope_exit. The scope_exit will get
        // called when we await, which is not what we want.
        std::unique_lock lock{ _dialogLock, std::try_to_lock };
        if (!lock)
        {
            // Another dialog is visible.
            co_return ContentDialogResult::None;
        }

        _dialog = dialog;

        // IMPORTANT: This is necessary as documented in the ContentDialog MSDN docs.