@geastack/host 0.1.28 → 0.1.30

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,34 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <string>
5
+
6
+ // Keeping the app running while it is not on screen. On watchOS this is a
7
+ // WKExtendedRuntimeSession; elsewhere the weak defaults in host/background.cpp
8
+ // report "unsupported" and start() returns false.
9
+ namespace gea::platform::background {
10
+
11
+ // type is the platform's session kind ("physical-therapy", "self-care",
12
+ // "mindfulness" or "alarm" on watchOS). Returns false when it cannot start.
13
+ bool start(const char *type);
14
+ void stop();
15
+ // "unsupported", "idle", "starting", "running", "expiring" or "ended".
16
+ const char *state();
17
+
18
+ } // namespace gea::platform::background
19
+
20
+ namespace gea::host {
21
+
22
+ struct BackgroundSessionFacade {
23
+ bool start(const std::string &type) const { return gea::platform::background::start(type.c_str()); }
24
+ void stop() const { gea::platform::background::stop(); }
25
+ std::string state() const { return gea::platform::background::state(); }
26
+ bool active() const {
27
+ const std::string value = gea::platform::background::state();
28
+ return value == "starting" || value == "running" || value == "expiring";
29
+ }
30
+ };
31
+
32
+ inline constexpr BackgroundSessionFacade BackgroundSession{};
33
+
34
+ } // namespace gea::host
@@ -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
@@ -8,18 +8,24 @@ namespace gea::host {
8
8
  // Menu bar mode for desktop apps (TS `MenuBar`, core index.d.ts). install()
9
9
  // turns the app into a menu bar extra: no Dock icon, an SF Symbol in the menu
10
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 offers
12
- // Quit). Frames keep running while the panel is hidden, so polling work
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
13
  // (Bluetooth, sockets, timers) carries on. macOS only; elsewhere supported()
14
14
  // is false and the calls do nothing.
15
15
  struct MenuBarFacade {
16
16
  bool supported() const;
17
17
  // `symbol` is an SF Symbol name, e.g. "waveform".
18
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;
19
22
  void setSymbol(const std::string &symbol) const;
20
23
  bool shown() const;
21
24
  void show() const;
22
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;
23
29
  };
24
30
 
25
31
  inline constexpr MenuBarFacade MenuBar{};
@@ -28,10 +34,15 @@ namespace menu_bar_platform {
28
34
  // Platform hooks; host/menu_bar.cpp holds the no-op fallbacks.
29
35
  bool supported();
30
36
  bool install(const std::string &symbol);
37
+ bool active();
31
38
  void setSymbol(const std::string &symbol);
32
39
  bool shown();
33
40
  void show();
34
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();
35
46
  } // namespace menu_bar_platform
36
47
 
37
48
  } // namespace gea::host
@@ -49,7 +49,11 @@ public:
49
49
  gea::framework::sensors::AccelerometerBackend::accelerationZ),
50
50
  gyroscopeX(gea::framework::sensors::AccelerometerBackend::gyroscopeX),
51
51
  gyroscopeY(gea::framework::sensors::AccelerometerBackend::gyroscopeY),
52
- gyroscopeZ(gea::framework::sensors::AccelerometerBackend::gyroscopeZ) {}
52
+ gyroscopeZ(gea::framework::sensors::AccelerometerBackend::gyroscopeZ),
53
+ attitudeX(gea::framework::sensors::AccelerometerBackend::attitudeX),
54
+ attitudeY(gea::framework::sensors::AccelerometerBackend::attitudeY),
55
+ attitudeZ(gea::framework::sensors::AccelerometerBackend::attitudeZ),
56
+ attitudeW(gea::framework::sensors::AccelerometerBackend::attitudeW) {}
53
57
 
54
58
  void start() const { gea::framework::sensors::AccelerometerBackend::init(); }
55
59
  void init() const { gea::framework::sensors::AccelerometerBackend::init(); }
@@ -69,6 +73,10 @@ public:
69
73
  AccelerometerValueProperty gyroscopeX;
70
74
  AccelerometerValueProperty gyroscopeY;
71
75
  AccelerometerValueProperty gyroscopeZ;
76
+ AccelerometerValueProperty attitudeX;
77
+ AccelerometerValueProperty attitudeY;
78
+ AccelerometerValueProperty attitudeZ;
79
+ AccelerometerValueProperty attitudeW;
72
80
  };
73
81
 
74
82
  using IMU = AccelerometerFacade;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/host",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "GeaStack host bindings and platform service sources.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {