nits, cleanup
This commit is contained in:
parent
ccbcb425da
commit
14d21f492b
|
@ -4,7 +4,6 @@
|
|||
#include "pch.h"
|
||||
#include "BaseApplicationState.h"
|
||||
#include "CascadiaSettings.h"
|
||||
// #include "ApplicationState.g.cpp"
|
||||
|
||||
#include "JsonUtils.h"
|
||||
#include "FileUtils.h"
|
||||
|
@ -12,13 +11,14 @@
|
|||
constexpr std::wstring_view stateFileName{ L"state.json" };
|
||||
using namespace ::Microsoft::Terminal::Settings::Model;
|
||||
|
||||
// namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||
// {
|
||||
BaseApplicationState::BaseApplicationState(std::filesystem::path path) noexcept :
|
||||
_path{ std::move(path) },
|
||||
_throttler{ std::chrono::seconds(1), [this]() { _write(); } }
|
||||
{
|
||||
// _read();
|
||||
// DON'T _read() here! _read() will call FromJson, which is virtual, and
|
||||
// needs to be implemented in a derived class. Classes that derive from
|
||||
// BaseApplicationState should make sure to call Reload() after construction
|
||||
// to ensure the data is loaded.
|
||||
}
|
||||
|
||||
// The destructor ensures that the last write is flushed to disk before returning.
|
||||
|
@ -80,4 +80,3 @@ try
|
|||
WriteUTF8FileAtomic(_path, content);
|
||||
}
|
||||
CATCH_LOG()
|
||||
// }
|
||||
|
|
|
@ -11,93 +11,6 @@
|
|||
|
||||
constexpr std::wstring_view stateFileName{ L"elevated-state.json" };
|
||||
|
||||
namespace Microsoft::Terminal::Settings::Model::JsonUtils
|
||||
{
|
||||
// This trait exists in order to serialize the std::unordered_set for GeneratedProfiles.
|
||||
template<typename T>
|
||||
struct ConversionTrait<std::unordered_set<T>>
|
||||
{
|
||||
std::unordered_set<T> FromJson(const Json::Value& json) const
|
||||
{
|
||||
ConversionTrait<T> trait;
|
||||
std::unordered_set<T> val;
|
||||
val.reserve(json.size());
|
||||
|
||||
for (const auto& element : json)
|
||||
{
|
||||
val.emplace(trait.FromJson(element));
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
bool CanConvert(const Json::Value& json) const
|
||||
{
|
||||
ConversionTrait<T> trait;
|
||||
return json.isArray() && std::all_of(json.begin(), json.end(), [trait](const auto& json) -> bool { return trait.CanConvert(json); });
|
||||
}
|
||||
|
||||
Json::Value ToJson(const std::unordered_set<T>& val)
|
||||
{
|
||||
ConversionTrait<T> trait;
|
||||
Json::Value json{ Json::arrayValue };
|
||||
|
||||
for (const auto& key : val)
|
||||
{
|
||||
json.append(trait.ToJson(key));
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
std::string TypeDescription() const
|
||||
{
|
||||
return fmt::format("{}[]", ConversionTrait<GUID>{}.TypeDescription());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConversionTrait<winrt::Windows::Foundation::Collections::IVector<T>>
|
||||
{
|
||||
winrt::Windows::Foundation::Collections::IVector<T> FromJson(const Json::Value& json) const
|
||||
{
|
||||
ConversionTrait<T> trait;
|
||||
std::vector<T> val;
|
||||
val.reserve(json.size());
|
||||
|
||||
for (const auto& element : json)
|
||||
{
|
||||
val.push_back(trait.FromJson(element));
|
||||
}
|
||||
|
||||
return winrt::single_threaded_vector(move(val));
|
||||
}
|
||||
|
||||
bool CanConvert(const Json::Value& json) const
|
||||
{
|
||||
ConversionTrait<T> trait;
|
||||
return json.isArray() && std::all_of(json.begin(), json.end(), [trait](const auto& json) -> bool { return trait.CanConvert(json); });
|
||||
}
|
||||
|
||||
Json::Value ToJson(const winrt::Windows::Foundation::Collections::IVector<T>& val)
|
||||
{
|
||||
ConversionTrait<T> trait;
|
||||
Json::Value json{ Json::arrayValue };
|
||||
|
||||
for (const auto& key : val)
|
||||
{
|
||||
json.append(trait.ToJson(key));
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
std::string TypeDescription() const
|
||||
{
|
||||
return fmt::format("vector ({})", ConversionTrait<T>{}.TypeDescription());
|
||||
}
|
||||
};
|
||||
}
|
||||
using namespace ::Microsoft::Terminal::Settings::Model;
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||
|
|
Loading…
Reference in a new issue