[Workspaces] Handle admin windows repositioning. (#34965)

This commit is contained in:
Seraphima Zykova
2024-09-25 12:13:38 +03:00
committed by GitHub
parent 499dc9bb7a
commit 1e18e83af6
65 changed files with 2531 additions and 891 deletions

View File

@@ -1,57 +0,0 @@
#pragma once
#include <vector>
#include <WorkspacesLib/WorkspacesData.h>
#include <common/logger/logger.h>
namespace WorkspacesJsonUtils
{
inline std::vector<WorkspacesData::WorkspacesProject> Read(const std::wstring& fileName)
{
std::vector<WorkspacesData::WorkspacesProject> projects{};
try
{
auto savedProjectsJson = json::from_file(fileName);
if (savedProjectsJson.has_value())
{
auto savedProjects = WorkspacesData::WorkspacesListJSON::FromJson(savedProjectsJson.value());
if (savedProjects.has_value())
{
projects = savedProjects.value();
}
}
}
catch (std::exception ex)
{
Logger::error("Error reading workspaces file. {}", ex.what());
}
return projects;
}
inline void Write(const std::wstring& fileName, const std::vector<WorkspacesData::WorkspacesProject>& projects)
{
try
{
json::to_file(fileName, WorkspacesData::WorkspacesListJSON::ToJson(projects));
}
catch (std::exception ex)
{
Logger::error("Error writing workspaces file. {}", ex.what());
}
}
inline void Write(const std::wstring& fileName, const WorkspacesData::WorkspacesProject& project)
{
try
{
json::to_file(fileName, WorkspacesData::WorkspacesProjectJSON::ToJson(project));
}
catch (std::exception ex)
{
Logger::error("Error writing workspaces file. {}", ex.what());
}
}
}

View File

@@ -133,7 +133,6 @@
<ClCompile Include="SnapshotUtils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="JsonUtils.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="resource.base.h" />
<ClInclude Include="SnapshotUtils.h" />

View File

@@ -18,9 +18,6 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="JsonUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SnapshotUtils.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@@ -5,21 +5,21 @@
#include <workspaces-common/GuidUtils.h>
#include <workspaces-common/MonitorUtils.h>
#include <WorkspacesLib/JsonUtils.h>
#include <WorkspacesLib/WorkspacesData.h>
#include <JsonUtils.h>
#include <SnapshotUtils.h>
#include <common/utils/gpo.h>
#include <common/utils/logger_helper.h>
#include <common/utils/UnhandledExceptionHandler.h>
const std::wstring moduleName = L"Workspaces\\ProjectsSnapshotTool";
const std::wstring moduleName = L"Workspaces\\WorkspacesSnapshotTool";
const std::wstring internalPath = L"";
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdLine, int cmdShow)
{
LoggerHelpers::init_logger(moduleName, internalPath, LogSettings::workspacesLauncherLoggerName);
LoggerHelpers::init_logger(moduleName, internalPath, LogSettings::workspacesSnapshotToolLoggerName);
InitUnhandledExceptionHandler();
if (powertoys_gpo::getConfiguredWorkspacesEnabledValue() == powertoys_gpo::gpo_rule_configured_disabled)
@@ -46,14 +46,6 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdLine, int cm
return -1;
}
std::wstring fileName = WorkspacesData::WorkspacesFile();
std::string cmdLineStr(cmdLine);
if (!cmdLineStr.empty())
{
std::wstring fileNameParam(cmdLineStr.begin(), cmdLineStr.end());
fileName = fileNameParam;
}
// create new project
time_t creationTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
WorkspacesData::WorkspacesProject project{ .id = CreateGuidString(), .creationTime = creationTime };
@@ -75,7 +67,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdLine, int cm
return monitorNumber;
});
WorkspacesJsonUtils::Write(WorkspacesData::TempWorkspacesFile(), project);
JsonUtils::Write(WorkspacesData::TempWorkspacesFile(), project);
Logger::trace(L"WorkspacesProject {}:{} created", project.name, project.id);
CoUninitialize();