mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[PowerRename]Save data from the last run outside of the settings file (#28861)
* [PowerRename] Sync settings before saving last window size * address review comments
This commit is contained in:
@@ -70,4 +70,40 @@ namespace json
|
||||
{
|
||||
return value; // identity function overload for convenience
|
||||
}
|
||||
|
||||
template<typename T, typename D = std::optional<T>>
|
||||
requires std::constructible_from<std::optional<T>, D>
|
||||
void get(const json::JsonObject& o, const wchar_t* name, T& destination, D default_value = std::nullopt)
|
||||
{
|
||||
try
|
||||
{
|
||||
if constexpr (std::is_same_v<T, bool>)
|
||||
{
|
||||
destination = o.GetNamedBoolean(name);
|
||||
}
|
||||
else if constexpr (std::is_arithmetic_v<T>)
|
||||
{
|
||||
destination = static_cast<T>(o.GetNamedNumber(name));
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, std::wstring>)
|
||||
{
|
||||
destination = o.GetNamedString(name);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, json::JsonObject>)
|
||||
{
|
||||
destination = o.GetNamedObject(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(std::bool_constant<std::is_same_v<T, T&>>::value, "Unsupported type");
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::optional<T> maybe_default{ std::move(default_value) };
|
||||
if (maybe_default.has_value())
|
||||
destination = std::move(*maybe_default);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user