diff --git a/src/CalcViewModel/Common/NavCategory.cpp b/src/CalcViewModel/Common/NavCategory.cpp index 6af89959..1bd0d15c 100644 --- a/src/CalcViewModel/Common/NavCategory.cpp +++ b/src/CalcViewModel/Common/NavCategory.cpp @@ -60,29 +60,36 @@ bool IsGraphingModeAvailable() } Box ^ _isGraphingModeEnabledCached = nullptr; -bool IsGraphingModeEnabled() +bool IsGraphingModeEnabled(User ^ firstUser = nullptr) { - if (!IsGraphingModeAvailable()) + if (firstUser) { - return false; - } + if (!IsGraphingModeAvailable()) + { + return false; + } - if (_isGraphingModeEnabledCached != nullptr) - { - return _isGraphingModeEnabledCached->Value; - } + if (_isGraphingModeEnabledCached != nullptr) + { + return _isGraphingModeEnabledCached->Value; + } - User ^ firstUser; - create_task(User::FindAllAsync(UserType::LocalUser)).then([&firstUser](IVectorView ^ users) { - firstUser = users->GetAt(0); }).wait(); auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser(firstUser, L"Education", L"AllowGraphingCalculator"); _isGraphingModeEnabledCached = namedPolicyData->GetBoolean() == true; - return _isGraphingModeEnabledCached->Value; + return _isGraphingModeEnabledCached->Value; + } + else + { + return _isGraphingModeEnabledCached->Value; + } } // The order of items in this list determines the order of items in the menu. -static const list s_categoryManifest = [] { +static list s_categoryManifest; + +void NavCategory::CreateCategoryManifest(User ^ user) +{ auto res = list{ NavCategoryInitializer{ ViewMode::Standard, STANDARD_ID, L"Standard", @@ -108,7 +115,7 @@ static const list s_categoryManifest = [] { bool supportGraphingCalculator = IsGraphingModeAvailable(); if (supportGraphingCalculator) { - const bool isEnabled = IsGraphingModeEnabled(); + bool isEnabled = IsGraphingModeEnabled(user); res.push_back(NavCategoryInitializer{ ViewMode::Graphing, GRAPHING_ID, L"Graphing", @@ -273,8 +280,8 @@ static const list s_categoryManifest = [] { nullptr, SUPPORTS_NEGATIVE, true } }); - return res; -}(); + s_categoryManifest = res; +} // This function should only be used when storing the mode to app data. int NavCategory::Serialize(ViewMode mode) diff --git a/src/CalcViewModel/Common/NavCategory.h b/src/CalcViewModel/Common/NavCategory.h index b7c46057..3d9e2296 100644 --- a/src/CalcViewModel/Common/NavCategory.h +++ b/src/CalcViewModel/Common/NavCategory.h @@ -59,15 +59,15 @@ namespace CalculatorApp private struct NavCategoryInitializer { - constexpr NavCategoryInitializer( + NavCategoryInitializer( ViewMode mode, int id, - wchar_t const* name, - wchar_t const* nameKey, - wchar_t const* glyph, + wchar_t * name, + wchar_t * nameKey, + wchar_t * glyph, CategoryGroupType group, MyVirtualKey vKey, - wchar_t const* aKey, + wchar_t * aKey, bool categorySupportsNegative, bool enabled) : viewMode(mode) @@ -83,22 +83,22 @@ namespace CalculatorApp { } - const ViewMode viewMode; - const int serializationId; - const wchar_t* const friendlyName; - const wchar_t* const nameResourceKey; - const wchar_t* const glyph; - const CategoryGroupType groupType; - const MyVirtualKey virtualKey; - const wchar_t* const accessKey; - const bool supportsNegative; - const bool isEnabled; + ViewMode viewMode; + int serializationId; + wchar_t* friendlyName; + wchar_t* nameResourceKey; + wchar_t* glyph; + CategoryGroupType groupType; + MyVirtualKey virtualKey; + wchar_t* accessKey; + bool supportsNegative; + bool isEnabled; }; private struct NavCategoryGroupInitializer { - constexpr NavCategoryGroupInitializer(CategoryGroupType t, wchar_t const* h, wchar_t const* n, wchar_t const* a) + NavCategoryGroupInitializer(CategoryGroupType t, wchar_t * h, wchar_t * n, wchar_t * a) : type(t) , headerResourceKey(h) , modeResourceKey(n) @@ -106,10 +106,10 @@ namespace CalculatorApp { } - const CategoryGroupType type; - const wchar_t* headerResourceKey; - const wchar_t* modeResourceKey; - const wchar_t* automationResourceKey; + CategoryGroupType type; + wchar_t* headerResourceKey; + wchar_t* modeResourceKey; + wchar_t* automationResourceKey; }; [Windows::UI::Xaml::Data::Bindable] public ref class NavCategory sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged @@ -140,6 +140,8 @@ namespace CalculatorApp static bool IsDateCalculatorViewMode(ViewMode mode); static bool IsConverterViewMode(ViewMode mode); + static void CreateCategoryManifest(Windows::System::User ^ user); + static Platform::String ^ GetFriendlyName(ViewMode mode); static Platform::String ^ GetNameResourceKey(ViewMode mode); static CategoryGroupType GetGroupType(ViewMode mode); diff --git a/src/Calculator/App.xaml.cpp b/src/Calculator/App.xaml.cpp index b8f7702d..f11c1f7f 100644 --- a/src/Calculator/App.xaml.cpp +++ b/src/Calculator/App.xaml.cpp @@ -198,12 +198,12 @@ void App::OnLaunched(LaunchActivatedEventArgs ^ args) // If the app got pre-launch activated, then save that state in a flag m_preLaunched = true; } + NavCategory::CreateCategoryManifest(args->User); OnAppLaunch(args, args->Arguments); } void App::OnAppLaunch(IActivatedEventArgs ^ args, String ^ argument) { - // Uncomment the following lines to display frame-rate and per-frame CPU usage info. //#if _DEBUG // if (IsDebuggerPresent())