simplify the graphing test

This commit is contained in:
Tian Liao 2024-04-23 20:45:46 +08:00
commit d3f9bc0363

View file

@ -50,34 +50,24 @@ static constexpr int GRAPHING_ID = 17;
namespace // put the utils within this TU namespace // put the utils within this TU
{ {
Platform::String^ CurrentUserId; Platform::String^ CurrentUserId;
std::mutex GraphingModeCheckMutex;
bool IsGraphingModeEnabled() bool IsGraphingModeEnabled()
{ {
static bool isChecked = false; static auto enabled = []
static bool isEnabled = false; {
if (CurrentUserId == nullptr)
{
throw std::logic_error{ "SetCurrentUser must be invoked at least once." };
}
std::scoped_lock<std::mutex> lock(GraphingModeCheckMutex);
if (isChecked)
{
return isEnabled;
}
else
{
auto user = User::GetFromId(CurrentUserId); auto user = User::GetFromId(CurrentUserId);
if (user == nullptr) if (user == nullptr)
{ {
return true; return true;
} }
return NamedPolicy::GetPolicyFromPathForUser(user, L"Education", L"AllowGraphingCalculator")->GetBoolean();
auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser( }();
user, return enabled;
L"Education",
L"AllowGraphingCalculator");
isEnabled = namedPolicyData->GetBoolean();
isChecked = true;
return isEnabled;
}
} }
// The order of items in this list determines the order of items in the menu. // 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) void NavCategoryStates::SetCurrentUser(Platform::String^ userId)
{ {
std::scoped_lock<std::mutex> lock(GraphingModeCheckMutex);
CurrentUserId = userId; CurrentUserId = userId;
} }