Better fix

This commit is contained in:
greedyAI 2021-01-20 14:54:24 -08:00
commit 37d287373f
3 changed files with 46 additions and 44 deletions

View file

@ -61,8 +61,6 @@ bool IsGraphingModeAvailable()
Box<bool> ^ _isGraphingModeEnabledCached = nullptr; Box<bool> ^ _isGraphingModeEnabledCached = nullptr;
bool IsGraphingModeEnabled(User ^ firstUser = nullptr) bool IsGraphingModeEnabled(User ^ firstUser = nullptr)
{
if (firstUser)
{ {
if (!IsGraphingModeAvailable()) if (!IsGraphingModeAvailable())
{ {
@ -74,22 +72,19 @@ bool IsGraphingModeEnabled(User ^ firstUser = nullptr)
return _isGraphingModeEnabledCached->Value; return _isGraphingModeEnabledCached->Value;
} }
if (!firstUser)
{
return false;
}
auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser(firstUser, L"Education", L"AllowGraphingCalculator"); auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser(firstUser, L"Education", L"AllowGraphingCalculator");
_isGraphingModeEnabledCached = namedPolicyData->GetBoolean() == true; _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. // The order of items in this list determines the order of items in the menu.
static list<NavCategoryInitializer> s_categoryManifest; static list<NavCategoryInitializer> s_categoryManifest = [] {
void NavCategory::CreateCategoryManifest(User ^ user)
{
auto res = list<NavCategoryInitializer>{ NavCategoryInitializer{ ViewMode::Standard, auto res = list<NavCategoryInitializer>{ NavCategoryInitializer{ ViewMode::Standard,
STANDARD_ID, STANDARD_ID,
L"Standard", L"Standard",
@ -115,7 +110,7 @@ void NavCategory::CreateCategoryManifest(User ^ user)
bool supportGraphingCalculator = IsGraphingModeAvailable(); bool supportGraphingCalculator = IsGraphingModeAvailable();
if (supportGraphingCalculator) if (supportGraphingCalculator)
{ {
bool isEnabled = IsGraphingModeEnabled(user); bool isEnabled = IsGraphingModeEnabled();
res.push_back(NavCategoryInitializer{ ViewMode::Graphing, res.push_back(NavCategoryInitializer{ ViewMode::Graphing,
GRAPHING_ID, GRAPHING_ID,
L"Graphing", L"Graphing",
@ -280,7 +275,14 @@ void NavCategory::CreateCategoryManifest(User ^ user)
nullptr, nullptr,
SUPPORTS_NEGATIVE, SUPPORTS_NEGATIVE,
true } }); true } });
s_categoryManifest = res; return res;
}();
void NavCategory::InitializeCategoryManifest(User ^ user)
{
auto navCatInit = s_categoryManifest.begin();
std::advance(navCatInit, 2);
(*navCatInit).isEnabled = IsGraphingModeEnabled(user);
} }
// This function should only be used when storing the mode to app data. // This function should only be used when storing the mode to app data.

View file

@ -59,15 +59,15 @@ namespace CalculatorApp
private private
struct NavCategoryInitializer struct NavCategoryInitializer
{ {
NavCategoryInitializer( constexpr NavCategoryInitializer(
ViewMode mode, ViewMode mode,
int id, int id,
wchar_t * name, wchar_t const* name,
wchar_t * nameKey, wchar_t const* nameKey,
wchar_t * glyph, wchar_t const* glyph,
CategoryGroupType group, CategoryGroupType group,
MyVirtualKey vKey, MyVirtualKey vKey,
wchar_t * aKey, wchar_t const* aKey,
bool categorySupportsNegative, bool categorySupportsNegative,
bool enabled) bool enabled)
: viewMode(mode) : viewMode(mode)
@ -83,22 +83,22 @@ namespace CalculatorApp
{ {
} }
ViewMode viewMode; const ViewMode viewMode;
int serializationId; const int serializationId;
wchar_t* friendlyName; const wchar_t* const friendlyName;
wchar_t* nameResourceKey; const wchar_t* const nameResourceKey;
wchar_t* glyph; const wchar_t* const glyph;
CategoryGroupType groupType; const CategoryGroupType groupType;
MyVirtualKey virtualKey; const MyVirtualKey virtualKey;
wchar_t* accessKey; const wchar_t* const accessKey;
bool supportsNegative; const bool supportsNegative;
bool isEnabled; bool isEnabled;
}; };
private private
struct NavCategoryGroupInitializer struct NavCategoryGroupInitializer
{ {
NavCategoryGroupInitializer(CategoryGroupType t, wchar_t * h, wchar_t * n, wchar_t * a) constexpr NavCategoryGroupInitializer(CategoryGroupType t, wchar_t const* h, wchar_t const* n, wchar_t const* a)
: type(t) : type(t)
, headerResourceKey(h) , headerResourceKey(h)
, modeResourceKey(n) , modeResourceKey(n)
@ -106,10 +106,10 @@ namespace CalculatorApp
{ {
} }
CategoryGroupType type; const CategoryGroupType type;
wchar_t* headerResourceKey; const wchar_t* headerResourceKey;
wchar_t* modeResourceKey; const wchar_t* modeResourceKey;
wchar_t* automationResourceKey; const wchar_t* automationResourceKey;
}; };
[Windows::UI::Xaml::Data::Bindable] public ref class NavCategory sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged [Windows::UI::Xaml::Data::Bindable] public ref class NavCategory sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
@ -140,7 +140,7 @@ namespace CalculatorApp
static bool IsDateCalculatorViewMode(ViewMode mode); static bool IsDateCalculatorViewMode(ViewMode mode);
static bool IsConverterViewMode(ViewMode mode); static bool IsConverterViewMode(ViewMode mode);
static void CreateCategoryManifest(Windows::System::User ^ user); static void InitializeCategoryManifest(Windows::System::User ^ user);
static Platform::String ^ GetFriendlyName(ViewMode mode); static Platform::String ^ GetFriendlyName(ViewMode mode);
static Platform::String ^ GetNameResourceKey(ViewMode mode); static Platform::String ^ GetNameResourceKey(ViewMode mode);

View file

@ -198,7 +198,7 @@ void App::OnLaunched(LaunchActivatedEventArgs ^ args)
// If the app got pre-launch activated, then save that state in a flag // If the app got pre-launch activated, then save that state in a flag
m_preLaunched = true; m_preLaunched = true;
} }
NavCategory::CreateCategoryManifest(args->User); NavCategory::InitializeCategoryManifest(args->User);
OnAppLaunch(args, args->Arguments); OnAppLaunch(args, args->Arguments);
} }