[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:
Andrey Nekrasov
2024-04-02 01:09:47 +02:00
committed by GitHub
parent 818d3e3035
commit f23fa3f592
81 changed files with 2608 additions and 265 deletions

View File

@@ -63,9 +63,6 @@ public:
static HRESULT s_CreateInstance(_In_opt_ IUnknown* punkOuter, _In_ REFIID riid, _Outptr_ void** ppv);
static bool SetEnabled(_In_ bool enabled);
static bool IsEnabled();
private:
~CPowerRenameMenu();

View File

@@ -162,7 +162,7 @@ class PowerRenameModule : 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;
@@ -202,16 +202,13 @@ public:
package::RegisterSparsePackage(path, packageUri);
}
}
save_settings();
}
// Disable the powertoy
virtual void disable()
{
Logger::info(L"PowerRename disabled");
m_enabled = false;
save_settings();
Logger::info(L"PowerRename disabled");
}
// Returns if the powertoy is enabled
@@ -316,8 +313,6 @@ public:
void save_settings()
{
CSettingsInstance().SetEnabled(m_enabled);
CSettingsInstance().Save();
Trace::EnablePowerRename(m_enabled);
}

View File

@@ -33,9 +33,11 @@ namespace
CSettings::CSettings()
{
generalJsonFilePath = PTSettingsHelper::get_powertoys_general_save_file_location();
std::wstring result = PTSettingsHelper::get_module_save_folder_location(PowerRenameConstants::ModuleKey);
jsonFilePath = result + std::wstring(c_powerRenameDataFilePath);
moduleJsonFilePath = result + std::wstring(c_powerRenameDataFilePath);
UIFlagsFilePath = result + std::wstring(c_powerRenameUIFlagsFilePath);
RefreshEnabledState();
Load();
}
@@ -43,7 +45,6 @@ void CSettings::Save()
{
json::JsonObject jsonData;
jsonData.SetNamedValue(c_enabled, json::value(settings.enabled));
jsonData.SetNamedValue(c_showIconOnMenu, json::value(settings.showIconOnMenu));
jsonData.SetNamedValue(c_extendedContextMenuOnly, json::value(settings.extendedContextMenuOnly));
jsonData.SetNamedValue(c_persistState, json::value(settings.persistState));
@@ -51,13 +52,13 @@ void CSettings::Save()
jsonData.SetNamedValue(c_maxMRUSize, json::value(settings.maxMRUSize));
jsonData.SetNamedValue(c_useBoostLib, json::value(settings.useBoostLib));
json::to_file(jsonFilePath, jsonData);
json::to_file(moduleJsonFilePath, jsonData);
GetSystemTimeAsFileTime(&lastLoadedTime);
}
void CSettings::Load()
{
if (!std::filesystem::exists(jsonFilePath))
if (!std::filesystem::exists(moduleJsonFilePath))
{
MigrateFromRegistry();
@@ -71,20 +72,35 @@ void CSettings::Load()
}
}
void CSettings::Reload()
void CSettings::RefreshEnabledState()
{
// Load json settings from data file if it is modified in the meantime.
FILETIME lastModifiedTime{};
if (LastModifiedTime(jsonFilePath, &lastModifiedTime) &&
CompareFileTime(&lastModifiedTime, &lastLoadedTime) == 1)
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, L"enabled", modulesEnabledState, json::JsonObject{});
json::get(modulesEnabledState, L"PowerRename", settings.enabled, true);
}
catch (const winrt::hresult_error&)
{
Load();
}
}
void CSettings::MigrateFromRegistry()
{
settings.enabled = GetRegBoolean(c_enabled, true);
//settings.enabled = GetRegBoolean(c_enabled, true);
settings.showIconOnMenu = GetRegBoolean(c_showIconOnMenu, true);
settings.extendedContextMenuOnly = GetRegBoolean(c_extendedContextMenuOnly, false); // Disabled by default.
settings.persistState = GetRegBoolean(c_persistState, true);
@@ -100,16 +116,12 @@ void CSettings::MigrateFromRegistry()
void CSettings::ParseJson()
{
auto json = json::from_file(jsonFilePath);
auto json = json::from_file(moduleJsonFilePath);
if (json)
{
const json::JsonObject& jsonSettings = json.value();
try
{
if (json::has(jsonSettings, c_enabled, json::JsonValueType::Boolean))
{
settings.enabled = jsonSettings.GetNamedBoolean(c_enabled);
}
if (json::has(jsonSettings, c_showIconOnMenu, json::JsonValueType::Boolean))
{
settings.showIconOnMenu = jsonSettings.GetNamedBoolean(c_showIconOnMenu);

View File

@@ -15,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();
}
inline bool GetShowIconOnMenu() const
{
return settings.showIconOnMenu;
@@ -112,7 +106,7 @@ private:
unsigned int flags{ 0 };
};
void Reload();
void RefreshEnabledState();
void MigrateFromRegistry();
void ParseJson();
@@ -120,9 +114,11 @@ private:
void WriteFlags();
Settings settings;
std::wstring jsonFilePath;
std::wstring generalJsonFilePath;
std::wstring moduleJsonFilePath;
std::wstring UIFlagsFilePath;
FILETIME lastLoadedTime;
FILETIME lastLoadedTime{};
FILETIME lastLoadedGeneralSettingsTime{};
};
CSettings& CSettingsInstance();