mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
FancyZones and Shortcut Guide initial commit
Co-authored-by: Alexis Campailla <alexis@janeasystems.com> Co-authored-by: Bret Anderson <bretan@microsoft.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Jeff Bogdan <jeffbog@microsoft.com> Co-authored-by: March Rogers <marchr@microsoft.com> Co-authored-by: Mike Harsh <mharsh@microsoft.com> Co-authored-by: Nachum Bundak <Nachum.Bundak@microsoft.com> Co-authored-by: Oliver Jones <ojones@microsoft.com> Co-authored-by: Patrick Little <plittle@microsoft.com>
This commit is contained in:
committed by
Bartosz Sosnowski
parent
10c5396099
commit
8431b80e48
91
src/runner/general_settings.cpp
Normal file
91
src/runner/general_settings.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "pch.h"
|
||||
#include "general_settings.h"
|
||||
#include "auto_start_helper.h"
|
||||
#include <common/settings_helpers.h>
|
||||
#include "powertoy_module.h"
|
||||
|
||||
using namespace web;
|
||||
|
||||
web::json::value load_general_settings() {
|
||||
return PTSettingsHelper::load_general_settings();
|
||||
}
|
||||
|
||||
web::json::value get_general_settings() {
|
||||
json::value result = json::value::object();
|
||||
bool startup = is_auto_start_task_active_for_this_user();
|
||||
result.as_object()[L"startup"] = json::value::boolean(startup);
|
||||
|
||||
json::value enabled = json::value::object();
|
||||
for (auto&[name, powertoy] : modules()) {
|
||||
enabled.as_object()[name] = json::value::boolean(powertoy.is_enabled());
|
||||
}
|
||||
result.as_object()[L"enabled"] = enabled;
|
||||
return result;
|
||||
}
|
||||
|
||||
void apply_general_settings(const json::value& general_configs) {
|
||||
bool contains_startup = general_configs.has_boolean_field(L"startup");
|
||||
if (contains_startup) {
|
||||
bool startup = general_configs.at(L"startup").as_bool();
|
||||
bool current_startup = is_auto_start_task_active_for_this_user();
|
||||
if (current_startup != startup) {
|
||||
if (startup) {
|
||||
enable_auto_start_task_for_this_user();
|
||||
} else {
|
||||
disable_auto_start_task_for_this_user();
|
||||
}
|
||||
}
|
||||
}
|
||||
bool contains_enabled = general_configs.has_object_field(L"enabled");
|
||||
if (contains_enabled) {
|
||||
for (auto enabled_element : general_configs.at(L"enabled").as_object()) {
|
||||
if (enabled_element.second.is_boolean() && modules().find(enabled_element.first) != modules().end()) {
|
||||
bool module_inst_enabled = modules().at(enabled_element.first).is_enabled();
|
||||
bool target_enabled = enabled_element.second.as_bool();
|
||||
if (module_inst_enabled != target_enabled) {
|
||||
if (target_enabled) {
|
||||
modules().at(enabled_element.first).enable();
|
||||
} else {
|
||||
modules().at(enabled_element.first).disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
json::value save_settings = get_general_settings();
|
||||
PTSettingsHelper::save_general_settings(save_settings);
|
||||
}
|
||||
|
||||
void start_initial_powertoys() {
|
||||
bool only_enable_some_powertoys = false;
|
||||
|
||||
std::unordered_set<std::wstring> powertoys_to_enable;
|
||||
|
||||
json::value general_settings;
|
||||
try {
|
||||
general_settings = load_general_settings();
|
||||
json::value enabled = general_settings[L"enabled"];
|
||||
for (auto enabled_element : enabled.as_object()) {
|
||||
if (enabled_element.second.as_bool()) {
|
||||
// Enable this powertoy.
|
||||
powertoys_to_enable.emplace(enabled_element.first);
|
||||
}
|
||||
}
|
||||
only_enable_some_powertoys = true;
|
||||
}
|
||||
catch (std::exception ex) {
|
||||
// Couldn't read the general settings correctly.
|
||||
// Load all powertoys.
|
||||
only_enable_some_powertoys = false;
|
||||
}
|
||||
|
||||
for (auto&[name, powertoy] : modules()) {
|
||||
if (only_enable_some_powertoys) {
|
||||
if (powertoys_to_enable.find(name)!=powertoys_to_enable.end()) {
|
||||
powertoy.enable();
|
||||
}
|
||||
} else {
|
||||
powertoy.enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user