Release KSwitcher v0.6.65
This commit is contained in:
1 parent
14f33012a3
commit
8a65e7f7fb
21 files changed
+570
-111
No files matched your search
+19
-6
@@ -216,7 +216,20 @@ std::unique_ptr<SyncProvider> makeSyncProvider(const SyncConfig &c, SyncTranspor
|
||||
{
|
||||
return std::make_unique<OpenBao>(c, std::move(transport));
|
||||
}
|
||||
namespace { Json canonicalProfile(Json); }
|
||||
namespace {
|
||||
Json canonicalProfile(Json);
|
||||
constexpr const char *PreviouslyLocalSettings[] = {
|
||||
"startWithSystem", "autostartAsAdministrator", "tesseractPath", "useTesseract",
|
||||
"historyEnabled", "maxItems", "maxTotalMegabytes", "maxImageMegabytes", "writeLog", "preventScreenLock",
|
||||
"appLanguageSets", "mouseBindings", "disabledMouseProfiles", "mouseProfileApplications", "customMouseEvents"
|
||||
};
|
||||
|
||||
void preserveMissingSettings(Json &profile, const Json &fallback)
|
||||
{
|
||||
for (auto key : PreviouslyLocalSettings)
|
||||
if (!profile.contains(key) && fallback.contains(key)) profile[key] = fallback.at(key);
|
||||
}
|
||||
}
|
||||
Bytes sharedSyncSettings(const Settings &s)
|
||||
{
|
||||
auto j = parse(encodeSettings(s));
|
||||
@@ -226,14 +239,12 @@ Bytes sharedSyncSettings(const Settings &s)
|
||||
std::sort(bindings.begin(), bindings.end(), [](const Json &a, const Json &b) {
|
||||
return a.at("layoutId").get<std::string>() < b.at("layoutId").get<std::string>();
|
||||
});
|
||||
for (auto key : {"startWithSystem", "autostartAsAdministrator", "tesseractPath", "useTesseract",
|
||||
"historyEnabled", "maxItems", "maxTotalMegabytes", "maxImageMegabytes", "writeLog", "preventScreenLock",
|
||||
"appLanguageSets", "mouseBindings", "disabledMouseProfiles", "mouseProfileApplications"}) j.erase(key);
|
||||
return bytes(canonicalProfile(j));
|
||||
}
|
||||
Settings restoreSyncSettings(const Bytes &shared, const Settings &local, const std::vector<Layout> &layouts, bool keepLocalLayouts)
|
||||
{
|
||||
auto j = parse(shared), original = parse(encodeSettings(local));
|
||||
preserveMissingSettings(j, original);
|
||||
if (!j.contains("snippetTombstones")) j["snippetTombstones"] = Json::array();
|
||||
if (!j.contains("autoCorrectReplace")) j["autoCorrectReplace"] = false;
|
||||
if (!j.contains("autoCorrectTypos")) j["autoCorrectTypos"] = false;
|
||||
@@ -245,7 +256,7 @@ Settings restoreSyncSettings(const Bytes &shared, const Settings &local, const s
|
||||
if (!j.is_object() || j.value("format", "") != "kswitcher-settings" || j.value("schemaVersion", 0) != 1)
|
||||
throw std::runtime_error("Unsupported synchronized settings format.");
|
||||
for (auto it = j.begin(); it != j.end(); ++it)
|
||||
if (!allowed.contains(it.key())) throw std::runtime_error("Remote profile contains unsupported or local-only fields.");
|
||||
if (!allowed.contains(it.key())) throw std::runtime_error("Remote profile contains unsupported fields.");
|
||||
if (j.size() != allowed.size()) throw std::runtime_error("Remote profile is incomplete.");
|
||||
std::set<std::string> installed;
|
||||
for (const auto &layout : layouts) installed.insert(utf8(layout.id));
|
||||
@@ -307,7 +318,9 @@ SyncResult synchronize(SyncProvider &provider, const Bytes &base, const Bytes &l
|
||||
else
|
||||
{
|
||||
auto profile = parse(action == SyncAction::Download ? remote.settings : mergeLocal);
|
||||
if (!profile.contains("chatCycles")) profile["chatCycles"] = parse(local).value("chatCycles", Json::object());
|
||||
const auto current = parse(local);
|
||||
if (!profile.contains("chatCycles")) profile["chatCycles"] = current.value("chatCycles", Json::object());
|
||||
preserveMissingSettings(profile, current);
|
||||
auto selected = bytes(normalizeProfile(profile));
|
||||
merged = {selected, selected, selected, {}};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user