plusui-native-core 0.1.52 → 0.1.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/Core/CMakeLists.txt +2 -3
  2. package/Core/Features/App/app.cpp +58 -1
  3. package/Core/Features/Connection/ARCHITECTURE.md +369 -0
  4. package/Core/Features/Connection/README.md +165 -0
  5. package/Core/Features/Connection/connection.cpp +57 -0
  6. package/Core/Features/Connection/connection.ts +186 -0
  7. package/Core/Features/Connection/examples/simple_tags_example.hpp +130 -0
  8. package/Core/Features/Connection/examples/simple_tags_example.ts +247 -0
  9. package/Core/Features/Window/window.cpp +187 -151
  10. package/Core/generated/bridge.hpp +302 -0
  11. package/Core/include/plusui/connection.hpp +145 -0
  12. package/Core/include/plusui/plusui.hpp +1 -3
  13. package/Core/include/plusui/window.hpp +17 -19
  14. package/package.json +1 -1
  15. package/Core/Features/Bindings/ARCHITECTURE.md +0 -328
  16. package/Core/Features/Bindings/CustomBindings/custom_bindings.cpp +0 -55
  17. package/Core/Features/Bindings/CustomBindings/custom_bindings.ts +0 -35
  18. package/Core/Features/Bindings/EXAMPLE_USAGE.hpp +0 -143
  19. package/Core/Features/Bindings/EXAMPLE_USAGE.tsx +0 -210
  20. package/Core/Features/Bindings/IPC_GUIDE.md +0 -325
  21. package/Core/Features/Bindings/NativeBindings/native_bindings.cpp +0 -30
  22. package/Core/Features/Bindings/NativeBindings/native_bindings.ts +0 -29
  23. package/Core/Features/Bindings/UNIFIED_SYSTEM.md +0 -351
  24. package/Core/Features/Event/Events.ts +0 -166
  25. package/Core/Features/Event/events.cpp +0 -200
  26. package/Core/include/plusui/bindings.hpp +0 -65
  27. package/Core/include/plusui/custom_bindings.hpp +0 -17
  28. package/Core/include/plusui/events.hpp +0 -58
@@ -0,0 +1,302 @@
1
+ /**
2
+ * Auto-generated by plusui-bindgen
3
+ * DO NOT EDIT - Changes will be overwritten
4
+ * Generated from: connection.schema
5
+ */
6
+ #pragma once
7
+ #include <plusui/connection.hpp>
8
+ #include <string>
9
+ #include <vector>
10
+
11
+ namespace plusui {
12
+ namespace connect {
13
+
14
+ // ============================================
15
+ // Type Definitions
16
+ // ============================================
17
+
18
+ struct GreetIn {
19
+ std::string name;
20
+
21
+ static GreetIn from_json(const nlohmann::json& j) {
22
+ GreetIn result;
23
+ if (j.contains("name")) { result.name = j["name"]; }
24
+ return result;
25
+ }
26
+
27
+ nlohmann::json to_json() const {
28
+ nlohmann::json j;
29
+ j["name"] = name;
30
+ return j;
31
+ }
32
+ };
33
+
34
+ struct GreetOut {
35
+ std::string message;
36
+
37
+ static GreetOut from_json(const nlohmann::json& j) {
38
+ GreetOut result;
39
+ if (j.contains("message")) { result.message = j["message"]; }
40
+ return result;
41
+ }
42
+
43
+ nlohmann::json to_json() const {
44
+ nlohmann::json j;
45
+ j["message"] = message;
46
+ return j;
47
+ }
48
+ };
49
+
50
+ struct LogIn {
51
+ std::string msg;
52
+
53
+ static LogIn from_json(const nlohmann::json& j) {
54
+ LogIn result;
55
+ if (j.contains("msg")) { result.msg = j["msg"]; }
56
+ return result;
57
+ }
58
+
59
+ nlohmann::json to_json() const {
60
+ nlohmann::json j;
61
+ j["msg"] = msg;
62
+ return j;
63
+ }
64
+ };
65
+
66
+ struct OnResizeIn {
67
+ double width;
68
+ double height;
69
+
70
+ static OnResizeIn from_json(const nlohmann::json& j) {
71
+ OnResizeIn result;
72
+ if (j.contains("width")) { result.width = j["width"]; }
73
+ if (j.contains("height")) { result.height = j["height"]; }
74
+ return result;
75
+ }
76
+
77
+ nlohmann::json to_json() const {
78
+ nlohmann::json j;
79
+ j["width"] = width;
80
+ j["height"] = height;
81
+ return j;
82
+ }
83
+ };
84
+
85
+ struct OnResizeData {
86
+ double width;
87
+ double height;
88
+
89
+ static OnResizeData from_json(const nlohmann::json& j) {
90
+ OnResizeData result;
91
+ if (j.contains("width")) { result.width = j["width"]; }
92
+ if (j.contains("height")) { result.height = j["height"]; }
93
+ return result;
94
+ }
95
+
96
+ nlohmann::json to_json() const {
97
+ nlohmann::json j;
98
+ j["width"] = width;
99
+ j["height"] = height;
100
+ return j;
101
+ }
102
+ };
103
+
104
+ struct OnFileDropIn {
105
+ nlohmann::json files;
106
+
107
+ static OnFileDropIn from_json(const nlohmann::json& j) {
108
+ OnFileDropIn result;
109
+ if (j.contains("files")) { result.files = j["files"]; }
110
+ return result;
111
+ }
112
+
113
+ nlohmann::json to_json() const {
114
+ nlohmann::json j;
115
+ j["files"] = files;
116
+ return j;
117
+ }
118
+ };
119
+
120
+ struct OnFileDropData {
121
+ nlohmann::json files;
122
+
123
+ static OnFileDropData from_json(const nlohmann::json& j) {
124
+ OnFileDropData result;
125
+ if (j.contains("files")) { result.files = j["files"]; }
126
+ return result;
127
+ }
128
+
129
+ nlohmann::json to_json() const {
130
+ nlohmann::json j;
131
+ j["files"] = files;
132
+ return j;
133
+ }
134
+ };
135
+
136
+ struct CpuUsageIn {
137
+ double percent;
138
+
139
+ static CpuUsageIn from_json(const nlohmann::json& j) {
140
+ CpuUsageIn result;
141
+ if (j.contains("percent")) { result.percent = j["percent"]; }
142
+ return result;
143
+ }
144
+
145
+ nlohmann::json to_json() const {
146
+ nlohmann::json j;
147
+ j["percent"] = percent;
148
+ return j;
149
+ }
150
+ };
151
+
152
+ struct CpuUsageData {
153
+ double percent;
154
+
155
+ static CpuUsageData from_json(const nlohmann::json& j) {
156
+ CpuUsageData result;
157
+ if (j.contains("percent")) { result.percent = j["percent"]; }
158
+ return result;
159
+ }
160
+
161
+ nlohmann::json to_json() const {
162
+ nlohmann::json j;
163
+ j["percent"] = percent;
164
+ return j;
165
+ }
166
+ };
167
+
168
+ struct LogBusIn {
169
+ std::string level;
170
+ std::string line;
171
+
172
+ static LogBusIn from_json(const nlohmann::json& j) {
173
+ LogBusIn result;
174
+ if (j.contains("level")) { result.level = j["level"]; }
175
+ if (j.contains("line")) { result.line = j["line"]; }
176
+ return result;
177
+ }
178
+
179
+ nlohmann::json to_json() const {
180
+ nlohmann::json j;
181
+ j["level"] = level;
182
+ j["line"] = line;
183
+ return j;
184
+ }
185
+ };
186
+
187
+ struct LogBusData {
188
+ std::string level;
189
+ std::string line;
190
+
191
+ static LogBusData from_json(const nlohmann::json& j) {
192
+ LogBusData result;
193
+ if (j.contains("level")) { result.level = j["level"]; }
194
+ if (j.contains("line")) { result.line = j["line"]; }
195
+ return result;
196
+ }
197
+
198
+ nlohmann::json to_json() const {
199
+ nlohmann::json j;
200
+ j["level"] = level;
201
+ j["line"] = line;
202
+ return j;
203
+ }
204
+ };
205
+
206
+ // ============================================
207
+ // Generated Bindings Base Class
208
+ // ============================================
209
+
210
+ /**
211
+ * Auto-generated connection bindings
212
+ * Inherit from this class and implement the handler methods
213
+ */
214
+ class Bindings : public Connection {
215
+ public:
216
+
217
+ // ========================================
218
+ // Handler Methods (implement these)
219
+ // ========================================
220
+
221
+ /** [CALL] greet - Request/response handler */
222
+ virtual GreetOut handle_greet(const GreetIn& args) = 0;
223
+
224
+ /** [FIRE] log - One-way handler */
225
+ virtual void handle_log(const LogIn& args) = 0;
226
+
227
+ /** [FIRE] minimize - One-way handler */
228
+ virtual void handle_minimize() = 0;
229
+
230
+ /** [CHANNEL] logBus - Publish handler */
231
+ virtual void handle_logBus_publish(const LogBusData& data) = 0;
232
+
233
+ // ========================================
234
+ // Emit Methods (call these to send to frontend)
235
+ // ========================================
236
+
237
+ /** [EVENT] onResize - Emit to frontend */
238
+ void emit_onResize(const OnResizeData& data) {
239
+ auto payload = data.to_json();
240
+ event("onResize", payload);
241
+ }
242
+
243
+ /** [EVENT] onFileDrop - Emit to frontend */
244
+ void emit_onFileDrop(const OnFileDropData& data) {
245
+ auto payload = data.to_json();
246
+ event("onFileDrop", payload);
247
+ }
248
+
249
+ /** [STREAM] cpuUsage - Emit to frontend */
250
+ void emit_cpuUsage(const CpuUsageData& data) {
251
+ auto payload = data.to_json();
252
+ stream("cpuUsage", payload);
253
+ }
254
+
255
+ /** [CHANNEL] logBus - Emit to frontend */
256
+ void emit_logBus(const LogBusData& data) {
257
+ auto payload = data.to_json();
258
+ publish("logBus", payload);
259
+ }
260
+
261
+ protected:
262
+ // ========================================
263
+ // Message Dispatcher (auto-generated)
264
+ // ========================================
265
+
266
+ void handleMessage(const std::string &name, const nlohmann::json &payload) override {
267
+ try {
268
+ // TODO: Update bindgen to generate simplified handlers
269
+ // For now, all messages are treated as events
270
+
271
+ if (name == "greet") {
272
+ auto args = GreetIn::from_json(payload);
273
+ auto res = handle_greet(args);
274
+ emit("greetResult", res.to_json());
275
+ return;
276
+ }
277
+
278
+ if (name == "log") {
279
+ auto args = LogIn::from_json(payload);
280
+ handle_log(args);
281
+ return;
282
+ }
283
+
284
+ if (name == "minimize") {
285
+ handle_minimize();
286
+ return;
287
+ }
288
+
289
+ if (name == "logBus") {
290
+ auto data = LogBusData::from_json(payload);
291
+ handle_logBus_publish(data);
292
+ return;
293
+ }
294
+ } catch (const std::exception& e) {
295
+ // Error handling simplified - just log or ignore
296
+ // sendError(env.id, env.name, std::string("Handler error: ") + e.what());
297
+ }
298
+ }
299
+ };
300
+
301
+ } // namespace connect
302
+ } // namespace plusui
@@ -0,0 +1,145 @@
1
+ #pragma once
2
+
3
+ #include <functional>
4
+ #include <nlohmann/json.hpp>
5
+ #include <string>
6
+
7
+ // ============================================
8
+ // PlusUI Connection Feature
9
+ // ============================================
10
+ //
11
+ // TWO METHODS. FIVE PRIMITIVES. EVERYTHING YOU NEED.
12
+ //
13
+ // Mirror API - same methods on both sides:
14
+ // Frontend: connect.emit(name, data) → Backend: emit(name, data)
15
+ // Frontend: connect.on(name, callback) → Backend: handleMessage(name, data)
16
+ //
17
+ // ============================================
18
+ // THE 5 PRIMITIVES
19
+ // ============================================
20
+ //
21
+ // 1. EVENT - Fire & forget, one way →
22
+ // Frontend: connect.emit('notification', { message: 'Done!' })
23
+ // Backend: emit("notification", {{"message", "Done!"}});
24
+ //
25
+ // 2. CALL - Request/response, two ways ↔
26
+ // Frontend: connect.emit('getUser', { id: 123 })
27
+ // connect.on('userData', (data) => { ... })
28
+ // Backend: handleMessage("getUser", payload) → emit("userData", {...})
29
+ //
30
+ // 3. STREAM - Continuous data, one way push →
31
+ // Backend: emit("cpu-usage", {{"percent", 45}}); // called repeatedly
32
+ // Frontend: connect.on('cpu-usage', (data) => { ... })
33
+ //
34
+ // 4. QUERY - Request + stream, two way + many ↔↔↔
35
+ // Frontend: connect.emit('search', { query: 'test' })
36
+ // connect.on('searchResult', (item) => { ... }) // fires multiple times
37
+ // Backend: handleMessage("search", payload) → emit("searchResult", item1)
38
+ // emit("searchResult", item2) ...
39
+ //
40
+ // 5. STATE - Synced value, both ways ↕
41
+ // Both sides can emit and receive the same message:
42
+ // connect.emit('theme', { mode: 'dark' })
43
+ // connect.on('theme', (data) => { ... })
44
+ //
45
+ // ============================================
46
+ // BASIC USAGE
47
+ // ============================================
48
+ //
49
+ // class MyConnection : public plusui::Connection {
50
+ // protected:
51
+ // void handleMessage(const std::string& name, const nlohmann::json& data) override {
52
+ // if (name == "greet") {
53
+ // auto userName = data["name"].get<std::string>();
54
+ // emit("greeting", {{"message", "Hello " + userName + "!"}});
55
+ // }
56
+ // }
57
+ // };
58
+ //
59
+ // ============================================
60
+
61
+ namespace plusui {
62
+
63
+ class Connection {
64
+ std::function<void(const std::string &)> outboundHandler;
65
+
66
+ public:
67
+ virtual ~Connection() = default;
68
+
69
+ // Setup the outbound message handler
70
+ void setOutbound(std::function<void(const std::string &)> h) {
71
+ outboundHandler = std::move(h);
72
+ }
73
+
74
+ void setOutboundHandler(std::function<void(const std::string &)> h) {
75
+ setOutbound(std::move(h));
76
+ }
77
+
78
+ /**
79
+ * emit() - Send a message to the frontend
80
+ *
81
+ * Works for all 5 primitives:
82
+ * - EVENT: emit("notification", {{"msg", "Hi!"}})
83
+ * - CALL: emit("response", {{"data", 123}})
84
+ * - STREAM: emit("updates", {{"value", x}}) // call repeatedly
85
+ * - QUERY: emit("result", item) // call for each result
86
+ * - STATE: emit("theme", {{"mode", "dark"}})
87
+ */
88
+ void emit(const std::string &name, const nlohmann::json &payload) {
89
+ if (!outboundHandler) {
90
+ return;
91
+ }
92
+
93
+ nlohmann::json j;
94
+ j["kind"] = "event";
95
+ j["name"] = name;
96
+ j["payload"] = payload;
97
+
98
+ outboundHandler(j.dump());
99
+ }
100
+
101
+ // Parse and dispatch incoming messages from frontend
102
+ void dispatchMessage(const std::string &message) {
103
+ try {
104
+ auto j = nlohmann::json::parse(message);
105
+ std::string name = j.value("name", "");
106
+ nlohmann::json payload = j.value("payload", nlohmann::json::object());
107
+
108
+ if (!name.empty()) {
109
+ handleMessage(name, payload);
110
+ }
111
+ } catch (...) {
112
+ // Silently ignore malformed messages
113
+ }
114
+ }
115
+
116
+ void dispatch(const std::string &message) { dispatchMessage(message); }
117
+
118
+ protected:
119
+ /**
120
+ * handleMessage() - Receive messages from the frontend
121
+ *
122
+ * Override this to handle incoming messages. This is your "on()" equivalent.
123
+ *
124
+ * Works for all 5 primitives:
125
+ * - EVENT: Just receive and act
126
+ * - CALL: Receive request, emit() response
127
+ * - STREAM: Receive subscription, emit() repeatedly
128
+ * - QUERY: Receive query, emit() multiple results
129
+ * - STATE: Receive update, optionally emit() back
130
+ *
131
+ * Example:
132
+ * void handleMessage(const std::string& name, const nlohmann::json& data) override {
133
+ * if (name == "greet") {
134
+ * auto userName = data["name"].get<std::string>();
135
+ * emit("greeting", {{"message", "Hello " + userName}});
136
+ * }
137
+ * }
138
+ */
139
+ virtual void handleMessage(const std::string &name, const nlohmann::json &payload) = 0;
140
+ };
141
+
142
+ // Legacy alias for backwards compatibility
143
+ using Bridge = Connection;
144
+
145
+ } // namespace plusui
@@ -23,12 +23,10 @@
23
23
  */
24
24
 
25
25
  #include <plusui/app.hpp>
26
- #include <plusui/bindings.hpp>
27
26
  #include <plusui/browser.hpp>
28
27
  #include <plusui/clipboard.hpp>
29
- #include <plusui/custom_bindings.hpp>
28
+ #include <plusui/connection.hpp>
30
29
  #include <plusui/display.hpp>
31
- #include <plusui/events.hpp>
32
30
  #include <plusui/filedrop.hpp>
33
31
  #include <plusui/keyboard.hpp>
34
32
  #include <plusui/menu.hpp>
@@ -34,8 +34,9 @@ struct WindowConfig {
34
34
  bool skipTaskbar = false;
35
35
  double opacity = 1.0;
36
36
  bool fullscreen = false;
37
- bool enableFileDrop = true; // Enable native FileDrop API (auto-disables webview drag-drop)
38
-
37
+ bool enableFileDrop =
38
+ true; // Enable native FileDrop API (auto-disables webview drag-drop)
39
+
39
40
  // WebView properties
40
41
  std::string userAgent = "";
41
42
  bool devtools = true;
@@ -45,9 +46,10 @@ struct WindowConfig {
45
46
  bool allowFileAccess = false;
46
47
  bool allowRemoteContent = true;
47
48
  std::string dataPath = "";
48
- int cacheSize = 100; // MB
49
- bool scrollbars = true; // Show/hide scrollbars
50
- bool disableWebviewDragDrop = true; // Disable webview drag-drop (usually set by enableFileDrop)
49
+ int cacheSize = 100; // MB
50
+ bool scrollbars = true; // Show/hide scrollbars
51
+ bool disableWebviewDragDrop =
52
+ true; // Disable webview drag-drop (usually set by enableFileDrop)
51
53
  };
52
54
 
53
55
  struct WindowState {
@@ -128,6 +130,9 @@ public:
128
130
  void onFocus(FocusCallback callback);
129
131
  void onStateChange(StateCallback callback);
130
132
 
133
+ using FileDropCallback = std::function<void(const std::string &)>;
134
+ void onFileDrop(FileDropCallback callback);
135
+
131
136
  void *nativeHandle() const;
132
137
 
133
138
  void setWindow(std::shared_ptr<Window> win);
@@ -138,7 +143,6 @@ public:
138
143
  using ErrorCallback = std::function<void(const std::string &error, int code)>;
139
144
  using ConsoleCallback = std::function<void(
140
145
  const std::string &message, int level, const std::string &source)>;
141
- using JSCallback = std::function<std::string(const std::string &args)>;
142
146
  using NavigationCallback = std::function<bool(const std::string &url)>;
143
147
  using LoadCallback = std::function<void()>;
144
148
 
@@ -168,22 +172,11 @@ public:
168
172
  return std::future<T>();
169
173
  }
170
174
 
171
- // Bindings
172
- void bind(const std::string &name, JSCallback callback);
173
- void unbind(const std::string &name);
174
-
175
- template <typename F> void expose(const std::string &name, F &&callback) {
176
- // Implementation for simplified expose
177
- }
178
-
179
175
  // Dev tools
180
176
  void openDevTools();
181
177
  void closeDevTools();
182
178
 
183
- // Events
184
- void on(const std::string &event,
185
- std::function<void(const std::string &)> callback);
186
- void emit(const std::string &event, const std::string &data = "");
179
+ // WebView settings
187
180
 
188
181
  // WebView settings
189
182
  void setUserAgent(const std::string &userAgent);
@@ -191,7 +184,12 @@ public:
191
184
  void setZoom(double factor);
192
185
  double getZoom() const;
193
186
  void injectCSS(const std::string &css);
194
- void setWebviewDragDropEnabled(bool enabled); // Enable/disable webview drag-drop at runtime
187
+ void setWebviewDragDropEnabled(
188
+ bool enabled); // Enable/disable webview drag-drop at runtime
189
+
190
+ using MessageCallback = std::function<void(const std::string &)>;
191
+ void onMessage(MessageCallback callback);
192
+ void postMessage(const std::string &message);
195
193
 
196
194
  // WebView callbacks
197
195
  void onNavigationStart(NavigationCallback callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.52",
3
+ "version": "0.1.53",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "files": [