@geastack/host 0.1.27 → 0.1.29

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.
@@ -0,0 +1,93 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <functional>
5
+ #include <string>
6
+
7
+ namespace gea::host {
8
+
9
+ // Native menus under the TS `Menu` / `MenuItem` classes (core runtime/menu.ts),
10
+ // used today as the right-click menu of the macOS menu bar status item
11
+ // (`MenuBar.setMenu`). Every menu and item is a double handle; a handle is
12
+ // never reused, so a stale one is simply ignored. An item's click is queued by
13
+ // the platform and its `onClick` runs on the app thread at the start of the
14
+ // next frame (menu::runCallbacks, from Application::frame). macOS only
15
+ // (host/menu_apple.mm); elsewhere the calls return dummy handles, store
16
+ // nothing and never fire.
17
+ //
18
+ // Shortcuts arrive pre-parsed: `key` is one lower-case character ("q", ",")
19
+ // or a key name ("enter", "tab", "space", "escape", "backspace", "delete",
20
+ // "up", "down", "left", "right", "home", "end", "pageup", "pagedown",
21
+ // "f1".."f12"); `modifiers` is a mask of the k*Modifier bits below.
22
+ struct MenuFacade {
23
+ static constexpr int kCommandModifier = 1;
24
+ static constexpr int kShiftModifier = 2;
25
+ static constexpr int kAltModifier = 4;
26
+ static constexpr int kControlModifier = 8;
27
+
28
+ double create() const;
29
+ // `role` is "" or "quit" (NSApp terminate:, ignoring onClick; an empty
30
+ // label becomes "Quit <App>").
31
+ double item(const std::string &label, const std::string &key, double modifiers, const std::string &role,
32
+ std::function<void()> onClick) const;
33
+ double separator() const;
34
+ // An item lives in one menu: appending it elsewhere moves it.
35
+ void append(double menu, double item) const;
36
+ void clear(double menu) const;
37
+ void setLabel(double item, const std::string &label) const;
38
+ void setEnabled(double item, bool enabled) const;
39
+ void setChecked(double item, bool checked) const;
40
+ void setVisible(double item, bool visible) const;
41
+ // An SF Symbol name shown beside the label; "" removes it.
42
+ void setSymbol(double item, const std::string &symbol) const;
43
+ // -1 removes the submenu.
44
+ void setSubmenu(double item, double menu) const;
45
+ // Releases a menu or an item, and with it the item's onClick.
46
+ void release(double handle) const;
47
+ };
48
+
49
+ inline constexpr MenuFacade Menu{};
50
+
51
+ namespace menu_platform {
52
+ // Platform hooks; host/menu.cpp holds the no-op fallbacks.
53
+ double create();
54
+ double item(const std::string &label, const std::string &key, int modifiers, const std::string &role,
55
+ std::function<void()> onClick);
56
+ double separator();
57
+ void append(double menu, double item);
58
+ void clear(double menu);
59
+ void setLabel(double item, const std::string &label);
60
+ void setEnabled(double item, bool enabled);
61
+ void setChecked(double item, bool checked);
62
+ void setVisible(double item, bool visible);
63
+ void setSymbol(double item, const std::string &symbol);
64
+ void setSubmenu(double item, double menu);
65
+ void release(double handle);
66
+ // The platform's own menu object for a menu handle (an NSMenu on macOS, for
67
+ // host/menu_bar_apple.mm), or null for a released or unknown handle.
68
+ void *nativeMenu(double menu);
69
+ } // namespace menu_platform
70
+
71
+ } // namespace gea::host
72
+
73
+ namespace gea::host::menu {
74
+
75
+ // Set by the platform when it creates its first item, so a program that never
76
+ // builds a menu (and a platform without menus) runs nothing per frame.
77
+ inline void (*pendingCallbacks)() = nullptr;
78
+ // Set alongside it: drops clicks still queued when the app unmounts.
79
+ inline void (*discardCallbacks)() = nullptr;
80
+
81
+ // Application::frame: run the onClick of every item clicked since last frame.
82
+ inline void runCallbacks()
83
+ {
84
+ if (pendingCallbacks) pendingCallbacks();
85
+ }
86
+
87
+ // Application::unmount.
88
+ inline void reset()
89
+ {
90
+ if (discardCallbacks) discardCallbacks();
91
+ }
92
+
93
+ } // namespace gea::host::menu
@@ -0,0 +1,48 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <string>
5
+
6
+ namespace gea::host {
7
+
8
+ // Menu bar mode for desktop apps (TS `MenuBar`, core index.d.ts). install()
9
+ // turns the app into a menu bar extra: no Dock icon, an SF Symbol in the menu
10
+ // bar, and the app's window becomes a borderless panel that drops down under
11
+ // the icon on click and hides when the app loses focus (right-click shows the
12
+ // app's menu from setMenu(), or a built-in Quit menu). Frames keep running while the panel is hidden, so polling work
13
+ // (Bluetooth, sockets, timers) carries on. macOS only; elsewhere supported()
14
+ // is false and the calls do nothing.
15
+ struct MenuBarFacade {
16
+ bool supported() const;
17
+ // `symbol` is an SF Symbol name, e.g. "waveform".
18
+ bool install(const std::string &symbol) const;
19
+ // True once install() has made this a menu bar app. The host then keeps the
20
+ // app running when its panel hides, though no window is left on screen.
21
+ bool active() const;
22
+ void setSymbol(const std::string &symbol) const;
23
+ bool shown() const;
24
+ void show() const;
25
+ void hide() const;
26
+ // The right-click / control-click menu: a `Menu` handle (host/menu.h), or
27
+ // -1 for the built-in "Quit <App>" menu. May be called before install().
28
+ void setMenu(double menu) const;
29
+ };
30
+
31
+ inline constexpr MenuBarFacade MenuBar{};
32
+
33
+ namespace menu_bar_platform {
34
+ // Platform hooks; host/menu_bar.cpp holds the no-op fallbacks.
35
+ bool supported();
36
+ bool install(const std::string &symbol);
37
+ bool active();
38
+ void setSymbol(const std::string &symbol);
39
+ bool shown();
40
+ void show();
41
+ void hide();
42
+ void setMenu(double menu);
43
+ // The NSMenu a right-click on the icon shows right now (nullptr off-Mac or
44
+ // before install). For the macOS replay harness, which opens it headlessly.
45
+ void *nativeSecondaryMenu();
46
+ } // namespace menu_bar_platform
47
+
48
+ } // namespace gea::host
@@ -2,6 +2,9 @@
2
2
  #pragma once
3
3
 
4
4
  #include "backends.h"
5
+ #if defined(__APPLE__)
6
+ #include <TargetConditionals.h>
7
+ #endif
5
8
 
6
9
  #include <string>
7
10
 
@@ -309,6 +312,52 @@ public:
309
312
  }
310
313
  };
311
314
 
315
+ class BluetoothCentral {
316
+ public:
317
+ // Generic GATT central role -- see BluetoothCentral in the TS API
318
+ // (index.d.ts) and BluetoothCentralDriver in ble.h.
319
+ std::string state() const { return gea::framework::bluetooth::CentralBackend::state(); }
320
+ void startScan() const { gea::framework::bluetooth::CentralBackend::startScan(std::string()); }
321
+ void startScan(const std::string &services) const {
322
+ gea::framework::bluetooth::CentralBackend::startScan(services);
323
+ }
324
+ void stopScan() const { gea::framework::bluetooth::CentralBackend::stopScan(); }
325
+ bool scanning() const { return gea::framework::bluetooth::CentralBackend::scanning(); }
326
+ double scanCount() const { return gea::framework::bluetooth::CentralBackend::scanCount(); }
327
+ std::string scanIdAt(double index) const { return gea::framework::bluetooth::CentralBackend::scanIdAt(index); }
328
+ std::string scanNameAt(double index) const { return gea::framework::bluetooth::CentralBackend::scanNameAt(index); }
329
+ double scanRssiAt(double index) const { return gea::framework::bluetooth::CentralBackend::scanRssiAt(index); }
330
+ std::string scanServicesAt(double index) const {
331
+ return gea::framework::bluetooth::CentralBackend::scanServicesAt(index);
332
+ }
333
+ std::vector<std::uint8_t> scanManufacturerDataAt(double index) const {
334
+ return gea::framework::bluetooth::CentralBackend::scanManufacturerDataAt(index);
335
+ }
336
+ void clearScan() const { gea::framework::bluetooth::CentralBackend::clearScan(); }
337
+ void connect(const std::string &id, const std::string &services) const {
338
+ gea::framework::bluetooth::CentralBackend::connect(id, services);
339
+ }
340
+ std::string link() const { return gea::framework::bluetooth::CentralBackend::link(); }
341
+ std::string linkError() const { return gea::framework::bluetooth::CentralBackend::linkError(); }
342
+ void subscribe(const std::string &service, const std::string &characteristic) const {
343
+ gea::framework::bluetooth::CentralBackend::subscribe(service, characteristic);
344
+ }
345
+ bool subscribed(const std::string &service, const std::string &characteristic) const {
346
+ return gea::framework::bluetooth::CentralBackend::subscribed(service, characteristic);
347
+ }
348
+ bool write(const std::string &service, const std::string &characteristic,
349
+ const std::vector<std::uint8_t> &bytes) const {
350
+ return gea::framework::bluetooth::CentralBackend::write(service, characteristic, bytes);
351
+ }
352
+ std::vector<std::uint8_t> read(const std::string &service, const std::string &characteristic) const {
353
+ return gea::framework::bluetooth::CentralBackend::read(service, characteristic);
354
+ }
355
+ void requestRead(const std::string &service, const std::string &characteristic) const {
356
+ gea::framework::bluetooth::CentralBackend::requestRead(service, characteristic);
357
+ }
358
+ void disconnect() const { gea::framework::bluetooth::CentralBackend::disconnect(); }
359
+ };
360
+
312
361
  class Bluetooth {
313
362
  public:
314
363
  BluetoothKeyboard keyboard;
@@ -317,6 +366,7 @@ public:
317
366
  BluetoothHidHost hidHost;
318
367
  BluetoothConnections connections;
319
368
  BluetoothConfig config;
369
+ BluetoothCentral central;
320
370
 
321
371
  const Bluetooth &operator()() const { return *this; }
322
372
  bool enabled() const {
@@ -424,7 +474,23 @@ class Navigator {
424
474
  public:
425
475
  const char *userAgent = "gea-embedded";
426
476
  const char *language = "en-US";
427
- const char *platform = "embedded";
477
+ // The host this build runs on: "macos", "ios", "web", "windows", "linux" or
478
+ // "embedded" (a board). Lets one app adapt where a feature only exists on
479
+ // some hosts (a menu bar, a Bluetooth central).
480
+ const char *platform =
481
+ #if defined(__EMSCRIPTEN__)
482
+ "web";
483
+ #elif defined(__APPLE__) && TARGET_OS_IPHONE
484
+ "ios";
485
+ #elif defined(__APPLE__)
486
+ "macos";
487
+ #elif defined(_WIN32)
488
+ "windows";
489
+ #elif defined(__linux__) && !defined(ESP_PLATFORM) && !defined(GEA_GEAOS)
490
+ "linux";
491
+ #else
492
+ "embedded";
493
+ #endif
428
494
  bool onLine = true;
429
495
  WiFi wifi;
430
496
  Bluetooth bluetooth;
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <cstdint>
5
+ #include <vector>
6
+
7
+ namespace gea::host {
8
+
9
+ // Opus decoding for app code (TS `Opus`, core index.d.ts): turns a stream of
10
+ // Opus packets (the 48 kHz codec every Bluetooth voice recorder and WebRTC
11
+ // peer speaks) into 16-bit PCM. A decoder keeps its state between calls, so a
12
+ // stream decoded batch by batch has no seams.
13
+ //
14
+ // Packets go in length-prefixed: each one a 16-bit little-endian byte count
15
+ // followed by the packet. PCM comes out little-endian, interleaved, at the
16
+ // decoder's sample rate. Apple hosts decode with AudioToolbox; elsewhere
17
+ // supported() is false and decoders are never created (handle 0).
18
+ struct OpusFacade {
19
+ bool supported() const;
20
+ double createDecoder(double sampleRate, double channels) const;
21
+ std::vector<std::uint8_t> decode(double decoder, const std::vector<std::uint8_t> &packets) const;
22
+ void destroyDecoder(double decoder) const;
23
+ };
24
+
25
+ inline constexpr OpusFacade Opus{};
26
+
27
+ namespace opus_platform {
28
+ // Platform hooks; host/opus.cpp holds weak fallbacks.
29
+ bool supported();
30
+ int createDecoder(int sampleRate, int channels);
31
+ std::vector<std::uint8_t> decode(int decoder, const std::vector<std::uint8_t> &packets);
32
+ void destroyDecoder(int decoder);
33
+ } // namespace opus_platform
34
+
35
+ } // namespace gea::host
@@ -81,6 +81,8 @@ class WebSocket {
81
81
  double readyState() const;
82
82
  double bufferedAmount() const;
83
83
  void send(const std::string &data) const;
84
+ // Binary frame: a Uint8Array / ArrayBuffer argument lowers to the byte vector.
85
+ void send(const std::vector<std::uint8_t> &data) const;
84
86
  void close() const;
85
87
  void close(double code) const;
86
88
  void close(double code, const std::string &reason) const;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/host",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "GeaStack host bindings and platform service sources.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {