From d3f9bc0363c9b9576c9055f8df81048d8f8127c7 Mon Sep 17 00:00:00 2001 From: Tian Liao Date: Tue, 23 Apr 2024 20:45:46 +0800 Subject: [PATCH] simplify the graphing test --- src/CalcViewModel/Common/NavCategory.cpp | 29 ++++++++---------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/CalcViewModel/Common/NavCategory.cpp b/src/CalcViewModel/Common/NavCategory.cpp index 829f7488..904209e3 100644 --- a/src/CalcViewModel/Common/NavCategory.cpp +++ b/src/CalcViewModel/Common/NavCategory.cpp @@ -50,34 +50,24 @@ static constexpr int GRAPHING_ID = 17; namespace // put the utils within this TU { Platform::String^ CurrentUserId; - std::mutex GraphingModeCheckMutex; bool IsGraphingModeEnabled() { - static bool isChecked = false; - static bool isEnabled = false; + static auto enabled = [] + { + if (CurrentUserId == nullptr) + { + throw std::logic_error{ "SetCurrentUser must be invoked at least once." }; + } - std::scoped_lock lock(GraphingModeCheckMutex); - if (isChecked) - { - return isEnabled; - } - else - { auto user = User::GetFromId(CurrentUserId); if (user == nullptr) { return true; } - - auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser( - user, - L"Education", - L"AllowGraphingCalculator"); - isEnabled = namedPolicyData->GetBoolean(); - isChecked = true; - return isEnabled; - } + return NamedPolicy::GetPolicyFromPathForUser(user, L"Education", L"AllowGraphingCalculator")->GetBoolean(); + }(); + return enabled; } // The order of items in this list determines the order of items in the menu. @@ -318,7 +308,6 @@ NavCategoryGroup::NavCategoryGroup(const NavCategoryGroupInitializer& groupIniti void NavCategoryStates::SetCurrentUser(Platform::String^ userId) { - std::scoped_lock lock(GraphingModeCheckMutex); CurrentUserId = userId; }