mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 01:36:31 +02:00
[DSC] Implement Microsoft.PowerToys.Configure DSCResource & winget support (#30918)
* [DSC] Microsoft.PowerToys.Configure module + winget configuration file support
* f: fix for an incorrect directory id reference
* f: update comment
* f: address review comments
* f: file locksmith bug fix
* f: add explorer preview switches in samples
* f: remove debug
* Sign DSC files
* f: implement docs/samples generator
* [ci]Sign FancyZonesEditorCommon.dll
* Sign DSC files in the Generated folder
* f: address review comments
* f: update usable options
* f: add autogenerated sample
* [Installer] Don't use same GUID for different components
* [Installer]Don't remove folders shared by other modules
* Allow configuring PTRun MaximumNumberOfResults
* Remove all settings DSC sample. Just random data
* Allow configuring Hosts Run as Administrator
* Revert "[Installer]Don't remove folders shared by other modules"
This reverts commit 6da3d6cfd5.
* Add all PTRun plugins and Global and keyboard to DSC sample
* Fix issues with context menu modules not disabling
* Fix default enabled values when setting with DSC
* Fix tests regarding default modules in Settings
* Fix merge error
* Restart PowerToys process if we stopped it
---------
Co-authored-by: Andrey Nekrasov <1828123+yuyoyuppe@users.noreply.github.com>
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
@@ -11,7 +11,8 @@ namespace
|
||||
{
|
||||
const wchar_t c_imageResizerDataFilePath[] = L"\\image-resizer-settings.json";
|
||||
const wchar_t c_rootRegPath[] = L"Software\\Microsoft\\ImageResizer";
|
||||
const wchar_t c_enabled[] = L"Enabled";
|
||||
const wchar_t c_enabled[] = L"enabled";
|
||||
const wchar_t c_ImageResizer[] = L"Image Resizer";
|
||||
|
||||
unsigned int RegReadInteger(const std::wstring& valueName, unsigned int defaultValue)
|
||||
{
|
||||
@@ -45,6 +46,7 @@ namespace
|
||||
|
||||
CSettings::CSettings()
|
||||
{
|
||||
generalJsonFilePath = PTSettingsHelper::get_powertoys_general_save_file_location();
|
||||
std::wstring oldSavePath = PTSettingsHelper::get_module_save_folder_location(ImageResizerConstants::ModuleOldSaveFolderKey);
|
||||
std::wstring savePath = PTSettingsHelper::get_module_save_folder_location(ImageResizerConstants::ModuleSaveFolderKey);
|
||||
std::error_code ec;
|
||||
@@ -62,8 +64,6 @@ void CSettings::Save()
|
||||
{
|
||||
json::JsonObject jsonData;
|
||||
|
||||
jsonData.SetNamedValue(c_enabled, json::value(settings.enabled));
|
||||
|
||||
json::to_file(jsonFilePath, jsonData);
|
||||
GetSystemTimeAsFileTime(&lastLoadedTime);
|
||||
}
|
||||
@@ -82,6 +82,32 @@ void CSettings::Load()
|
||||
}
|
||||
}
|
||||
|
||||
void CSettings::RefreshEnabledState()
|
||||
{
|
||||
// Load json settings from data file if it is modified in the meantime.
|
||||
FILETIME lastModifiedTime{};
|
||||
if (!(LastModifiedTime(generalJsonFilePath, &lastModifiedTime) &&
|
||||
CompareFileTime(&lastModifiedTime, &lastLoadedGeneralSettingsTime) == 1))
|
||||
return;
|
||||
|
||||
lastLoadedGeneralSettingsTime = lastModifiedTime;
|
||||
|
||||
auto json = json::from_file(generalJsonFilePath);
|
||||
if (!json)
|
||||
return;
|
||||
|
||||
const json::JsonObject& jsonSettings = json.value();
|
||||
try
|
||||
{
|
||||
json::JsonObject modulesEnabledState;
|
||||
json::get(jsonSettings, c_enabled, modulesEnabledState, json::JsonObject{});
|
||||
json::get(modulesEnabledState, c_ImageResizer, settings.enabled, true);
|
||||
}
|
||||
catch (const winrt::hresult_error&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void CSettings::Reload()
|
||||
{
|
||||
// Load json settings from data file if it is modified in the meantime.
|
||||
@@ -106,10 +132,7 @@ void CSettings::ParseJson()
|
||||
const json::JsonObject& jsonSettings = json.value();
|
||||
try
|
||||
{
|
||||
if (json::has(jsonSettings, c_enabled, json::JsonValueType::Boolean))
|
||||
{
|
||||
settings.enabled = jsonSettings.GetNamedBoolean(c_enabled);
|
||||
}
|
||||
// NB: add any new settings here
|
||||
}
|
||||
catch (const winrt::hresult_error&)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
#include <common/utils/gpo.h>
|
||||
|
||||
class CSettings
|
||||
@@ -14,16 +15,10 @@ public:
|
||||
return true;
|
||||
if (gpoSetting == powertoys_gpo::gpo_rule_configured_disabled)
|
||||
return false;
|
||||
Reload();
|
||||
RefreshEnabledState();
|
||||
return settings.enabled;
|
||||
}
|
||||
|
||||
inline void SetEnabled(bool enabled)
|
||||
{
|
||||
settings.enabled = enabled;
|
||||
Save();
|
||||
}
|
||||
|
||||
void Save();
|
||||
void Load();
|
||||
|
||||
@@ -33,13 +28,16 @@ private:
|
||||
bool enabled{ true };
|
||||
};
|
||||
|
||||
void RefreshEnabledState();
|
||||
void Reload();
|
||||
void MigrateFromRegistry();
|
||||
void ParseJson();
|
||||
|
||||
Settings settings;
|
||||
std::wstring jsonFilePath;
|
||||
std::wstring generalJsonFilePath;
|
||||
FILETIME lastLoadedTime;
|
||||
FILETIME lastLoadedGeneralSettingsTime{};
|
||||
};
|
||||
|
||||
CSettings& CSettingsInstance();
|
||||
@@ -37,7 +37,7 @@ class ImageResizerModule : public PowertoyModuleIface
|
||||
{
|
||||
private:
|
||||
// Enabled by default
|
||||
bool m_enabled = true;
|
||||
bool m_enabled = false;
|
||||
std::wstring app_name;
|
||||
//contains the non localized key of the powertoy
|
||||
std::wstring app_key;
|
||||
@@ -101,7 +101,6 @@ public:
|
||||
virtual void enable()
|
||||
{
|
||||
m_enabled = true;
|
||||
CSettingsInstance().SetEnabled(m_enabled);
|
||||
|
||||
if (package::IsWin11OrGreater())
|
||||
{
|
||||
@@ -121,7 +120,6 @@ public:
|
||||
virtual void disable()
|
||||
{
|
||||
m_enabled = false;
|
||||
CSettingsInstance().SetEnabled(m_enabled);
|
||||
Trace::EnableImageResizer(m_enabled);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user