mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[FancyZones] Refactor/improve saving JSON files (#8947)
* Divide SaveFancyZonesData into two functions
* Removed unused function, continued refactoring
* Use SaveAppZoneHistory in some places
* Revert "Use SaveAppZoneHistory in some places"
This reverts commit 74a4a1e467.
* Only save files if the contents are about to be changed
* Restore FileWatcher
This commit is contained in:
@@ -532,17 +532,10 @@ namespace JSONHelpers
|
||||
}
|
||||
}
|
||||
|
||||
void SaveFancyZonesData(const std::wstring& zonesSettingsFileName,
|
||||
const std::wstring& appZoneHistoryFileName,
|
||||
const TDeviceInfoMap& deviceInfoMap,
|
||||
const TCustomZoneSetsMap& customZoneSetsMap,
|
||||
const TAppZoneHistoryMap& appZoneHistoryMap)
|
||||
|
||||
void SaveZoneSettings(const std::wstring& zonesSettingsFileName, const TDeviceInfoMap& deviceInfoMap, const TCustomZoneSetsMap& customZoneSetsMap)
|
||||
{
|
||||
json::JsonObject root{};
|
||||
json::JsonObject appZoneHistoryRoot{};
|
||||
|
||||
appZoneHistoryRoot.SetNamedValue(NonLocalizable::AppZoneHistoryStr, JSONHelpers::SerializeAppZoneHistory(appZoneHistoryMap));
|
||||
root.SetNamedValue(NonLocalizable::DevicesStr, JSONHelpers::SerializeDeviceInfos(deviceInfoMap));
|
||||
root.SetNamedValue(NonLocalizable::CustomZoneSetsStr, JSONHelpers::SerializeCustomZoneSets(customZoneSetsMap));
|
||||
|
||||
@@ -550,10 +543,21 @@ namespace JSONHelpers
|
||||
if (!before.has_value() || before.value().Stringify() != root.Stringify())
|
||||
{
|
||||
Trace::FancyZones::DataChanged();
|
||||
json::to_file(zonesSettingsFileName, root);
|
||||
}
|
||||
}
|
||||
|
||||
json::to_file(zonesSettingsFileName, root);
|
||||
json::to_file(appZoneHistoryFileName, appZoneHistoryRoot);
|
||||
void SaveAppZoneHistory(const std::wstring& appZoneHistoryFileName, const TAppZoneHistoryMap& appZoneHistoryMap)
|
||||
{
|
||||
json::JsonObject root{};
|
||||
|
||||
root.SetNamedValue(NonLocalizable::AppZoneHistoryStr, JSONHelpers::SerializeAppZoneHistory(appZoneHistoryMap));
|
||||
|
||||
auto before = json::from_file(appZoneHistoryFileName);
|
||||
if (!before.has_value() || before.value().Stringify() != root.Stringify())
|
||||
{
|
||||
json::to_file(appZoneHistoryFileName, root);
|
||||
}
|
||||
}
|
||||
|
||||
TAppZoneHistoryMap ParseAppZoneHistory(const json::JsonObject& fancyZonesDataJSON)
|
||||
|
||||
Reference in New Issue
Block a user