mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
move DeleteFancyZonesRegistryData to proper place add logging
This commit is contained in:
@@ -162,6 +162,9 @@ public:
|
|||||||
m_settings = MakeFancyZonesSettings(reinterpret_cast<HINSTANCE>(&__ImageBase), FancyZonesModule::get_name(), FancyZonesModule::get_key());
|
m_settings = MakeFancyZonesSettings(reinterpret_cast<HINSTANCE>(&__ImageBase), FancyZonesModule::get_name(), FancyZonesModule::get_key());
|
||||||
FancyZonesDataInstance().LoadFancyZonesData();
|
FancyZonesDataInstance().LoadFancyZonesData();
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
||||||
|
// TODO: consider removing this call since the registry hasn't been used since 0.15
|
||||||
|
DeleteFancyZonesRegistryData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -942,7 +942,7 @@ void FancyZones::AddZoneWindow(HMONITOR monitor, const std::wstring& deviceId) n
|
|||||||
if (workArea)
|
if (workArea)
|
||||||
{
|
{
|
||||||
m_workAreaHandler.AddWorkArea(m_currentDesktopId, monitor, workArea);
|
m_workAreaHandler.AddWorkArea(m_currentDesktopId, monitor, workArea);
|
||||||
FancyZonesDataInstance().SaveFancyZonesData();
|
FancyZonesDataInstance().SaveZoneSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <common/utils/process_path.h>
|
#include <common/utils/process_path.h>
|
||||||
|
#include <common/logger/logger.h>
|
||||||
|
|
||||||
// Non-localizable strings
|
// Non-localizable strings
|
||||||
namespace NonLocalizable
|
namespace NonLocalizable
|
||||||
@@ -222,7 +223,10 @@ void FancyZonesData::UpdatePrimaryDesktopData(const std::wstring& desktopId)
|
|||||||
auto replaceDesktopId = [&desktopId](const std::wstring& deviceId) {
|
auto replaceDesktopId = [&desktopId](const std::wstring& deviceId) {
|
||||||
return deviceId.substr(0, deviceId.rfind('_') + 1) + desktopId;
|
return deviceId.substr(0, deviceId.rfind('_') + 1) + desktopId;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::scoped_lock lock{ dataLock };
|
std::scoped_lock lock{ dataLock };
|
||||||
|
bool dirtyFlag = false;
|
||||||
|
|
||||||
for (auto& [path, perDesktopData] : appZoneHistoryMap)
|
for (auto& [path, perDesktopData] : appZoneHistoryMap)
|
||||||
{
|
{
|
||||||
for (auto& data : perDesktopData)
|
for (auto& data : perDesktopData)
|
||||||
@@ -230,30 +234,42 @@ void FancyZonesData::UpdatePrimaryDesktopData(const std::wstring& desktopId)
|
|||||||
if (ExtractVirtualDesktopId(data.deviceId) == NonLocalizable::DefaultGuid)
|
if (ExtractVirtualDesktopId(data.deviceId) == NonLocalizable::DefaultGuid)
|
||||||
{
|
{
|
||||||
data.deviceId = replaceDesktopId(data.deviceId);
|
data.deviceId = replaceDesktopId(data.deviceId);
|
||||||
|
dirtyFlag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::wstring> toReplace{};
|
std::vector<std::wstring> toReplace{};
|
||||||
|
|
||||||
for (const auto& [id, data] : deviceInfoMap)
|
for (const auto& [id, data] : deviceInfoMap)
|
||||||
{
|
{
|
||||||
if (ExtractVirtualDesktopId(id) == NonLocalizable::DefaultGuid)
|
if (ExtractVirtualDesktopId(id) == NonLocalizable::DefaultGuid)
|
||||||
{
|
{
|
||||||
toReplace.push_back(id);
|
toReplace.push_back(id);
|
||||||
|
dirtyFlag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& id : toReplace)
|
for (const auto& id : toReplace)
|
||||||
{
|
{
|
||||||
auto mapEntry = deviceInfoMap.extract(id);
|
auto mapEntry = deviceInfoMap.extract(id);
|
||||||
mapEntry.key() = replaceDesktopId(id);
|
mapEntry.key() = replaceDesktopId(id);
|
||||||
deviceInfoMap.insert(std::move(mapEntry));
|
deviceInfoMap.insert(std::move(mapEntry));
|
||||||
}
|
}
|
||||||
SaveFancyZonesData();
|
|
||||||
|
// TODO: when updating the primary desktop GUID, the app zone history also needs to be updated
|
||||||
|
if (dirtyFlag)
|
||||||
|
{
|
||||||
|
SaveZoneSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZonesData::RemoveDeletedDesktops(const std::vector<std::wstring>& activeDesktops)
|
void FancyZonesData::RemoveDeletedDesktops(const std::vector<std::wstring>& activeDesktops)
|
||||||
{
|
{
|
||||||
std::unordered_set<std::wstring> active(std::begin(activeDesktops), std::end(activeDesktops));
|
std::unordered_set<std::wstring> active(std::begin(activeDesktops), std::end(activeDesktops));
|
||||||
std::scoped_lock lock{ dataLock };
|
std::scoped_lock lock{ dataLock };
|
||||||
|
bool dirtyFlag = false;
|
||||||
|
|
||||||
for (auto it = std::begin(deviceInfoMap); it != std::end(deviceInfoMap);)
|
for (auto it = std::begin(deviceInfoMap); it != std::end(deviceInfoMap);)
|
||||||
{
|
{
|
||||||
std::wstring desktopId = ExtractVirtualDesktopId(it->first);
|
std::wstring desktopId = ExtractVirtualDesktopId(it->first);
|
||||||
@@ -264,12 +280,17 @@ void FancyZonesData::RemoveDeletedDesktops(const std::vector<std::wstring>& acti
|
|||||||
{
|
{
|
||||||
RemoveDesktopAppZoneHistory(desktopId);
|
RemoveDesktopAppZoneHistory(desktopId);
|
||||||
it = deviceInfoMap.erase(it);
|
it = deviceInfoMap.erase(it);
|
||||||
|
dirtyFlag = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
SaveFancyZonesData();
|
|
||||||
|
if (dirtyFlag)
|
||||||
|
{
|
||||||
|
SaveAppZoneHistoryAndZoneSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FancyZonesData::IsAnotherWindowOfApplicationInstanceZoned(HWND window, const std::wstring_view& deviceId) const
|
bool FancyZonesData::IsAnotherWindowOfApplicationInstanceZoned(HWND window, const std::wstring_view& deviceId) const
|
||||||
@@ -392,7 +413,7 @@ bool FancyZonesData::RemoveAppLastZone(HWND window, const std::wstring_view& dev
|
|||||||
{
|
{
|
||||||
appZoneHistoryMap.erase(processPath);
|
appZoneHistoryMap.erase(processPath);
|
||||||
}
|
}
|
||||||
SaveFancyZonesData();
|
SaveAppZoneHistory();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -436,7 +457,7 @@ bool FancyZonesData::SetAppLastZones(HWND window, const std::wstring& deviceId,
|
|||||||
data.processIdToHandleMap[processId] = window;
|
data.processIdToHandleMap[processId] = window;
|
||||||
data.zoneSetUuid = zoneSetId;
|
data.zoneSetUuid = zoneSetId;
|
||||||
data.zoneIndexSet = zoneIndexSet;
|
data.zoneIndexSet = zoneIndexSet;
|
||||||
SaveFancyZonesData();
|
SaveAppZoneHistory();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -460,7 +481,7 @@ bool FancyZonesData::SetAppLastZones(HWND window, const std::wstring& deviceId,
|
|||||||
appZoneHistoryMap[processPath] = std::vector<FancyZonesDataTypes::AppZoneHistoryData>{ data };
|
appZoneHistoryMap[processPath] = std::vector<FancyZonesDataTypes::AppZoneHistoryData>{ data };
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveFancyZonesData();
|
SaveAppZoneHistory();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +504,7 @@ void FancyZonesData::LoadFancyZonesData()
|
|||||||
{
|
{
|
||||||
if (!std::filesystem::exists(zonesSettingsFileName))
|
if (!std::filesystem::exists(zonesSettingsFileName))
|
||||||
{
|
{
|
||||||
SaveFancyZonesData();
|
SaveAppZoneHistoryAndZoneSettings();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -493,25 +514,24 @@ void FancyZonesData::LoadFancyZonesData()
|
|||||||
deviceInfoMap = JSONHelpers::ParseDeviceInfos(fancyZonesDataJSON);
|
deviceInfoMap = JSONHelpers::ParseDeviceInfos(fancyZonesDataJSON);
|
||||||
customZoneSetsMap = JSONHelpers::ParseCustomZoneSets(fancyZonesDataJSON);
|
customZoneSetsMap = JSONHelpers::ParseCustomZoneSets(fancyZonesDataJSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteFancyZonesRegistryData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZonesData::SaveFancyZonesData() const
|
void FancyZonesData::SaveAppZoneHistoryAndZoneSettings() const
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{ dataLock };
|
SaveZoneSettings();
|
||||||
JSONHelpers::SaveZoneSettings(zonesSettingsFileName, deviceInfoMap, customZoneSetsMap);
|
SaveAppZoneHistory();
|
||||||
JSONHelpers::SaveAppZoneHistory(appZoneHistoryFileName, appZoneHistoryMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZonesData::SaveZoneSettings() const
|
void FancyZonesData::SaveZoneSettings() const
|
||||||
{
|
{
|
||||||
|
Logger::trace("FancyZonesData::SaveZoneSettings()");
|
||||||
std::scoped_lock lock{ dataLock };
|
std::scoped_lock lock{ dataLock };
|
||||||
JSONHelpers::SaveZoneSettings(zonesSettingsFileName, deviceInfoMap, customZoneSetsMap);
|
JSONHelpers::SaveZoneSettings(zonesSettingsFileName, deviceInfoMap, customZoneSetsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZonesData::SaveAppZoneHistory() const
|
void FancyZonesData::SaveAppZoneHistory() const
|
||||||
{
|
{
|
||||||
|
Logger::trace("FancyZonesData::SaveAppZoneHistory()");
|
||||||
std::scoped_lock lock{ dataLock };
|
std::scoped_lock lock{ dataLock };
|
||||||
JSONHelpers::SaveAppZoneHistory(appZoneHistoryFileName, appZoneHistoryMap);
|
JSONHelpers::SaveAppZoneHistory(appZoneHistoryFileName, appZoneHistoryMap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
json::JsonObject GetPersistFancyZonesJSON();
|
json::JsonObject GetPersistFancyZonesJSON();
|
||||||
|
|
||||||
void LoadFancyZonesData();
|
void LoadFancyZonesData();
|
||||||
void SaveFancyZonesData() const;
|
void SaveAppZoneHistoryAndZoneSettings() const;
|
||||||
void SaveZoneSettings() const;
|
void SaveZoneSettings() const;
|
||||||
void SaveAppZoneHistory() const;
|
void SaveAppZoneHistory() const;
|
||||||
|
|
||||||
|
|||||||
@@ -1727,7 +1727,7 @@ namespace FancyZonesUnitTests
|
|||||||
data.SetSettingsModulePath(m_moduleName);
|
data.SetSettingsModulePath(m_moduleName);
|
||||||
const auto& jsonPath = data.zonesSettingsFileName;
|
const auto& jsonPath = data.zonesSettingsFileName;
|
||||||
|
|
||||||
data.SaveFancyZonesData();
|
data.SaveAppZoneHistoryAndZoneSettings();
|
||||||
bool actual = std::filesystem::exists(jsonPath);
|
bool actual = std::filesystem::exists(jsonPath);
|
||||||
|
|
||||||
Assert::IsTrue(actual);
|
Assert::IsTrue(actual);
|
||||||
@@ -1751,7 +1751,7 @@ namespace FancyZonesUnitTests
|
|||||||
// write json with templates to file
|
// write json with templates to file
|
||||||
json::to_file(jsonPath, expectedJsonObj);
|
json::to_file(jsonPath, expectedJsonObj);
|
||||||
|
|
||||||
data.SaveFancyZonesData();
|
data.SaveAppZoneHistoryAndZoneSettings();
|
||||||
|
|
||||||
// verify that file was written successfully
|
// verify that file was written successfully
|
||||||
Assert::IsTrue(std::filesystem::exists(jsonPath));
|
Assert::IsTrue(std::filesystem::exists(jsonPath));
|
||||||
|
|||||||
Reference in New Issue
Block a user