plusui-native 0.2.72 → 0.2.74

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native",
3
- "version": "0.2.72",
3
+ "version": "0.2.74",
4
4
  "description": "PlusUI CLI - Build C++ desktop apps modern UI ",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -27,11 +27,11 @@
27
27
  "semver": "^7.6.0",
28
28
  "which": "^4.0.0",
29
29
  "execa": "^8.0.1",
30
- "plusui-native-builder": "^0.1.71",
31
- "plusui-native-connect": "^0.1.71"
30
+ "plusui-native-builder": "^0.1.73",
31
+ "plusui-native-connect": "^0.1.73"
32
32
  },
33
33
  "peerDependencies": {
34
- "plusui-native-connect": "^0.1.71"
34
+ "plusui-native-connect": "^0.1.73"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
package/src/index.js CHANGED
@@ -250,14 +250,57 @@ function findVcvarsall() {
250
250
  return null;
251
251
  }
252
252
 
253
+ // Capture the full environment from vcvarsall.bat (cached per session)
254
+ let _vcEnvCache = undefined;
255
+ function getVcEnvironment() {
256
+ if (_vcEnvCache !== undefined) return _vcEnvCache;
257
+
258
+ if (process.platform !== 'win32') {
259
+ _vcEnvCache = null;
260
+ return null;
261
+ }
262
+
263
+ const vcvarsall = findVcvarsall();
264
+ if (!vcvarsall) {
265
+ _vcEnvCache = null;
266
+ return null;
267
+ }
268
+
269
+ try {
270
+ // Run vcvarsall and dump all environment variables
271
+ const output = execSync(
272
+ `cmd /c ""${vcvarsall}" x64 >nul 2>&1 && set"`,
273
+ { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 30000, shell: true }
274
+ );
275
+
276
+ // Parse "KEY=VALUE" lines into an env object
277
+ const env = {};
278
+ for (const line of output.split(/\r?\n/)) {
279
+ const idx = line.indexOf('=');
280
+ if (idx > 0) {
281
+ env[line.substring(0, idx)] = line.substring(idx + 1);
282
+ }
283
+ }
284
+
285
+ // Sanity check: we should have PATH and INCLUDE set
286
+ if (env.PATH && env.INCLUDE) {
287
+ _vcEnvCache = env;
288
+ return env;
289
+ }
290
+ } catch { }
291
+
292
+ _vcEnvCache = null;
293
+ return null;
294
+ }
295
+
253
296
  function runCMake(args, options = {}) {
254
297
  const cmake = getCMakePath();
255
298
 
256
- // On Windows, wrap cmake in vcvarsall to ensure cl.exe is in PATH (needed for Ninja)
299
+ // On Windows, use the captured vcvarsall environment so cl.exe + ninja are in PATH
257
300
  if (process.platform === 'win32') {
258
- const vcvarsall = findVcvarsall();
259
- if (vcvarsall) {
260
- return execSync(`cmd /c ""${vcvarsall}" x64 >nul 2>&1 && "${cmake}" ${args}"`, { stdio: 'inherit', shell: true, ...options });
301
+ const vcEnv = getVcEnvironment();
302
+ if (vcEnv) {
303
+ return execSync(`"${cmake}" ${args}`, { stdio: 'inherit', env: vcEnv, ...options });
261
304
  }
262
305
  }
263
306
 
@@ -114,12 +114,13 @@ struct WebGPUConfig {
114
114
  // MAIN - Application Entry Point
115
115
  // ============================================================================
116
116
  // ── Connect instance ─────────────────────────────────────────────────────────
117
- // connect is the bridge between C++ and the frontend.
117
+ // conn is the bridge between C++ and the frontend.
118
118
  // Run `plusui connect` to generate Connections/ from your name.on / name.emit usage.
119
- // Then declare: Connections ch(connect);
120
- // and use: ch.myEvent.on([](const json& p) { ... });
121
- // ch.myEvent.emit({{"value", 42}});
122
- static Connect connect;
119
+ // Call initChannels(conn) once, then use channels directly:
120
+ // customFileDrop.on([](const json& p) { ... });
121
+ // customFileDrop.emit({{"value", 42}});
122
+ static Connect conn;
123
+ using json = nlohmann::json;
123
124
 
124
125
  int main() {
125
126
  // Build the app with configuration
@@ -191,12 +192,12 @@ int main() {
191
192
  // ========================================
192
193
  // CONNECT — bind frontend ↔ backend
193
194
  // ========================================
194
- // Wires the connect object to this window.
195
- // Connections ch gives you named channel objects — same API as TypeScript:
196
- // ch.myEvent.on([](const json& p) { ... }); // receive from frontend
197
- // ch.myEvent.emit({{"value", 42}}); // send to frontend
198
- bindConnect(mainWindow, connect);
199
- Connections ch(connect); // use ch.name.on() / ch.name.emit()
195
+ // Wires the connect object to this window, then initialises
196
+ // the auto-generated channels so you can use them directly:
197
+ // customFileDrop.on([](const json& p) { ... });
198
+ // customFileDrop.emit({{"value", 42}});
199
+ bindConnect(mainWindow, conn);
200
+ initChannels(conn);
200
201
 
201
202
  // ========================================
202
203
  // CUSTOM FILE DROP CHANNEL
@@ -205,7 +206,7 @@ int main() {
205
206
  // Frontend drops files → emits via customFileDrop.emit({ files: [...] })
206
207
  // C++ receives here, processes, then emits back to the frontend.
207
208
  // Frontend receives the reply via customFileDrop.on() in App.tsx.
208
- ch.customFileDrop.on([&ch](const json& payload) {
209
+ customFileDrop.on([](const json& payload) {
209
210
  auto files = payload.value("files", json::array());
210
211
  int count = static_cast<int>(files.size());
211
212
  std::cout << "customFileDrop: received " << count << " file(s) from frontend" << std::endl;
@@ -213,7 +214,7 @@ int main() {
213
214
  std::cout << " - " << f.value("name", "?") << " (" << f.value("size", 0) << " bytes)" << std::endl;
214
215
  }
215
216
  // Reply back to frontend — received by customFileDrop.on() in App.tsx
216
- ch.customFileDrop.emit({
217
+ customFileDrop.emit({
217
218
  {"processed", true},
218
219
  {"count", count},
219
220
  {"message", "C++ received " + std::to_string(count) + " file(s)"}
@@ -237,10 +238,10 @@ int main() {
237
238
  //
238
239
  // CONNECT (custom channels — same API on both sides):
239
240
  // Run `plusui connect` to generate Connections/ from your name.on / name.emit calls.
240
- // C++: ch.myEvent.on([](const json& p) { ... }); // receive
241
- // ch.myEvent.emit({{"value", 42}}); // send
242
- // TS: myEvent.on((data) => { ... }); // receive
243
- // myEvent.emit({ value: 42 }); // send
241
+ // C++: customFileDrop.on([](const json& p) { ... }); // receive
242
+ // customFileDrop.emit({{"value", 42}}); // send
243
+ // TS: customFileDrop.on((data) => { ... }); // receive
244
+ // customFileDrop.emit({ value: 42 }); // send
244
245
  //
245
246
  // WINDOW: win.minimize(), win.maximize(), win.close(), win.center(),
246
247
  // win.setSize(w, h), win.setPosition(x, y), win.setTitle(str),
@@ -113,12 +113,13 @@ struct WebGPUConfig {
113
113
  // MAIN - Application Entry Point
114
114
  // ============================================================================
115
115
  // ── Connect instance ─────────────────────────────────────────────────────────
116
- // connect is the bridge between C++ and the frontend.
116
+ // conn is the bridge between C++ and the frontend.
117
117
  // Run `plusui connect` to generate Connections/ from your name.on / name.emit usage.
118
- // Then declare: Connections ch(connect);
119
- // and use: ch.myEvent.on([](const json& p) { ... });
120
- // ch.myEvent.emit({{"value", 42}});
121
- static Connect connect;
118
+ // Call initChannels(conn) once, then use channels directly:
119
+ // customFileDrop.on([](const json& p) { ... });
120
+ // customFileDrop.emit({{"value", 42}});
121
+ static Connect conn;
122
+ using json = nlohmann::json;
122
123
 
123
124
  int main() {
124
125
  // Build the app with configuration
@@ -185,12 +186,12 @@ int main() {
185
186
  // ========================================
186
187
  // CONNECT — bind frontend ↔ backend
187
188
  // ========================================
188
- // Wires the connect object to this window.
189
- // Connections ch gives you named channel objects — same API as TypeScript:
190
- // ch.myEvent.on([](const json& p) { ... }); // receive from frontend
191
- // ch.myEvent.emit({{"value", 42}}); // send to frontend
192
- bindConnect(mainWindow, connect);
193
- Connections ch(connect); // use ch.name.on() / ch.name.emit()
189
+ // Wires the connect object to this window, then initialises
190
+ // the auto-generated channels so you can use them directly:
191
+ // customFileDrop.on([](const json& p) { ... });
192
+ // customFileDrop.emit({{"value", 42}});
193
+ bindConnect(mainWindow, conn);
194
+ initChannels(conn);
194
195
 
195
196
  // ========================================
196
197
  // CUSTOM FILE DROP CHANNEL
@@ -199,7 +200,7 @@ int main() {
199
200
  // Frontend drops files → emits via customFileDrop.emit({ files: [...] })
200
201
  // C++ receives here, processes, then emits back to the frontend.
201
202
  // Frontend receives the reply via customFileDrop.on() in App.tsx.
202
- ch.customFileDrop.on([&ch](const json& payload) {
203
+ customFileDrop.on([](const json& payload) {
203
204
  auto files = payload.value("files", json::array());
204
205
  int count = static_cast<int>(files.size());
205
206
  std::cout << "customFileDrop: received " << count << " file(s) from frontend" << std::endl;
@@ -207,7 +208,7 @@ int main() {
207
208
  std::cout << " - " << f.value("name", "?") << " (" << f.value("size", 0) << " bytes)" << std::endl;
208
209
  }
209
210
  // Reply back to frontend — received by customFileDrop.on() in App.tsx
210
- ch.customFileDrop.emit({
211
+ customFileDrop.emit({
211
212
  {"processed", true},
212
213
  {"count", count},
213
214
  {"message", "C++ received " + std::to_string(count) + " file(s)"}
@@ -231,10 +232,10 @@ int main() {
231
232
  //
232
233
  // CONNECT (custom channels — same API on both sides):
233
234
  // Run `plusui connect` to generate Connections/ from your name.on / name.emit calls.
234
- // C++: ch.myEvent.on([](const json& p) { ... }); // receive
235
- // ch.myEvent.emit({{"value", 42}}); // send
236
- // TS: myEvent.on((data) => { ... }); // receive
237
- // myEvent.emit({ value: 42 }); // send
235
+ // C++: customFileDrop.on([](const json& p) { ... }); // receive
236
+ // customFileDrop.emit({{"value", 42}}); // send
237
+ // TS: customFileDrop.on((data) => { ... }); // receive
238
+ // customFileDrop.emit({ value: 42 }); // send
238
239
  //
239
240
  // WINDOW: win.minimize(), win.maximize(), win.close(), win.center(),
240
241
  // win.setSize(w, h), win.setPosition(x, y), win.setTitle(str),