diff --git a/src/CalcViewModel/ApplicationViewModel.cpp b/src/CalcViewModel/ApplicationViewModel.cpp index e5f55ed4..a9301633 100644 --- a/src/CalcViewModel/ApplicationViewModel.cpp +++ b/src/CalcViewModel/ApplicationViewModel.cpp @@ -155,13 +155,19 @@ void ApplicationViewModel::OnModeChanged() auto resProvider = AppResourceProvider::GetInstance(); CategoryName = resProvider.GetResourceString(NavCategory::GetNameResourceKey(m_mode)); - // This is the only place where a ViewMode enum should be cast to an int. - // + // Cast mode to an int in order to save it to app data. // Save the changed mode, so that the new window launches in this mode. // Don't save until after we have adjusted to the new mode, so we don't save a mode that fails to load. ApplicationData::Current->LocalSettings->Values->Insert(ModePropertyName, NavCategory::Serialize(m_mode)); TraceLogger::GetInstance().LogModeChangeEnd(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread())); + + // Do not log mode change on first launch + if (NavCategory::IsValidViewMode(m_PreviousMode)) + { + TraceLogger::GetInstance().LogModeChange(m_mode); + } + RaisePropertyChanged(ClearMemoryVisibilityPropertyName); } diff --git a/src/CalcViewModel/Common/TraceLogger.cpp b/src/CalcViewModel/Common/TraceLogger.cpp index 998c9965..25e7257d 100644 --- a/src/CalcViewModel/Common/TraceLogger.cpp +++ b/src/CalcViewModel/Common/TraceLogger.cpp @@ -75,6 +75,8 @@ namespace CalculatorApp constexpr auto EVENT_NAME_NAV_BAR_OPENED = L"NavBarOpened"; constexpr auto EVENT_NAME_CORE_WINDOW_WAS_NULL = L"CoreWindowWasNull"; + constexpr auto EVENT_NAME_MODE_CHANGED = L"ModeChanged"; + constexpr auto EVENT_NAME_EXCEPTION = L"Exception"; constexpr auto PDT_PRIVACY_DATA_TAG = L"PartA_PrivTags"; @@ -254,6 +256,7 @@ namespace CalculatorApp fields.AddString(L"CalculatorMode", NavCategory::GetFriendlyName(mode)->Data()); fields.AddUInt32(L"WindowId", windowId); LogLevel3Event(EVENT_NAME_CALCULATOR_VIEWED_IN_SESSION, fields); + LogLevel2Event(EVENT_NAME_MODE_CHANGED, fields); } } @@ -523,6 +526,20 @@ namespace CalculatorApp } } + void TraceLogger::LogModeChange(ViewMode mode) const + { + if (!GetTraceLoggingProviderEnabled()) + return; + + if (NavCategory::IsValidViewMode(mode)) + { + LoggingFields fields{}; + // cast mode to an int for telemetry + fields.AddInt32(L"CalcMode", NavCategory::Serialize(mode)); + LogLevel2Event(EVENT_NAME_MODE_CHANGE_BEGIN, fields); + } + } + void TraceLogger::LogHistoryItemLoadBegin() const { if (!GetTraceLoggingProviderEnabled()) diff --git a/src/CalcViewModel/Common/TraceLogger.h b/src/CalcViewModel/Common/TraceLogger.h index c68441d6..53f66f23 100644 --- a/src/CalcViewModel/Common/TraceLogger.h +++ b/src/CalcViewModel/Common/TraceLogger.h @@ -64,6 +64,7 @@ namespace CalculatorApp void LogSingleMemoryUsed(unsigned int) const; void LogSharedMemoryUsed(std::wstring_view, std::wstring_view, unsigned int) const; void LogMemoryBodyOpened() const; + void LogModeChange(CalculatorApp::Common::ViewMode mode) const; void LogMemoryFlyoutOpenBegin(unsigned int) const; void LogDebug(std::wstring_view debugData); void LogMemoryFlyoutOpenEnd(unsigned int) const;