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;
bool IsGraphingModeEnabled(User ^ firstUser = nullptr)
{
if (firstUser)
{
if (!IsGraphingModeAvailable())
{
@ -74,22 +72,19 @@ bool IsGraphingModeEnabled(User ^ firstUser = nullptr)
return _isGraphingModeEnabledCached->Value;
}
if (!firstUser)
{
return false;
}
auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser(firstUser, L"Education", L"AllowGraphingCalculator");
_isGraphingModeEnabledCached = namedPolicyData->GetBoolean() == true;
return _isGraphingModeEnabledCached->Value;
}
else
{
return _isGraphingModeEnabledCached->Value;
}
}
// The order of items in this list determines the order of items in the menu.
static list<NavCategoryInitializer> s_categoryManifest;
void NavCategory::CreateCategoryManifest(User ^ user)
{
static list<NavCategoryInitializer> s_categoryManifest = [] {
auto res = list<NavCategoryInitializer>{ NavCategoryInitializer{ ViewMode::Standard,
STANDARD_ID,
L"Standard",
@ -115,7 +110,7 @@ void NavCategory::CreateCategoryManifest(User ^ user)
bool supportGraphingCalculator = IsGraphingModeAvailable();
if (supportGraphingCalculator)
{
bool isEnabled = IsGraphingModeEnabled(user);
bool isEnabled = IsGraphingModeEnabled();
res.push_back(NavCategoryInitializer{ ViewMode::Graphing,
GRAPHING_ID,
L"Graphing",
@ -280,7 +275,14 @@ void NavCategory::CreateCategoryManifest(User ^ user)
nullptr,
SUPPORTS_NEGATIVE,
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.

View file

@ -59,15 +59,15 @@ namespace CalculatorApp
private
struct NavCategoryInitializer
{
NavCategoryInitializer(
constexpr NavCategoryInitializer(
ViewMode mode,
int id,
wchar_t * name,
wchar_t * nameKey,
wchar_t * glyph,
wchar_t const* name,
wchar_t const* nameKey,
wchar_t const* glyph,
CategoryGroupType group,
MyVirtualKey vKey,
wchar_t * aKey,
wchar_t const* aKey,
bool categorySupportsNegative,
bool enabled)
: viewMode(mode)
@ -83,22 +83,22 @@ namespace CalculatorApp
{
}
ViewMode viewMode;
int serializationId;
wchar_t* friendlyName;
wchar_t* nameResourceKey;
wchar_t* glyph;
CategoryGroupType groupType;
MyVirtualKey virtualKey;
wchar_t* accessKey;
bool supportsNegative;
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;
bool isEnabled;
};
private
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)
, headerResourceKey(h)
, modeResourceKey(n)
@ -106,10 +106,10 @@ namespace CalculatorApp
{
}
CategoryGroupType type;
wchar_t* headerResourceKey;
wchar_t* modeResourceKey;
wchar_t* automationResourceKey;
const CategoryGroupType type;
const wchar_t* headerResourceKey;
const wchar_t* modeResourceKey;
const wchar_t* automationResourceKey;
};
[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 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 ^ 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
m_preLaunched = true;
}
NavCategory::CreateCategoryManifest(args->User);
NavCategory::InitializeCategoryManifest(args->User);
OnAppLaunch(args, args->Arguments);
}