-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable switching app theme based off of OS theme #14497
Changes from all commits
3d5d88a
5f54750
43cc9fa
e4c2d20
b1c5342
e4f3625
c16b998
4e40eff
367d38c
fdc2c80
8e08d75
a0e28f1
b64b032
1b81da9
d71c56e
e70ac18
11460d6
b969353
c823fe6
4e51484
9f251dd
1260705
109ecd9
1aa3675
a14574a
fc6ef60
ef6f660
c56a424
156e952
77d00ee
a10dfe4
14f38f3
9ff12c8
f11220f
0fac998
85d6f92
c176c71
40afe5e
bc1b385
7666478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, why is this a separate file? When, in the future, should I add something here instead of, say, Terminal Settings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just a utils header - there was no good place for shared code in the settings binary. It didn't compile in the WinRTUtils binary (cause dependencies on Windows.UI.Xaml or something), so I just stuck it here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this might be good opportunity to rename |
||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
|
||
bool IsSystemInDarkTheme(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
#include "WindowTheme.g.cpp" | ||
#include "TabRowTheme.g.cpp" | ||
#include "TabTheme.g.cpp" | ||
#include "ThemePair.g.cpp" | ||
#include "Theme.g.cpp" | ||
|
||
using namespace ::Microsoft::Console; | ||
|
@@ -27,6 +28,8 @@ namespace winrt | |
} | ||
|
||
static constexpr std::string_view NameKey{ "name" }; | ||
static constexpr std::string_view LightNameKey{ "light" }; | ||
static constexpr std::string_view DarkNameKey{ "dark" }; | ||
|
||
static constexpr wchar_t RegKeyDwm[] = L"Software\\Microsoft\\Windows\\DWM"; | ||
static constexpr wchar_t RegKeyAccentColor[] = L"AccentColor"; | ||
|
@@ -320,3 +323,42 @@ winrt::WUX::ElementTheme Theme::RequestedTheme() const noexcept | |
{ | ||
return _Window ? _Window.RequestedTheme() : winrt::WUX::ElementTheme::Default; | ||
} | ||
|
||
winrt::com_ptr<ThemePair> ThemePair::FromJson(const Json::Value& json) | ||
{ | ||
auto result = winrt::make_self<ThemePair>(L"dark"); | ||
|
||
if (json.isString()) | ||
{ | ||
result->_DarkName = result->_LightName = JsonUtils::GetValue<winrt::hstring>(json); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, |
||
} | ||
else if (json.isObject()) | ||
{ | ||
JsonUtils::GetValueForKey(json, DarkNameKey, result->_DarkName); | ||
JsonUtils::GetValueForKey(json, LightNameKey, result->_LightName); | ||
} | ||
return result; | ||
} | ||
|
||
Json::Value ThemePair::ToJson() const | ||
{ | ||
if (_DarkName == _LightName) | ||
{ | ||
return JsonUtils::ConversionTrait<winrt::hstring>().ToJson(DarkName()); | ||
} | ||
else | ||
{ | ||
Json::Value json{ Json::ValueType::objectValue }; | ||
|
||
JsonUtils::SetValueForKey(json, DarkNameKey, _DarkName); | ||
JsonUtils::SetValueForKey(json, LightNameKey, _LightName); | ||
return json; | ||
} | ||
} | ||
winrt::com_ptr<ThemePair> ThemePair::Copy() const | ||
{ | ||
auto pair{ winrt::make_self<ThemePair>() }; | ||
pair->_DarkName = _DarkName; | ||
pair->_LightName = _LightName; | ||
return pair; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever