Add darkmode support for the settings window (#494)

This commit is contained in:
Bartosz Sosnowski
2019-10-16 10:21:44 +02:00
committed by GitHub
parent c8039828fa
commit 52b15f29ad
22 changed files with 343 additions and 59 deletions

View File

@@ -3,11 +3,23 @@
#include "auto_start_helper.h"
#include <common/settings_helpers.h>
#include "powertoy_module.h"
#include <common/windows_colors.h>
using namespace web;
static std::wstring settings_theme;
web::json::value load_general_settings() {
return PTSettingsHelper::load_general_settings();
auto loaded = PTSettingsHelper::load_general_settings();
if (loaded.has_string_field(L"theme")) {
settings_theme = loaded.as_object()[L"theme"].as_string();
if (settings_theme != L"dark" && settings_theme != L"light") {
settings_theme = L"system";
}
} else {
settings_theme = L"system";
}
return loaded;
}
web::json::value get_general_settings() {
@@ -20,6 +32,9 @@ web::json::value get_general_settings() {
enabled.as_object()[name] = json::value::boolean(powertoy.is_enabled());
}
result.as_object()[L"enabled"] = enabled;
result.as_object()[L"theme"] = json::value::string(settings_theme);
result.as_object()[L"system_theme"] = json::value::string(WindowsColors::is_dark_mode() ? L"dark" : L"light");
return result;
}
@@ -52,6 +67,9 @@ void apply_general_settings(const json::value& general_configs) {
}
}
}
if (general_configs.has_string_field(L"theme")) {
settings_theme = general_configs.at(L"theme").as_string();
}
json::value save_settings = get_general_settings();
PTSettingsHelper::save_general_settings(save_settings);
}

View File

@@ -9,6 +9,7 @@
#include <common/two_way_pipe_message_ipc.h>
#include "tray_icon.h"
#include "general_settings.h"
#include "common/windows_colors.h"
#define BUFSIZE 1024
@@ -116,6 +117,12 @@ void run_settings_window() {
PathRemoveFileSpec(executable_path);
wcscat_s(executable_path, L"\\PowerToysSettings.exe");
WCHAR executable_args[MAX_PATH * 3];
std::wstring settings_theme_setting = get_general_settings().at(L"theme").as_string();
std::wstring settings_theme;
if (settings_theme_setting == L"dark" || (settings_theme_setting == L"system" && WindowsColors::is_dark_mode())) {
settings_theme = L" dark"; // Include arg separating space
}
// Generate unique names for the pipes, if getting a UUID is possible
std::wstring powertoys_pipe_name(L"\\\\.\\pipe\\powertoys_runner_");
std::wstring settings_pipe_name(L"\\\\.\\pipe\\powertoys_settings_");
@@ -136,6 +143,7 @@ void run_settings_window() {
// powertoys_pipe - PowerToys pipe server.
// settings_pipe - Settings pipe server.
// powertoys_pid - PowerToys process pid.
// settings_theme - pass "dark" to start the settings window in dark mode
wcscpy_s(executable_args, L"\"");
wcscat_s(executable_args, executable_path);
wcscat_s(executable_args, L"\"");
@@ -145,6 +153,7 @@ void run_settings_window() {
wcscat_s(executable_args, settings_pipe_name.c_str());
wcscat_s(executable_args, L" ");
wcscat_s(executable_args, std::to_wstring(powertoys_pid).c_str());
wcscat_s(executable_args, settings_theme.c_str());
// Run the Settings process with non-elevated privileges