@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.
- package/README.md +15 -4
- package/audio_runtime.cpp +131 -29
- package/host/audio.cpp +132 -4
- package/host/background.cpp +12 -0
- package/host/fetch.cpp +47 -2
- package/host/files.cpp +17 -12
- package/host/image.cpp +17 -6
- package/host/imu.cpp +25 -0
- package/host/media.cpp +8 -7
- package/host/menu.cpp +49 -0
- package/host/menu_apple.mm +249 -0
- package/host/menu_bar.cpp +5 -0
- package/host/menu_bar_apple.mm +48 -2
- package/host/tile_loader.cpp +5 -3
- package/include/gea/embedded-host.h +2 -0
- package/include/host/audio.h +12 -0
- package/include/host/backends.h +4 -0
- package/include/host/background.h +34 -0
- package/include/host/menu.h +93 -0
- package/include/host/menu_bar.h +13 -2
- package/include/host/navigator.h +9 -1
- package/package.json +1 -1
package/host/image.cpp
CHANGED
|
@@ -57,7 +57,14 @@ namespace {
|
|
|
57
57
|
bool (*g_mount_provider)() = nullptr;
|
|
58
58
|
bool (*g_fallback_mount_provider)() = nullptr;
|
|
59
59
|
std::string (*g_read_path_provider)(const std::string &) = nullptr;
|
|
60
|
+
std::string (*g_path_provider)(const std::string &) = nullptr;
|
|
60
61
|
} // namespace
|
|
62
|
+
void setPathProvider(std::string (*provider)(const std::string &)) {
|
|
63
|
+
g_path_provider = provider;
|
|
64
|
+
}
|
|
65
|
+
std::string hostPath(const std::string &path) {
|
|
66
|
+
return g_path_provider ? g_path_provider(path) : path;
|
|
67
|
+
}
|
|
61
68
|
void setMountProvider(bool (*provider)()) { g_mount_provider = provider; }
|
|
62
69
|
void setFallbackMountProvider(bool (*provider)()) {
|
|
63
70
|
g_fallback_mount_provider = provider;
|
|
@@ -66,9 +73,11 @@ void setReadPathProvider(std::string (*provider)(const std::string &)) {
|
|
|
66
73
|
g_read_path_provider = provider;
|
|
67
74
|
}
|
|
68
75
|
static std::FILE *openRead(const std::string &path) {
|
|
76
|
+
if (std::FILE *file = std::fopen(hostPath(path).c_str(), "rb"))
|
|
77
|
+
return file;
|
|
69
78
|
if (g_read_path_provider)
|
|
70
79
|
return std::fopen(g_read_path_provider(path).c_str(), "rb");
|
|
71
|
-
return
|
|
80
|
+
return nullptr;
|
|
72
81
|
}
|
|
73
82
|
bool ensureMounted() {
|
|
74
83
|
auto provider =
|
|
@@ -286,9 +295,10 @@ bool ImageService::writeFile(const std::string &path,
|
|
|
286
295
|
if (path.empty() || bytes.empty() ||
|
|
287
296
|
!storageReadyFor(path))
|
|
288
297
|
return;
|
|
289
|
-
|
|
298
|
+
const std::string host = gea::platform::storage::hostPath(path);
|
|
299
|
+
makeParentDirs(host);
|
|
290
300
|
gea::platform::storage::FileOperations files;
|
|
291
|
-
result = gea::platform::storage::writeFileAtomically(
|
|
301
|
+
result = gea::platform::storage::writeFileAtomically(host, bytes, files);
|
|
292
302
|
});
|
|
293
303
|
return result;
|
|
294
304
|
}
|
|
@@ -297,7 +307,7 @@ bool ImageService::removeFile(const std::string &path) const {
|
|
|
297
307
|
bool result = false;
|
|
298
308
|
gea::platform::onInternalStack([&] {
|
|
299
309
|
if (!path.empty() && storageReadyFor(path))
|
|
300
|
-
result = std::remove(path.c_str()) == 0;
|
|
310
|
+
result = std::remove(gea::platform::storage::hostPath(path).c_str()) == 0;
|
|
301
311
|
});
|
|
302
312
|
return result;
|
|
303
313
|
}
|
|
@@ -350,7 +360,8 @@ std::string ImageService::listFiles(const std::string &path) const {
|
|
|
350
360
|
if (path.empty() || !storageReadyFor(path))
|
|
351
361
|
return;
|
|
352
362
|
#ifdef GEA_HOST_HAS_DIRENT
|
|
353
|
-
|
|
363
|
+
const std::string host = gea::platform::storage::hostPath(path);
|
|
364
|
+
DIR *dir = opendir(host.c_str());
|
|
354
365
|
if (!dir)
|
|
355
366
|
return;
|
|
356
367
|
while (const dirent *entry = readdir(dir)) {
|
|
@@ -359,7 +370,7 @@ std::string ImageService::listFiles(const std::string &path) const {
|
|
|
359
370
|
bool regular = entry->d_type == DT_REG;
|
|
360
371
|
if (entry->d_type == DT_UNKNOWN) {
|
|
361
372
|
struct stat st{};
|
|
362
|
-
const std::string full =
|
|
373
|
+
const std::string full = host + "/" + entry->d_name;
|
|
363
374
|
regular = stat(full.c_str(), &st) == 0 && S_ISREG(st.st_mode);
|
|
364
375
|
}
|
|
365
376
|
if (!regular)
|
package/host/imu.cpp
CHANGED
|
@@ -2,8 +2,33 @@
|
|
|
2
2
|
#include "imu.h"
|
|
3
3
|
#include "gea/embedded-host.h"
|
|
4
4
|
|
|
5
|
+
namespace gea::platform::sensors {
|
|
6
|
+
|
|
7
|
+
__attribute__((weak)) bool attitude(double &, double &, double &, double &) { return false; }
|
|
8
|
+
|
|
9
|
+
} // namespace gea::platform::sensors
|
|
10
|
+
|
|
5
11
|
namespace gea::framework::sensors {
|
|
6
12
|
|
|
13
|
+
namespace {
|
|
14
|
+
|
|
15
|
+
struct Attitude {
|
|
16
|
+
double w = 0, x = 0, y = 0, z = 0;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
Attitude currentAttitude() {
|
|
20
|
+
Attitude q;
|
|
21
|
+
if (!gea::platform::sensors::attitude(q.w, q.x, q.y, q.z)) return Attitude{};
|
|
22
|
+
return q;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace
|
|
26
|
+
|
|
27
|
+
double AccelerometerBackend::attitudeX() { return currentAttitude().x; }
|
|
28
|
+
double AccelerometerBackend::attitudeY() { return currentAttitude().y; }
|
|
29
|
+
double AccelerometerBackend::attitudeZ() { return currentAttitude().z; }
|
|
30
|
+
double AccelerometerBackend::attitudeW() { return currentAttitude().w; }
|
|
31
|
+
|
|
7
32
|
void AccelerometerBackend::init() {
|
|
8
33
|
gea::platform::sensors::Accelerometer::init();
|
|
9
34
|
}
|
package/host/media.cpp
CHANGED
|
@@ -245,9 +245,10 @@ bool patchWavHeader(FILE *file, std::uint32_t dataBytes) {
|
|
|
245
245
|
double writeWavFileOnInternalStack(const std::string &path, const std::vector<std::int16_t> &samples, int sampleRate, int channels) {
|
|
246
246
|
if (path.empty()) return 0.0;
|
|
247
247
|
gea::platform::storage::ensureMounted();
|
|
248
|
-
|
|
248
|
+
const std::string host = gea::platform::storage::hostPath(path);
|
|
249
|
+
makeParentDirs(host);
|
|
249
250
|
|
|
250
|
-
FILE *file = std::fopen(
|
|
251
|
+
FILE *file = std::fopen(host.c_str(), "wb");
|
|
251
252
|
if (!file) {
|
|
252
253
|
#ifdef ESP_PLATFORM
|
|
253
254
|
ESP_LOGE(kMediaLogTag, "failed to open WAV for write path=%s errno=%d", path.c_str(), errno);
|
|
@@ -314,7 +315,7 @@ std::string nextDefaultRecordingPath(NativeMediaRecorderHandle handle) {
|
|
|
314
315
|
if (recordingPathAssigned(buf)) continue;
|
|
315
316
|
|
|
316
317
|
struct stat info;
|
|
317
|
-
if (stat(buf, &info) != 0 && errno == ENOENT) return buf;
|
|
318
|
+
if (stat(gea::platform::storage::hostPath(buf).c_str(), &info) != 0 && errno == ENOENT) return buf;
|
|
318
319
|
}
|
|
319
320
|
return {};
|
|
320
321
|
}
|
|
@@ -322,10 +323,10 @@ std::string nextDefaultRecordingPath(NativeMediaRecorderHandle handle) {
|
|
|
322
323
|
// A default name is claimed by creating the file ("x" fails if it exists), so it never replaces a file that
|
|
323
324
|
// appeared after the name was picked, or this recorder's previous recording; it moves on to the next name.
|
|
324
325
|
std::FILE *openRecorderOutput(RecorderState &recorder, NativeMediaRecorderHandle handle) {
|
|
325
|
-
if (!recorder.defaultPath) return std::fopen(recorder.path.c_str(), "wb");
|
|
326
|
+
if (!recorder.defaultPath) return std::fopen(gea::platform::storage::hostPath(recorder.path).c_str(), "wb");
|
|
326
327
|
|
|
327
328
|
for (;;) {
|
|
328
|
-
std::FILE *file = std::fopen(recorder.path.c_str(), "wbx");
|
|
329
|
+
std::FILE *file = std::fopen(gea::platform::storage::hostPath(recorder.path).c_str(), "wbx");
|
|
329
330
|
if (file || errno != EEXIST) return file;
|
|
330
331
|
|
|
331
332
|
recorder.path = nextDefaultRecordingPath(handle);
|
|
@@ -336,7 +337,7 @@ std::FILE *openRecorderOutput(RecorderState &recorder, NativeMediaRecorderHandle
|
|
|
336
337
|
bool openRecorderFileOnInternalStack(RecorderState &recorder, NativeMediaRecorderHandle handle) {
|
|
337
338
|
if (recorder.path.empty()) return false;
|
|
338
339
|
gea::platform::storage::ensureMounted();
|
|
339
|
-
makeParentDirs(recorder.path);
|
|
340
|
+
makeParentDirs(gea::platform::storage::hostPath(recorder.path));
|
|
340
341
|
recorder.file = openRecorderOutput(recorder, handle);
|
|
341
342
|
recorder.samplesWritten = 0;
|
|
342
343
|
recorder.writeFailed = false;
|
|
@@ -442,7 +443,7 @@ double finalizeRecorderFile(RecorderState &recorder) {
|
|
|
442
443
|
std::vector<std::uint8_t> readFileBytesOnInternalStack(const std::string &path) {
|
|
443
444
|
if (path.empty()) return {};
|
|
444
445
|
gea::platform::storage::ensureMounted();
|
|
445
|
-
FILE *file = std::fopen(path.c_str(), "rb");
|
|
446
|
+
FILE *file = std::fopen(gea::platform::storage::hostPath(path).c_str(), "rb");
|
|
446
447
|
if (!file) return {};
|
|
447
448
|
std::fseek(file, 0, SEEK_END);
|
|
448
449
|
const long size = std::ftell(file);
|
package/host/menu.cpp
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The `Menu` host API (host/menu.h). Menus themselves are the platform's
|
|
3
|
+
// (host/menu_apple.mm on macOS); these fallbacks make every other host a
|
|
4
|
+
// no-op that hands out dummy handles, keeps no callback and never fires.
|
|
5
|
+
#include "host/menu.h"
|
|
6
|
+
|
|
7
|
+
#include <utility>
|
|
8
|
+
|
|
9
|
+
namespace gea::host {
|
|
10
|
+
|
|
11
|
+
double MenuFacade::create() const { return menu_platform::create(); }
|
|
12
|
+
double MenuFacade::item(const std::string &label, const std::string &key, double modifiers, const std::string &role,
|
|
13
|
+
std::function<void()> onClick) const
|
|
14
|
+
{
|
|
15
|
+
return menu_platform::item(label, key, static_cast<int>(modifiers), role, std::move(onClick));
|
|
16
|
+
}
|
|
17
|
+
double MenuFacade::separator() const { return menu_platform::separator(); }
|
|
18
|
+
void MenuFacade::append(double menu, double item) const { menu_platform::append(menu, item); }
|
|
19
|
+
void MenuFacade::clear(double menu) const { menu_platform::clear(menu); }
|
|
20
|
+
void MenuFacade::setLabel(double item, const std::string &label) const { menu_platform::setLabel(item, label); }
|
|
21
|
+
void MenuFacade::setEnabled(double item, bool enabled) const { menu_platform::setEnabled(item, enabled); }
|
|
22
|
+
void MenuFacade::setChecked(double item, bool checked) const { menu_platform::setChecked(item, checked); }
|
|
23
|
+
void MenuFacade::setVisible(double item, bool visible) const { menu_platform::setVisible(item, visible); }
|
|
24
|
+
void MenuFacade::setSymbol(double item, const std::string &symbol) const { menu_platform::setSymbol(item, symbol); }
|
|
25
|
+
void MenuFacade::setSubmenu(double item, double menu) const { menu_platform::setSubmenu(item, menu); }
|
|
26
|
+
void MenuFacade::release(double handle) const { menu_platform::release(handle); }
|
|
27
|
+
|
|
28
|
+
namespace menu_platform {
|
|
29
|
+
|
|
30
|
+
__attribute__((weak)) double create() { return 0; }
|
|
31
|
+
__attribute__((weak)) double item(const std::string &, const std::string &, int, const std::string &,
|
|
32
|
+
std::function<void()>)
|
|
33
|
+
{
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
__attribute__((weak)) double separator() { return 0; }
|
|
37
|
+
__attribute__((weak)) void append(double, double) {}
|
|
38
|
+
__attribute__((weak)) void clear(double) {}
|
|
39
|
+
__attribute__((weak)) void setLabel(double, const std::string &) {}
|
|
40
|
+
__attribute__((weak)) void setEnabled(double, bool) {}
|
|
41
|
+
__attribute__((weak)) void setChecked(double, bool) {}
|
|
42
|
+
__attribute__((weak)) void setVisible(double, bool) {}
|
|
43
|
+
__attribute__((weak)) void setSymbol(double, const std::string &) {}
|
|
44
|
+
__attribute__((weak)) void setSubmenu(double, double) {}
|
|
45
|
+
__attribute__((weak)) void release(double) {}
|
|
46
|
+
__attribute__((weak)) void *nativeMenu(double) { return nullptr; }
|
|
47
|
+
|
|
48
|
+
} // namespace menu_platform
|
|
49
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// macOS menus for the `Menu` host API (host/menu.h): one NSMenu per menu
|
|
3
|
+
// handle, one NSMenuItem per item handle. Every item targets one shared
|
|
4
|
+
// GeaMenuTarget with its handle as the tag; a click only queues the handle,
|
|
5
|
+
// and menu::runCallbacks runs the item's onClick on the next frame. Frames
|
|
6
|
+
// run on the main thread on macOS, so the setters write AppKit directly.
|
|
7
|
+
#if defined(__APPLE__)
|
|
8
|
+
#include <TargetConditionals.h>
|
|
9
|
+
#endif
|
|
10
|
+
#if defined(__APPLE__) && TARGET_OS_OSX
|
|
11
|
+
|
|
12
|
+
#import <AppKit/AppKit.h>
|
|
13
|
+
|
|
14
|
+
#include <cstdlib>
|
|
15
|
+
#include <functional>
|
|
16
|
+
#include <string>
|
|
17
|
+
#include <unordered_map>
|
|
18
|
+
#include <utility>
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "host/menu.h"
|
|
22
|
+
|
|
23
|
+
__asm__(".linker_option \"-framework\", \"AppKit\"");
|
|
24
|
+
|
|
25
|
+
namespace {
|
|
26
|
+
|
|
27
|
+
struct Slot {
|
|
28
|
+
NSMenu *menu = nil;
|
|
29
|
+
NSMenuItem *item = nil;
|
|
30
|
+
std::function<void()> onClick;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Handles count up and are never reused, so a click queued for an item that
|
|
34
|
+
// was released (or a MenuBar holding a destroyed menu) finds nothing.
|
|
35
|
+
long gNextHandle = 1;
|
|
36
|
+
std::unordered_map<long, Slot> gSlots;
|
|
37
|
+
std::vector<long> gPending;
|
|
38
|
+
|
|
39
|
+
Slot *lookup(double handle) {
|
|
40
|
+
auto found = gSlots.find(static_cast<long>(handle));
|
|
41
|
+
return found == gSlots.end() ? nullptr : &found->second;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
NSMenuItem *itemFor(double handle) {
|
|
45
|
+
Slot *slot = lookup(handle);
|
|
46
|
+
return slot ? slot->item : nil;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
NSMenu *menuFor(double handle) {
|
|
50
|
+
Slot *slot = lookup(handle);
|
|
51
|
+
return slot ? slot->menu : nil;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
NSString *nsString(const std::string &text) { return [NSString stringWithUTF8String:text.c_str()] ?: @""; }
|
|
55
|
+
|
|
56
|
+
void runPending() {
|
|
57
|
+
if (gPending.empty()) return;
|
|
58
|
+
std::vector<long> clicked;
|
|
59
|
+
clicked.swap(gPending);
|
|
60
|
+
for (long handle : clicked) {
|
|
61
|
+
Slot *slot = lookup(handle);
|
|
62
|
+
if (!slot) continue;
|
|
63
|
+
// The callback may destroy this menu (or rebuild it into the table); run
|
|
64
|
+
// a copy so its captures outlive the call.
|
|
65
|
+
auto onClick = slot->onClick;
|
|
66
|
+
if (onClick) onClick();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
void discardPending() { gPending.clear(); }
|
|
71
|
+
|
|
72
|
+
NSString *keyEquivalent(const std::string &key) {
|
|
73
|
+
if (key.empty()) return @"";
|
|
74
|
+
if (key.size() == 1) return nsString(key);
|
|
75
|
+
static const std::unordered_map<std::string, unichar> named = {
|
|
76
|
+
{"enter", '\r'},
|
|
77
|
+
{"return", '\r'},
|
|
78
|
+
{"tab", '\t'},
|
|
79
|
+
{"space", ' '},
|
|
80
|
+
{"escape", 0x1b},
|
|
81
|
+
{"backspace", 0x08},
|
|
82
|
+
{"delete", NSDeleteFunctionKey},
|
|
83
|
+
{"up", NSUpArrowFunctionKey},
|
|
84
|
+
{"down", NSDownArrowFunctionKey},
|
|
85
|
+
{"left", NSLeftArrowFunctionKey},
|
|
86
|
+
{"right", NSRightArrowFunctionKey},
|
|
87
|
+
{"home", NSHomeFunctionKey},
|
|
88
|
+
{"end", NSEndFunctionKey},
|
|
89
|
+
{"pageup", NSPageUpFunctionKey},
|
|
90
|
+
{"pagedown", NSPageDownFunctionKey},
|
|
91
|
+
};
|
|
92
|
+
unichar character = 0;
|
|
93
|
+
auto found = named.find(key);
|
|
94
|
+
if (found != named.end()) {
|
|
95
|
+
character = found->second;
|
|
96
|
+
} else if (key[0] == 'f' && key.size() <= 3) {
|
|
97
|
+
const int number = std::atoi(key.c_str() + 1);
|
|
98
|
+
if (number >= 1 && number <= 12) character = static_cast<unichar>(NSF1FunctionKey + number - 1);
|
|
99
|
+
}
|
|
100
|
+
if (!character) return nsString(key);
|
|
101
|
+
return [NSString stringWithCharacters:&character length:1];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
NSEventModifierFlags modifierFlags(int modifiers) {
|
|
105
|
+
NSEventModifierFlags flags = 0;
|
|
106
|
+
if (modifiers & gea::host::MenuFacade::kCommandModifier) flags |= NSEventModifierFlagCommand;
|
|
107
|
+
if (modifiers & gea::host::MenuFacade::kShiftModifier) flags |= NSEventModifierFlagShift;
|
|
108
|
+
if (modifiers & gea::host::MenuFacade::kAltModifier) flags |= NSEventModifierFlagOption;
|
|
109
|
+
if (modifiers & gea::host::MenuFacade::kControlModifier) flags |= NSEventModifierFlagControl;
|
|
110
|
+
return flags;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
NSString *appName() {
|
|
114
|
+
return [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"]
|
|
115
|
+
?: [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"]
|
|
116
|
+
?: NSProcessInfo.processInfo.processName;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// A submenu hangs off one item at a time.
|
|
120
|
+
void detachFromSupermenu(NSMenu *menu) {
|
|
121
|
+
NSMenu *super = menu.supermenu;
|
|
122
|
+
if (!super) return;
|
|
123
|
+
for (NSMenuItem *item in super.itemArray) {
|
|
124
|
+
if (item.submenu == menu) item.submenu = nil;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
long insert(Slot slot) {
|
|
129
|
+
const long handle = gNextHandle++;
|
|
130
|
+
gSlots.emplace(handle, std::move(slot));
|
|
131
|
+
return handle;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
} // namespace
|
|
135
|
+
|
|
136
|
+
@interface GeaMenuTarget : NSObject
|
|
137
|
+
- (void)fire:(NSMenuItem *)sender;
|
|
138
|
+
@end
|
|
139
|
+
|
|
140
|
+
@implementation GeaMenuTarget
|
|
141
|
+
- (void)fire:(NSMenuItem *)sender {
|
|
142
|
+
gPending.push_back(static_cast<long>(sender.tag));
|
|
143
|
+
}
|
|
144
|
+
@end
|
|
145
|
+
|
|
146
|
+
namespace {
|
|
147
|
+
// NSMenuItem.target is weak.
|
|
148
|
+
GeaMenuTarget *target() {
|
|
149
|
+
static GeaMenuTarget *shared = [[GeaMenuTarget alloc] init];
|
|
150
|
+
return shared;
|
|
151
|
+
}
|
|
152
|
+
} // namespace
|
|
153
|
+
|
|
154
|
+
namespace gea::host::menu_platform {
|
|
155
|
+
|
|
156
|
+
double create() {
|
|
157
|
+
Slot slot;
|
|
158
|
+
slot.menu = [[NSMenu alloc] init];
|
|
159
|
+
// The app owns enabled: AppKit must not re-validate items against the
|
|
160
|
+
// responder chain.
|
|
161
|
+
slot.menu.autoenablesItems = NO;
|
|
162
|
+
return insert(std::move(slot));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
double item(const std::string &label, const std::string &key, int modifiers, const std::string &role,
|
|
166
|
+
std::function<void()> onClick) {
|
|
167
|
+
const bool quit = role == "quit";
|
|
168
|
+
NSString *title = nsString(label);
|
|
169
|
+
if (quit && title.length == 0) title = [@"Quit " stringByAppendingString:appName()];
|
|
170
|
+
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title
|
|
171
|
+
action:quit ? @selector(terminate:) : @selector(fire:)
|
|
172
|
+
keyEquivalent:keyEquivalent(key)];
|
|
173
|
+
item.keyEquivalentModifierMask = modifierFlags(modifiers);
|
|
174
|
+
item.target = quit ? (id)NSApp : (id)target();
|
|
175
|
+
Slot slot;
|
|
176
|
+
slot.item = item;
|
|
177
|
+
if (!quit) slot.onClick = std::move(onClick);
|
|
178
|
+
const long handle = insert(std::move(slot));
|
|
179
|
+
item.tag = handle;
|
|
180
|
+
gea::host::menu::pendingCallbacks = runPending;
|
|
181
|
+
gea::host::menu::discardCallbacks = discardPending;
|
|
182
|
+
return handle;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
double separator() {
|
|
186
|
+
Slot slot;
|
|
187
|
+
slot.item = [NSMenuItem separatorItem];
|
|
188
|
+
return insert(std::move(slot));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
void append(double menuHandle, double itemHandle) {
|
|
192
|
+
NSMenu *menu = menuFor(menuHandle);
|
|
193
|
+
NSMenuItem *item = itemFor(itemHandle);
|
|
194
|
+
if (!menu || !item) return;
|
|
195
|
+
if (item.menu) [item.menu removeItem:item];
|
|
196
|
+
[menu addItem:item];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
void clear(double menuHandle) { [menuFor(menuHandle) removeAllItems]; }
|
|
200
|
+
|
|
201
|
+
void setLabel(double handle, const std::string &label) { itemFor(handle).title = nsString(label); }
|
|
202
|
+
|
|
203
|
+
void setEnabled(double handle, bool enabled) { itemFor(handle).enabled = enabled; }
|
|
204
|
+
|
|
205
|
+
void setChecked(double handle, bool checked) {
|
|
206
|
+
itemFor(handle).state = checked ? NSControlStateValueOn : NSControlStateValueOff;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
void setVisible(double handle, bool visible) { itemFor(handle).hidden = !visible; }
|
|
210
|
+
|
|
211
|
+
void setSymbol(double handle, const std::string &symbol) {
|
|
212
|
+
NSMenuItem *item = itemFor(handle);
|
|
213
|
+
if (!item) return;
|
|
214
|
+
item.image = symbol.empty() ? nil : [NSImage imageWithSystemSymbolName:nsString(symbol) accessibilityDescription:nil];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
void setSubmenu(double itemHandle, double menuHandle) {
|
|
218
|
+
NSMenuItem *item = itemFor(itemHandle);
|
|
219
|
+
if (!item) return;
|
|
220
|
+
NSMenu *menu = menuFor(menuHandle);
|
|
221
|
+
if (menu && item.submenu == menu) return;
|
|
222
|
+
if (menu) detachFromSupermenu(menu);
|
|
223
|
+
item.submenu = menu;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
void release(double handle) {
|
|
227
|
+
Slot *slot = lookup(handle);
|
|
228
|
+
if (!slot) return;
|
|
229
|
+
if (slot->item) {
|
|
230
|
+
if (slot->item.menu) [slot->item.menu removeItem:slot->item];
|
|
231
|
+
slot->item.submenu = nil;
|
|
232
|
+
slot->item.target = nil;
|
|
233
|
+
slot->item.action = nil;
|
|
234
|
+
}
|
|
235
|
+
if (slot->menu) {
|
|
236
|
+
detachFromSupermenu(slot->menu);
|
|
237
|
+
[slot->menu removeAllItems];
|
|
238
|
+
}
|
|
239
|
+
// Destroying the callback releases its captures; when release() runs inside
|
|
240
|
+
// that callback, runPending holds the copy that is executing.
|
|
241
|
+
auto released = std::move(slot->onClick);
|
|
242
|
+
gSlots.erase(static_cast<long>(handle));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
void *nativeMenu(double handle) { return (__bridge void *)menuFor(handle); }
|
|
246
|
+
|
|
247
|
+
} // namespace gea::host::menu_platform
|
|
248
|
+
|
|
249
|
+
#endif
|
package/host/menu_bar.cpp
CHANGED
|
@@ -8,19 +8,24 @@ namespace gea::host {
|
|
|
8
8
|
|
|
9
9
|
bool MenuBarFacade::supported() const { return menu_bar_platform::supported(); }
|
|
10
10
|
bool MenuBarFacade::install(const std::string &symbol) const { return menu_bar_platform::install(symbol); }
|
|
11
|
+
bool MenuBarFacade::active() const { return menu_bar_platform::active(); }
|
|
11
12
|
void MenuBarFacade::setSymbol(const std::string &symbol) const { menu_bar_platform::setSymbol(symbol); }
|
|
12
13
|
bool MenuBarFacade::shown() const { return menu_bar_platform::shown(); }
|
|
13
14
|
void MenuBarFacade::show() const { menu_bar_platform::show(); }
|
|
14
15
|
void MenuBarFacade::hide() const { menu_bar_platform::hide(); }
|
|
16
|
+
void MenuBarFacade::setMenu(double menu) const { menu_bar_platform::setMenu(menu); }
|
|
15
17
|
|
|
16
18
|
namespace menu_bar_platform {
|
|
17
19
|
|
|
18
20
|
__attribute__((weak)) bool supported() { return false; }
|
|
19
21
|
__attribute__((weak)) bool install(const std::string &) { return false; }
|
|
22
|
+
__attribute__((weak)) bool active() { return false; }
|
|
20
23
|
__attribute__((weak)) void setSymbol(const std::string &) {}
|
|
21
24
|
__attribute__((weak)) bool shown() { return true; }
|
|
22
25
|
__attribute__((weak)) void show() {}
|
|
23
26
|
__attribute__((weak)) void hide() {}
|
|
27
|
+
__attribute__((weak)) void setMenu(double) {}
|
|
28
|
+
__attribute__((weak)) void *nativeSecondaryMenu() { return nullptr; }
|
|
24
29
|
|
|
25
30
|
} // namespace menu_bar_platform
|
|
26
31
|
} // namespace gea::host
|
package/host/menu_bar_apple.mm
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// macOS menu bar mode for the `MenuBar` host API (host/menu_bar.h): a status
|
|
3
3
|
// item with an SF Symbol, the app's window restyled as a borderless panel that
|
|
4
|
-
// drops down under it, accessory activation (no Dock icon),
|
|
4
|
+
// drops down under it, accessory activation (no Dock icon), the right-click
|
|
5
|
+
// menu (the app's `Menu` from setMenu, else Quit), and a timer that
|
|
5
6
|
// keeps the app delegate's frames coming while the panel is hidden -- the
|
|
6
7
|
// window's display link stops with the window.
|
|
7
8
|
#if defined(__APPLE__)
|
|
@@ -11,11 +12,19 @@
|
|
|
11
12
|
|
|
12
13
|
#import <AppKit/AppKit.h>
|
|
13
14
|
|
|
15
|
+
#include <cstdlib>
|
|
16
|
+
|
|
17
|
+
#include "host/menu.h"
|
|
14
18
|
#include "host/menu_bar.h"
|
|
15
19
|
|
|
16
20
|
static const CGFloat kPanelGap = 6;
|
|
17
21
|
static const NSTimeInterval kHiddenTick = 1.0 / 20.0;
|
|
18
22
|
|
|
23
|
+
// The app's right-click menu handle (host/menu.h), -1 for the built-in one.
|
|
24
|
+
// Kept as a handle and resolved per click, so setMenu() before install() just
|
|
25
|
+
// works and a destroyed menu falls back to Quit.
|
|
26
|
+
static double gCustomMenu = -1;
|
|
27
|
+
|
|
19
28
|
@interface GeaMenuBar : NSObject
|
|
20
29
|
@property(nonatomic, strong) NSStatusItem *item;
|
|
21
30
|
@property(nonatomic, weak) NSWindow *window;
|
|
@@ -79,6 +88,13 @@ static const NSTimeInterval kHiddenTick = 1.0 / 20.0;
|
|
|
79
88
|
name:NSApplicationDidResignActiveNotification
|
|
80
89
|
object:nil];
|
|
81
90
|
|
|
91
|
+
// Another of the app's windows (a `<window>` element) taking the keyboard
|
|
92
|
+
// closes the panel, the way clicking into another app does.
|
|
93
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
94
|
+
selector:@selector(otherWindowBecameKey:)
|
|
95
|
+
name:NSWindowDidBecomeKeyNotification
|
|
96
|
+
object:nil];
|
|
97
|
+
|
|
82
98
|
self.timer = [NSTimer timerWithTimeInterval:kHiddenTick
|
|
83
99
|
target:self
|
|
84
100
|
selector:@selector(tickWhileHidden:)
|
|
@@ -86,6 +102,10 @@ static const NSTimeInterval kHiddenTick = 1.0 / 20.0;
|
|
|
86
102
|
repeats:YES];
|
|
87
103
|
self.timer.tolerance = kHiddenTick / 4;
|
|
88
104
|
[NSRunLoop.mainRunLoop addTimer:self.timer forMode:NSRunLoopCommonModes];
|
|
105
|
+
|
|
106
|
+
// A scripted replay (the macOS target's GEA_MACOS_REPLAY_PLAN) drives the
|
|
107
|
+
// panel's window, so it opens the panel the way a click on the icon does.
|
|
108
|
+
if (std::getenv("GEA_MACOS_REPLAY_PLAN")) dispatch_async(dispatch_get_main_queue(), ^{ [self show]; });
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
- (void)setSymbol:(NSString *)symbol {
|
|
@@ -99,11 +119,18 @@ static const NSTimeInterval kHiddenTick = 1.0 / 20.0;
|
|
|
99
119
|
return self.window.isVisible;
|
|
100
120
|
}
|
|
101
121
|
|
|
122
|
+
// The menu a right-click or control-click shows: the app's from setMenu(),
|
|
123
|
+
// else the built-in Quit menu.
|
|
124
|
+
- (NSMenu *)secondaryMenu {
|
|
125
|
+
NSMenu *custom = gCustomMenu >= 0 ? (__bridge NSMenu *)gea::host::menu_platform::nativeMenu(gCustomMenu) : nil;
|
|
126
|
+
return custom ?: self.menu;
|
|
127
|
+
}
|
|
128
|
+
|
|
102
129
|
- (void)clicked:(id)sender {
|
|
103
130
|
NSEvent *event = NSApp.currentEvent;
|
|
104
131
|
const BOOL secondary = event.type == NSEventTypeRightMouseUp || (event.modifierFlags & NSEventModifierFlagControl);
|
|
105
132
|
if (secondary) {
|
|
106
|
-
self.item.menu = self
|
|
133
|
+
self.item.menu = [self secondaryMenu];
|
|
107
134
|
[self.item.button performClick:nil];
|
|
108
135
|
self.item.menu = nil;
|
|
109
136
|
return;
|
|
@@ -125,6 +152,9 @@ static const NSTimeInterval kHiddenTick = 1.0 / 20.0;
|
|
|
125
152
|
[window setFrameOrigin:NSMakePoint(x, y)];
|
|
126
153
|
[NSApp activateIgnoringOtherApps:YES];
|
|
127
154
|
[window makeKeyAndOrderFront:nil];
|
|
155
|
+
// Keys go to the app as soon as the panel opens, without a click first.
|
|
156
|
+
NSView *content = window.contentView;
|
|
157
|
+
if (window.firstResponder == window && content.acceptsFirstResponder) [window makeFirstResponder:content];
|
|
128
158
|
}
|
|
129
159
|
|
|
130
160
|
- (void)hide {
|
|
@@ -135,9 +165,19 @@ static const NSTimeInterval kHiddenTick = 1.0 / 20.0;
|
|
|
135
165
|
[self hide];
|
|
136
166
|
}
|
|
137
167
|
|
|
168
|
+
- (void)otherWindowBecameKey:(NSNotification *)notification {
|
|
169
|
+
NSWindow *window = notification.object;
|
|
170
|
+
if (window != self.window && window.canBecomeMainWindow && self.shown) [self hide];
|
|
171
|
+
}
|
|
172
|
+
|
|
138
173
|
- (void)tickWhileHidden:(NSTimer *)timer {
|
|
139
174
|
if (self.shown) return;
|
|
140
175
|
id delegate = NSApp.delegate;
|
|
176
|
+
// An open `<window>` element's own display link drives frames then.
|
|
177
|
+
const SEL drives = @selector(geaAuxiliaryWindowDrivesFrames);
|
|
178
|
+
if ([delegate respondsToSelector:drives] &&
|
|
179
|
+
reinterpret_cast<BOOL (*)(id, SEL)>([delegate methodForSelector:drives])(delegate, drives))
|
|
180
|
+
return;
|
|
141
181
|
if ([delegate respondsToSelector:@selector(tick)]) [delegate performSelector:@selector(tick)];
|
|
142
182
|
}
|
|
143
183
|
|
|
@@ -161,6 +201,8 @@ bool install(const std::string &symbol) {
|
|
|
161
201
|
return true;
|
|
162
202
|
}
|
|
163
203
|
|
|
204
|
+
bool active() { return installed != nil; }
|
|
205
|
+
|
|
164
206
|
void setSymbol(const std::string &symbol) { [installed setSymbol:nsString(symbol)]; }
|
|
165
207
|
|
|
166
208
|
bool shown() { return installed ? installed.shown : true; }
|
|
@@ -169,6 +211,10 @@ void show() { [installed show]; }
|
|
|
169
211
|
|
|
170
212
|
void hide() { [installed hide]; }
|
|
171
213
|
|
|
214
|
+
void setMenu(double menu) { gCustomMenu = menu; }
|
|
215
|
+
|
|
216
|
+
void *nativeSecondaryMenu() { return (__bridge void *)[installed secondaryMenu]; }
|
|
217
|
+
|
|
172
218
|
} // namespace gea::host::menu_bar_platform
|
|
173
219
|
|
|
174
220
|
#endif
|
package/host/tile_loader.cpp
CHANGED
|
@@ -69,7 +69,7 @@ std::int64_t nowUs() {
|
|
|
69
69
|
|
|
70
70
|
std::vector<std::uint8_t> readWholeFile(const std::string &path) {
|
|
71
71
|
std::vector<std::uint8_t> out;
|
|
72
|
-
std::FILE *f = std::fopen(path.c_str(), "rb");
|
|
72
|
+
std::FILE *f = std::fopen(gea::platform::storage::hostPath(path).c_str(), "rb");
|
|
73
73
|
if (!f) return out;
|
|
74
74
|
std::fseek(f, 0, SEEK_END);
|
|
75
75
|
const long size = std::ftell(f);
|
|
@@ -193,7 +193,8 @@ volatile bool g_prune_pending = false;
|
|
|
193
193
|
|
|
194
194
|
// Delete every tiles/<z> level directory whose z is NOT in the keep CSV.
|
|
195
195
|
// Depth-2 tree remove (z/x/y.png) over FAT — worker core only.
|
|
196
|
-
void pruneTileLevels(const std::string &
|
|
196
|
+
void pruneTileLevels(const std::string &logicalRoot, const std::string &keepCsv) {
|
|
197
|
+
const std::string root = gea::platform::storage::hostPath(logicalRoot);
|
|
197
198
|
std::unordered_set<std::string> keep;
|
|
198
199
|
std::string token;
|
|
199
200
|
for (char c : keepCsv + ",") {
|
|
@@ -244,7 +245,8 @@ void pruneTileLevels(const std::string &root, const std::string &keepCsv) {
|
|
|
244
245
|
// One-time census of the persistent tile cache: logs how many tiles each zoom
|
|
245
246
|
// level holds (tiles/<z>/<x>/<y>.png). Runs once on the worker core before the
|
|
246
247
|
// first job — readdir over FAT is slow, so it must never touch the frame task.
|
|
247
|
-
void logTileCensus(const std::string &
|
|
248
|
+
void logTileCensus(const std::string &logicalRoot) {
|
|
249
|
+
const std::string root = gea::platform::storage::hostPath(logicalRoot);
|
|
248
250
|
DIR *zDir = opendir(root.c_str());
|
|
249
251
|
if (!zDir) return;
|
|
250
252
|
int totalFiles = 0;
|
|
@@ -34,9 +34,11 @@
|
|
|
34
34
|
#include "host/profiler.h"
|
|
35
35
|
#include "host/storage.h"
|
|
36
36
|
#include "host/battery.h"
|
|
37
|
+
#include "host/background.h"
|
|
37
38
|
#include "host/crypto.h"
|
|
38
39
|
#include "host/opus.h"
|
|
39
40
|
#include "host/files.h"
|
|
41
|
+
#include "host/menu.h"
|
|
40
42
|
#include "host/menu_bar.h"
|
|
41
43
|
#include "host/notify.h"
|
|
42
44
|
#include "host/device_control.h"
|
package/include/host/audio.h
CHANGED
|
@@ -265,6 +265,18 @@ class HTMLAudioElement {
|
|
|
265
265
|
bool autoplay() const;
|
|
266
266
|
void setAutoplay(bool enabled) const;
|
|
267
267
|
bool paused() const;
|
|
268
|
+
// File playback position in seconds (`src` only; a srcObject stream reads 0).
|
|
269
|
+
// Live while playing, held while paused, 0 before the first play().
|
|
270
|
+
double currentTime() const;
|
|
271
|
+
// Seek: clamped to [0, duration]. While playing, playback continues from
|
|
272
|
+
// there; while paused, the next play() starts there. At or past the end the
|
|
273
|
+
// element ends (paused and ended turn true).
|
|
274
|
+
void setCurrentTime(double seconds) const;
|
|
275
|
+
// Length of `src` in seconds, read from the file on first use. NaN while no
|
|
276
|
+
// src is set or the file cannot be opened; +Infinity for a srcObject stream.
|
|
277
|
+
double duration() const;
|
|
278
|
+
// The file played (or was seeked) to its end. play() then restarts at 0.
|
|
279
|
+
bool ended() const;
|
|
268
280
|
explicit operator bool() const { return static_cast<bool>(state_); }
|
|
269
281
|
bool operator==(std::nullptr_t) const { return !state_; }
|
|
270
282
|
bool operator==(const HTMLAudioElement& other) const { return state_ == other.state_; }
|
package/include/host/backends.h
CHANGED
|
@@ -23,6 +23,10 @@ public:
|
|
|
23
23
|
static double gyroscopeX();
|
|
24
24
|
static double gyroscopeY();
|
|
25
25
|
static double gyroscopeZ();
|
|
26
|
+
static double attitudeX();
|
|
27
|
+
static double attitudeY();
|
|
28
|
+
static double attitudeZ();
|
|
29
|
+
static double attitudeW();
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
} // namespace gea::framework::sensors
|