mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-29 01:02:44 +08:00
[feat] add HarmonyOS desktop and mobile clients,issue #117
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* @Author: DI JUNKUN
|
||||
* @Date: 2026-10-15
|
||||
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _WINDOW_MODE_H_
|
||||
#define _WINDOW_MODE_H_
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace crossdesk::harmony::desktop {
|
||||
// Slint setters synchronously notify the platform one property at a time.
|
||||
// A native state snapshot must be acknowledged atomically without echoing
|
||||
// those intermediate combinations back to the native compositor.
|
||||
class WindowMode {
|
||||
nlohmann::json known_ = nlohmann::json::object();
|
||||
bool acknowledging_ = false;
|
||||
public:
|
||||
nlohmann::json Request(const nlohmann::json& desired) {
|
||||
auto changes = nlohmann::json::object();
|
||||
if (acknowledging_) return changes;
|
||||
for (const auto& [name, value] : desired.items())
|
||||
if (!known_.contains(name) || known_.at(name) != value) changes[name] = value;
|
||||
known_ = desired;
|
||||
return changes;
|
||||
}
|
||||
template <typename Apply>
|
||||
void Acknowledge(const nlohmann::json& actual, Apply apply) {
|
||||
known_.update(actual);
|
||||
struct Reset { bool& flag; ~Reset() { flag = false; } } reset{acknowledging_};
|
||||
acknowledging_ = true;
|
||||
apply();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user