diff --git a/src/Calculator/App.xaml.cpp b/src/Calculator/App.xaml.cpp index 63edbb3d..e72b57c7 100644 --- a/src/Calculator/App.xaml.cpp +++ b/src/Calculator/App.xaml.cpp @@ -71,18 +71,31 @@ App::App() this->Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting"); + auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings(); + auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString(); if (value != nullptr) { - String ^ colorS = safe_cast(value); + String ^ colorSetting = safe_cast(value); // Apply theme choice. - if (colorS == L"Dark") + if (colorSetting == L"Dark") { App::Current->RequestedTheme = ApplicationTheme::Dark; } - else if (colorS == L"Light") + else if (colorSetting == L"Light") { App::Current->RequestedTheme = ApplicationTheme::Light; } + else if (colorSetting == L"System") + { + if (uiTheme == "#FF000000") + { + App::Current->RequestedTheme = ApplicationTheme::Dark; + } + else if (uiTheme == "#FFFFFFFF") + { + App::Current->RequestedTheme = ApplicationTheme::Light; + } + } } #if _DEBUG diff --git a/src/Calculator/App.xaml.h b/src/Calculator/App.xaml.h index f11ebef6..34c30436 100644 --- a/src/Calculator/App.xaml.h +++ b/src/Calculator/App.xaml.h @@ -10,6 +10,7 @@ #include "App.g.h" #include "WindowFrameService.h" +#include "SettingsPage.g.h" namespace CalculatorApp { diff --git a/src/Calculator/SettingsPage.xaml b/src/Calculator/SettingsPage.xaml index ce82694f..f7213a81 100644 --- a/src/Calculator/SettingsPage.xaml +++ b/src/Calculator/SettingsPage.xaml @@ -17,7 +17,7 @@ MinHeight="{StaticResource HamburgerHeight}" MaxHeight="52"/> - + @@ -34,16 +34,16 @@ - - + + LocalSettings->Values->Lookup(L"themeSetting"); if (value != nullptr) { - String ^ colorS = safe_cast(value); - // Apply theme choice. - if (colorS == L"Dark") + String ^ colorSetting = safe_cast(value); + if (colorSetting == L"Dark") { SettingsDarkTheme->IsChecked = true; } - else if (Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"isSytemTheme")) - { - SettingsSystemTheme->IsChecked = true; - } - else if (colorS == L"Light") + else if (colorSetting == L"Light") { SettingsLightTheme->IsChecked = true; } + else if (colorSetting == L"System") + { + SettingsSystemTheme->IsChecked = true; + } } } @@ -69,7 +68,6 @@ void SettingsPage::SetVersionString() void SettingsPage::SetCopyrightString() { - auto resourceLoader = AppResourceProvider::GetInstance(); auto copyrightText = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str())); SettingsCopyright->Text = copyrightText; @@ -91,8 +89,6 @@ void SettingsPage::SettingsFeedbackButtonClick(_In_ Object ^ sender, _In_ Routed void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) { - auto resourceLoader = AppResourceProvider::GetInstance(); - SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible; SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice")); Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString()); @@ -100,8 +96,6 @@ void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::Ro void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) { - auto resourceLoader = AppResourceProvider::GetInstance(); - SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible; SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice")); Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString()); @@ -109,20 +103,7 @@ void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::Rou void SettingsPage::SystemChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) { - auto resourceLoader = AppResourceProvider::GetInstance(); - auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings(); - auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString(); - SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible; SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice")); - Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"isSytemTheme", true); - - if (uiTheme == Windows::UI::Colors::Black.ToString()) - { - Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString()); - } - else if (uiTheme == Windows::UI::Colors::White.ToString()) - { - Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString()); - } + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", L"System"); }