plusui-native-core 0.1.55 β 0.1.57
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.
- package/Core/CMakeLists.txt +1 -1
- package/Core/Features/App/app.cpp +0 -56
- package/Core/Features/App/app.ts +3 -0
- package/Core/Features/Browser/browser.ts +6 -0
- package/Core/Features/Clipboard/clipboard.ts +3 -0
- package/Core/Features/Connection/README.md +50 -38
- package/Core/Features/Connection/connect.cpp +27 -50
- package/Core/Features/Connection/connect.ts +86 -0
- package/Core/Features/Display/display.ts +4 -0
- package/Core/Features/FileDrop/filedrop.ts +3 -0
- package/Core/Features/Keyboard/keyboard.ts +3 -0
- package/Core/Features/Menu/menu.ts +3 -0
- package/Core/Features/Tray/tray.ts +4 -0
- package/Core/Features/WebGPU/webgpu.ts +3 -0
- package/Core/Features/Window/window.cpp +176 -7
- package/Core/Features/Window/window.ts +4 -0
- package/Core/include/plusui/connect.hpp +150 -14
- package/Core/include/plusui/connection.hpp +3 -0
- package/Core/include/plusui/plusui.hpp +1 -0
- package/Core/include/plusui/window.hpp +3 -0
- package/package.json +1 -1
- package/Core/Features/Connection/ARCHITECTURE.md +0 -369
- package/Core/Features/Connection/examples/simple_tags_example.hpp +0 -130
- package/Core/Features/Connection/examples/simple_tags_example.ts +0 -247
- package/Core/generated/bridge.hpp +0 -302
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
# Connection Feature Architecture
|
|
2
|
-
|
|
3
|
-
## ποΈ System Overview
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
7
|
-
β PlusUI Connection Feature β
|
|
8
|
-
β Unified Frontend β Backend Communication β
|
|
9
|
-
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
10
|
-
|
|
11
|
-
ββββββββββββββββββββ ββββββββββββββββββββ
|
|
12
|
-
β Frontend (TS) β β Backend (C++) β
|
|
13
|
-
β β β β
|
|
14
|
-
β ββββββββββββββ β β ββββββββββββββ β
|
|
15
|
-
β β connect.* β β β β Bindings β β
|
|
16
|
-
β β API β β β β Class β β
|
|
17
|
-
β βββββββ¬βββββββ β β βββββββ¬βββββββ β
|
|
18
|
-
β β β β β β
|
|
19
|
-
β βββββββΌβββββββ β βββββββββββββββ β βββββββΌβββββββ β
|
|
20
|
-
β βConnection ββββΌββββΊβ WebView2 ββββββββββΌββΊβConnection β β
|
|
21
|
-
β β Client β β β IPC Layer β β β Protocol β β
|
|
22
|
-
β ββββββββββββββ β βββββββββββββββ β ββββββββββββββ β
|
|
23
|
-
β β β β
|
|
24
|
-
ββββββββββββββββββββ ββββββββββββββββββββ
|
|
25
|
-
|
|
26
|
-
βββββββββββββββββββ
|
|
27
|
-
β Schema File β
|
|
28
|
-
β connection. β
|
|
29
|
-
β schema β
|
|
30
|
-
ββββββββββ¬βββββββββ
|
|
31
|
-
β
|
|
32
|
-
ββββββββββΌβββββββββ
|
|
33
|
-
β Bindgen β
|
|
34
|
-
β Generator β
|
|
35
|
-
ββββββββββ¬βββββββββ
|
|
36
|
-
β
|
|
37
|
-
ββββββββββββββ΄βββββββββββββ
|
|
38
|
-
β β
|
|
39
|
-
ββββββββΌββββββ ββββββββΌβββββββ
|
|
40
|
-
βbindings.ts β βbindings.hpp β
|
|
41
|
-
β(Generated) β β (Generated) β
|
|
42
|
-
ββββββββββββββ βββββββββββββββ
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## π Communication Flow
|
|
46
|
-
|
|
47
|
-
### CALL Pattern (Request/Response)
|
|
48
|
-
```
|
|
49
|
-
Frontend Backend
|
|
50
|
-
β β
|
|
51
|
-
βββ[1] call(name, args)βββββΊβ
|
|
52
|
-
β β
|
|
53
|
-
β [2] handle_*
|
|
54
|
-
β β
|
|
55
|
-
ββββ[3] result ββββββββββββββ
|
|
56
|
-
β β
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### FIRE Pattern (One-way)
|
|
60
|
-
```
|
|
61
|
-
Frontend Backend
|
|
62
|
-
β β
|
|
63
|
-
βββ[1] fire(name, args)βββββΊβ
|
|
64
|
-
β β
|
|
65
|
-
β [2] handle_*
|
|
66
|
-
β β
|
|
67
|
-
β (no response) β
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### EVENT Pattern (Backend β Frontend)
|
|
71
|
-
```
|
|
72
|
-
Frontend Backend
|
|
73
|
-
β β
|
|
74
|
-
β [1] on(name, callback) β
|
|
75
|
-
β β
|
|
76
|
-
β β [2] emit_*
|
|
77
|
-
ββββ[3] event data ββββββββββ
|
|
78
|
-
β β
|
|
79
|
-
β [4] callback(data) β
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### STREAM Pattern (Continuous Data)
|
|
83
|
-
```
|
|
84
|
-
Frontend Backend
|
|
85
|
-
β β
|
|
86
|
-
β [1] stream.subscribe(cb) β
|
|
87
|
-
β β
|
|
88
|
-
β β [2] emit_* (repeated)
|
|
89
|
-
ββββ[3] data ββββββββββββββββ
|
|
90
|
-
ββββ[4] data ββββββββββββββββ
|
|
91
|
-
ββββ[5] data ββββββββββββββββ
|
|
92
|
-
β β
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### CHANNEL Pattern (Bidirectional Pub/Sub)
|
|
96
|
-
```
|
|
97
|
-
Frontend Backend
|
|
98
|
-
β β
|
|
99
|
-
βββ[1] channel.publish()ββββΊβ [2] handle_*_publish
|
|
100
|
-
β β
|
|
101
|
-
β [3] channel.subscribe() β
|
|
102
|
-
β β
|
|
103
|
-
ββββ[4] emit_* ββββββββββββββ
|
|
104
|
-
β β
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## π Build & Generation Flow
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
1. Developer writes schema
|
|
111
|
-
βββΊ connection.schema
|
|
112
|
-
|
|
113
|
-
2. Run connect generator tool
|
|
114
|
-
βββΊ node Tools/plusui-connector/src/connect.js
|
|
115
|
-
|
|
116
|
-
3. Parser reads schema
|
|
117
|
-
βββΊ Parses connect definitions
|
|
118
|
-
βββΊ Validates syntax
|
|
119
|
-
βββΊ Creates method definitions
|
|
120
|
-
|
|
121
|
-
4. Generator creates TypeScript
|
|
122
|
-
βββΊ Type definitions (GreetIn, GreetOut, etc.)
|
|
123
|
-
βββΊ connect.* API functions
|
|
124
|
-
βββΊ Typed callbacks
|
|
125
|
-
|
|
126
|
-
5. Generator creates C++
|
|
127
|
-
βββΊ Struct definitions with JSON converters
|
|
128
|
-
βββΊ Virtual handler methods
|
|
129
|
-
βββΊ Emit helper methods
|
|
130
|
-
βββΊ Message dispatcher
|
|
131
|
-
|
|
132
|
-
6. Files written
|
|
133
|
-
βββΊ Core/Features/Connection/generated/bindings.ts
|
|
134
|
-
βββΊ Core/Features/Connection/generated/bindings.hpp
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## π¦ Component Architecture
|
|
138
|
-
|
|
139
|
-
### TypeScript Side
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
143
|
-
β Generated API (bindings.ts) β
|
|
144
|
-
β ββββββββββββββββββββββββββββββββββ β
|
|
145
|
-
β β export const connect = { β β
|
|
146
|
-
β β greet: (args) => ..., β β
|
|
147
|
-
β β onResize: (cb) => ..., β β
|
|
148
|
-
β β cpuUsage: { subscribe }, β β
|
|
149
|
-
β β logBus: { subscribe, pub }, β β
|
|
150
|
-
β β } β β
|
|
151
|
-
β ββββββββββββββ¬ββββββββββββββββββββ β
|
|
152
|
-
βββββββββββββββββΌβββββββββββββββββββββββ
|
|
153
|
-
β uses
|
|
154
|
-
βΌ
|
|
155
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
156
|
-
β Core Connection (connection.ts) β
|
|
157
|
-
β ββββββββββββββββββββββββββββββββββ β
|
|
158
|
-
β β class ConnectionClient { β β
|
|
159
|
-
β β call(name, args) β β
|
|
160
|
-
β β fire(name, args) β β
|
|
161
|
-
β β on(name, callback) β β
|
|
162
|
-
β β stream(name) β β
|
|
163
|
-
β β channel(name) β β
|
|
164
|
-
β β } β β
|
|
165
|
-
β ββββββββββββββ¬ββββββββββββββββββββ β
|
|
166
|
-
βββββββββββββββββΌβββββββββββββββββββββββ
|
|
167
|
-
β sends/receives
|
|
168
|
-
βΌ
|
|
169
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
170
|
-
β Message Protocol β
|
|
171
|
-
β { β
|
|
172
|
-
β kind: "call" | "fire" | ..., β
|
|
173
|
-
β id: "...", β
|
|
174
|
-
β name: "methodName", β
|
|
175
|
-
β payload: { ... } β
|
|
176
|
-
β } β
|
|
177
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### C++ Side
|
|
181
|
-
|
|
182
|
-
```
|
|
183
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
184
|
-
β User Implementation β
|
|
185
|
-
β ββββββββββββββββββββββββββββββββββ β
|
|
186
|
-
β β class MyApp : public β β
|
|
187
|
-
β β plusui::connect::Bindings β β
|
|
188
|
-
β β { β β
|
|
189
|
-
β β GreetOut handle_greet(...) β β
|
|
190
|
-
β β void handle_log(...) β β
|
|
191
|
-
β β β β
|
|
192
|
-
β β void emitUpdate() { β β
|
|
193
|
-
β β emit_onResize({...}); β β
|
|
194
|
-
β β } β β
|
|
195
|
-
β β } β β
|
|
196
|
-
β ββββββββββββββ¬ββββββββββββββββββββ β
|
|
197
|
-
βββββββββββββββββΌβββββββββββββββββββββββ
|
|
198
|
-
β inherits
|
|
199
|
-
βΌ
|
|
200
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
201
|
-
β Generated Base (bindings.hpp) β
|
|
202
|
-
β ββββββββββββββββββββββββββββββββββ β
|
|
203
|
-
β β class Bindings : public β β
|
|
204
|
-
β β Connection { β β
|
|
205
|
-
β β β β
|
|
206
|
-
β β // Virtual handlers β β
|
|
207
|
-
β β virtual GreetOut handle_* β β
|
|
208
|
-
β β β β
|
|
209
|
-
β β // Emit methods β β
|
|
210
|
-
β β void emit_onResize(...) β β
|
|
211
|
-
β β β β
|
|
212
|
-
β β // Message dispatcher β β
|
|
213
|
-
β β void handleMessage(Envelope) β β
|
|
214
|
-
β β } β β
|
|
215
|
-
β ββββββββββββββ¬ββββββββββββββββββββ β
|
|
216
|
-
βββββββββββββββββΌβββββββββββββββββββββββ
|
|
217
|
-
β uses
|
|
218
|
-
βΌ
|
|
219
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
220
|
-
β Core Connect (connect.hpp) β
|
|
221
|
-
β ββββββββββββββββββββββββββββββββββ β
|
|
222
|
-
β β class Connection { β β
|
|
223
|
-
β β void send(Envelope) β β
|
|
224
|
-
β β void call(...) β β
|
|
225
|
-
β β void fire(...) β β
|
|
226
|
-
β β void event(...) β β
|
|
227
|
-
β β } β β
|
|
228
|
-
β ββββββββββββββββββββββββββββββββββ β
|
|
229
|
-
ββββββββββββββββββββββββββββββββββββββββ
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
## π Key Design Decisions
|
|
233
|
-
|
|
234
|
-
### 1. Schema-Driven
|
|
235
|
-
- **Why**: Single source of truth, prevents TS/C++ drift
|
|
236
|
-
- **Benefit**: Auto-generated types, less manual work
|
|
237
|
-
|
|
238
|
-
### 2. Strongly Typed
|
|
239
|
-
- **Why**: Catch errors at compile time
|
|
240
|
-
- **Benefit**: Better IDE support, safer code
|
|
241
|
-
|
|
242
|
-
### 3. Pattern-Based
|
|
243
|
-
- **Why**: Different use cases need different semantics
|
|
244
|
-
- **Benefit**: Clear intent, optimized for each pattern
|
|
245
|
-
|
|
246
|
-
### 4. Code Generation
|
|
247
|
-
- **Why**: Boilerplate is tedious and error-prone
|
|
248
|
-
- **Benefit**: Consistent, maintainable, fast development
|
|
249
|
-
|
|
250
|
-
### 5. Struct-Based (not JSON)
|
|
251
|
-
- **Why**: Type safety in C++
|
|
252
|
-
- **Benefit**: Compiler checks, clear interfaces
|
|
253
|
-
|
|
254
|
-
## π― Design Principles
|
|
255
|
-
|
|
256
|
-
1. **Simple Developer Experience**
|
|
257
|
-
- Minimal boilerplate
|
|
258
|
-
- Intuitive API
|
|
259
|
-
- Clear patterns
|
|
260
|
-
|
|
261
|
-
2. **Type Safety**
|
|
262
|
-
- End-to-end type checking
|
|
263
|
-
- Auto-generated types
|
|
264
|
-
- Compile-time validation
|
|
265
|
-
|
|
266
|
-
3. **Unified System**
|
|
267
|
-
- Single API for all patterns
|
|
268
|
-
- Consistent naming
|
|
269
|
-
- One import
|
|
270
|
-
|
|
271
|
-
4. **Framework Agnostic**
|
|
272
|
-
- Works with React, Vue, Svelte
|
|
273
|
-
- No framework lock-in
|
|
274
|
-
- Plain TypeScript/JavaScript
|
|
275
|
-
|
|
276
|
-
5. **Performance**
|
|
277
|
-
- Minimal overhead
|
|
278
|
-
- Efficient serialization
|
|
279
|
-
- Direct dispatch
|
|
280
|
-
|
|
281
|
-
## π Message Protocol
|
|
282
|
-
|
|
283
|
-
### Envelope Structure
|
|
284
|
-
```typescript
|
|
285
|
-
{
|
|
286
|
-
kind: "call" | "fire" | "result" | "event" | "stream" |
|
|
287
|
-
"sub" | "unsub" | "publish" | "error",
|
|
288
|
-
id?: string, // Request ID (for calls)
|
|
289
|
-
name: string, // Method/event name
|
|
290
|
-
payload: unknown, // Data
|
|
291
|
-
error?: string // Error message (if kind="error")
|
|
292
|
-
}
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### Message Kinds
|
|
296
|
-
- **call**: Request (needs response)
|
|
297
|
-
- **fire**: One-way command
|
|
298
|
-
- **result**: Response to call
|
|
299
|
-
- **event**: Backend notification
|
|
300
|
-
- **stream**: Continuous data
|
|
301
|
-
- **sub**: Subscribe to stream
|
|
302
|
-
- **unsub**: Unsubscribe from stream
|
|
303
|
-
- **publish**: Channel message
|
|
304
|
-
- **error**: Error response
|
|
305
|
-
|
|
306
|
-
## π Type Safety Flow
|
|
307
|
-
|
|
308
|
-
```
|
|
309
|
-
Schema Definition
|
|
310
|
-
β
|
|
311
|
-
Bindgen
|
|
312
|
-
β
|
|
313
|
-
ββββββββββββββββ
|
|
314
|
-
β TypeScript β
|
|
315
|
-
β - GreetIn β
|
|
316
|
-
β - GreetOut β
|
|
317
|
-
ββββββββββββββββ
|
|
318
|
-
β
|
|
319
|
-
Frontend Code
|
|
320
|
-
await connect.greet({ name: "..." })
|
|
321
|
-
β Type checked!
|
|
322
|
-
β
|
|
323
|
-
{ message: "..." }
|
|
324
|
-
β Type checked!
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
```
|
|
328
|
-
Schema Definition
|
|
329
|
-
β
|
|
330
|
-
Bindgen
|
|
331
|
-
β
|
|
332
|
-
ββββββββββββββββ
|
|
333
|
-
β C++ β
|
|
334
|
-
β - GreetIn β
|
|
335
|
-
β - GreetOut β
|
|
336
|
-
ββββββββββββββββ
|
|
337
|
-
β
|
|
338
|
-
Backend Code
|
|
339
|
-
GreetOut handle_greet(const GreetIn& args)
|
|
340
|
-
β Type checked!
|
|
341
|
-
return { "Hello" }
|
|
342
|
-
β Type checked!
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
## π Performance Characteristics
|
|
346
|
-
|
|
347
|
-
- **Call latency**: ~1-2ms (depends on WebView2)
|
|
348
|
-
- **Fire latency**: <1ms (fire-and-forget)
|
|
349
|
-
- **Event dispatch**: <0.1ms (in-process)
|
|
350
|
-
- **Serialization**: O(n) for payload size
|
|
351
|
-
- **Memory**: Minimal (shared memory for IPC)
|
|
352
|
-
|
|
353
|
-
## π§ Extension Points
|
|
354
|
-
|
|
355
|
-
Future enhancements:
|
|
356
|
-
- State synchronization (synced properties)
|
|
357
|
-
- Binary protocol option (faster than JSON)
|
|
358
|
-
- Compression for large payloads
|
|
359
|
-
- Message batching
|
|
360
|
-
- Request cancellation
|
|
361
|
-
- Middleware/interceptors
|
|
362
|
-
- RPC versioning
|
|
363
|
-
|
|
364
|
-
---
|
|
365
|
-
|
|
366
|
-
**See Also:**
|
|
367
|
-
- [README.md](README.md) - Complete guide
|
|
368
|
-
- [QUICK_REFERENCE.md](QUICK_REFERENCE.md) - Cheat sheet
|
|
369
|
-
- [MIGRATION.md](MIGRATION.md) - Migration from old system
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: Simple Tag-Based Connection (C++ Backend)
|
|
3
|
-
*
|
|
4
|
-
* No schema file needed! Just tag your methods and bindgen does the rest.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
#pragma once
|
|
8
|
-
#include <plusui/connect.hpp>
|
|
9
|
-
#include <string>
|
|
10
|
-
|
|
11
|
-
namespace example {
|
|
12
|
-
|
|
13
|
-
class SimpleApp : public plusui::Connect {
|
|
14
|
-
public:
|
|
15
|
-
|
|
16
|
-
// ============================================
|
|
17
|
-
// CONNECT_CALL: Request/Response
|
|
18
|
-
// Frontend can await the result
|
|
19
|
-
// ============================================
|
|
20
|
-
|
|
21
|
-
// Simple call with one parameter
|
|
22
|
-
CONNECT_CALL(greet, std::string, std::string name)
|
|
23
|
-
std::string greet(const std::string& name) {
|
|
24
|
-
return "Hello, " + name + "!";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Call with multiple parameters β returns object
|
|
28
|
-
CONNECT_CALL(calculate, double, double a, double b)
|
|
29
|
-
double calculate(double a, double b) {
|
|
30
|
-
return a + b;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Call with complex return (auto-generates struct)
|
|
34
|
-
CONNECT_CALL(getUser, {int id, std::string name, std::string email}, int userId)
|
|
35
|
-
auto getUser(int userId) {
|
|
36
|
-
struct Result { int id; std::string name; std::string email; };
|
|
37
|
-
return Result{ userId, "John Doe", "john@example.com" };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ============================================
|
|
41
|
-
// CONNECT_FIRE: One-way to Backend
|
|
42
|
-
// No response expected
|
|
43
|
-
// ============================================
|
|
44
|
-
|
|
45
|
-
CONNECT_FIRE(minimize, void)
|
|
46
|
-
void minimize() {
|
|
47
|
-
// Minimize window
|
|
48
|
-
std::cout << "Minimizing..." << std::endl;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
CONNECT_FIRE(log, void, std::string level, std::string message)
|
|
52
|
-
void log(const std::string& level, const std::string& message) {
|
|
53
|
-
std::cout << "[" << level << "] " << message << std::endl;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ============================================
|
|
57
|
-
// CONNECT_EVENT: Backend β Frontend
|
|
58
|
-
// Backend emits, frontend listens
|
|
59
|
-
// ============================================
|
|
60
|
-
|
|
61
|
-
CONNECT_EVENT(onResize, int width, int height)
|
|
62
|
-
void emitResize(int width, int height) {
|
|
63
|
-
// Auto-generated emit method
|
|
64
|
-
emit_onResize(width, height);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
CONNECT_EVENT(onFileDrop, std::vector<std::string> files)
|
|
68
|
-
void emitFileDrop(const std::vector<std::string>& files) {
|
|
69
|
-
emit_onFileDrop(files);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// ============================================
|
|
73
|
-
// CONNECT_STREAM: Continuous Data
|
|
74
|
-
// Backend streams, frontend subscribes
|
|
75
|
-
// ============================================
|
|
76
|
-
|
|
77
|
-
CONNECT_STREAM(cpuUsage, double percent)
|
|
78
|
-
void startMonitoring() {
|
|
79
|
-
// Stream CPU usage continuously
|
|
80
|
-
std::thread([this]() {
|
|
81
|
-
while (running) {
|
|
82
|
-
double cpu = getCpuUsage();
|
|
83
|
-
emit_cpuUsage(cpu);
|
|
84
|
-
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
85
|
-
}
|
|
86
|
-
}).detach();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ============================================
|
|
90
|
-
// CONNECT_CHANNEL: Bidirectional
|
|
91
|
-
// Both sides can send and receive
|
|
92
|
-
// ============================================
|
|
93
|
-
|
|
94
|
-
CONNECT_CHANNEL(logBus, std::string level, std::string line)
|
|
95
|
-
|
|
96
|
-
// Receive from frontend
|
|
97
|
-
void onLogFromFrontend(const std::string& level, const std::string& line) {
|
|
98
|
-
std::cout << "[Frontend] " << level << ": " << line << std::endl;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Send to frontend
|
|
102
|
-
void sendLogToFrontend(const std::string& level, const std::string& line) {
|
|
103
|
-
emit_logBus(level, line);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private:
|
|
107
|
-
bool running = true;
|
|
108
|
-
|
|
109
|
-
double getCpuUsage() {
|
|
110
|
-
return 50.0 + (rand() % 30);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
} // namespace example
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* This example shows how simple it is:
|
|
118
|
-
*
|
|
119
|
-
* 1. Tag your methods with CONNECT_* macros
|
|
120
|
-
* 2. Run: npm run bindgen
|
|
121
|
-
* 3. Use in TypeScript:
|
|
122
|
-
*
|
|
123
|
-
* const result = await connect.greet({ name: 'World' });
|
|
124
|
-
* connect.minimize();
|
|
125
|
-
* connect.onResize((w, h) => updateUI(w, h));
|
|
126
|
-
* connect.cpuUsage.subscribe((cpu) => showCpu(cpu));
|
|
127
|
-
* connect.logBus.publish({ level: 'info', line: 'msg' });
|
|
128
|
-
*
|
|
129
|
-
* That's it! No separate schema file, no manual typing.
|
|
130
|
-
*/
|