@geastack/apple 0.2.9 → 0.2.11
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 +46 -0
- package/dist/desktop-api.d.ts +3 -0
- package/dist/desktop-api.js +187 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +47 -1
- package/generated/AppKit.d.ts +32 -1
- package/generated/Foundation.d.ts +8 -0
- package/generated/Security.d.ts +3 -0
- package/generated/UserNotifications.d.ts +3 -0
- package/package.json +12 -3
- package/runtime/AVFoundation.js +1 -1
- package/runtime/ActivityKit.js +1 -1
- package/runtime/AppKit.js +38 -5
- package/runtime/CoreGraphics.js +1 -1
- package/runtime/CoreLocation.js +1 -1
- package/runtime/CoreMedia.js +1 -1
- package/runtime/Dispatch.js +1 -1
- package/runtime/Foundation.js +29 -1
- package/runtime/MapKit.js +1 -1
- package/runtime/Metal.js +1 -1
- package/runtime/MetalKit.js +1 -1
- package/runtime/Photos.js +1 -1
- package/runtime/QuartzCore.js +1 -1
- package/runtime/Security.js +15 -0
- package/runtime/SwiftData.js +1 -1
- package/runtime/UIKit.js +1 -1
- package/runtime/UserNotifications.js +15 -0
- package/targets/ios/generate-xcode-project.mjs +2 -0
- package/targets/macos/README.md +6 -6
- package/targets/macos/build-macos.sh +1 -1
- package/targets/macos/main/macos_renderer.mm +172 -37
package/README.md
CHANGED
|
@@ -43,6 +43,52 @@ Calls into these bindings are compiled to native Objective-C++ by `geatsc`
|
|
|
43
43
|
through `@geastack/geatsc-plugin-apple-native`, which reads binding metadata
|
|
44
44
|
the build generates from this package's declarations.
|
|
45
45
|
|
|
46
|
+
## Desktop services
|
|
47
|
+
|
|
48
|
+
`@geastack/apple/AppKit` exports `NSStatusBar`, `NSStatusItem`, `NSStatusBarButton`,
|
|
49
|
+
`NSMenu`, and `NSMenuItem`. Obtain the shared bar with
|
|
50
|
+
`NSStatusBar.systemStatusBar()`, create an item with `statusItemWithLength(-1)`
|
|
51
|
+
(variable width), set its button title or menu, and retain the item while it is
|
|
52
|
+
in use. Menu items use the existing `ObjCTarget`/selector action bridge.
|
|
53
|
+
Remove the item with `removeStatusItem(item)` when finished.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { randomUUID, localTimeZone, readTextFile, writeTextFile,
|
|
57
|
+
watchPath, stopWatchingPath, sharedContainerPath } from '@geastack/apple/Foundation'
|
|
58
|
+
|
|
59
|
+
const id = randomUUID()
|
|
60
|
+
const timeZone = localTimeZone() // IANA time-zone name
|
|
61
|
+
const folder = sharedContainerPath('group.example.app')
|
|
62
|
+
writeTextFile(folder + '/snapshot.json', JSON.stringify({ id, timeZone }))
|
|
63
|
+
const watch = watchPath(folder, () => {
|
|
64
|
+
const snapshot = readTextFile(folder + '/snapshot.json')
|
|
65
|
+
// Reload application state from the snapshot.
|
|
66
|
+
})
|
|
67
|
+
// Call when the owner is disposed:
|
|
68
|
+
stopWatchingPath(watch)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
File reads and atomic UTF-8 writes are synchronous. Errors throw. Path observation delivers callbacks on the main queue. Observe a file for
|
|
72
|
+
in-place writes, or its directory for entry changes and atomic file replacements.
|
|
73
|
+
Observation is not recursive; after replacing a file, recreate its file observer
|
|
74
|
+
or keep observing its directory. Stop observing before releasing callback-owned state. Sandbox file access
|
|
75
|
+
still requires the application's usual entitlements or granted access.
|
|
76
|
+
`sharedContainerPath` requires matching App Group entitlements on the app and its
|
|
77
|
+
WidgetKit extension. It exposes shared storage; the extension remains a separate
|
|
78
|
+
Xcode target.
|
|
79
|
+
|
|
80
|
+
`@geastack/apple/Security` exports `writePassword(service, account, password)`,
|
|
81
|
+
`readPassword(service, account)`, and `deletePassword(service, account)`. Write
|
|
82
|
+
and delete return the native `OSStatus` (zero means success); read throws on a
|
|
83
|
+
failed lookup. They use generic-password Keychain items.
|
|
84
|
+
|
|
85
|
+
`@geastack/apple/UserNotifications` exports `requestAuthorization(callback)`,
|
|
86
|
+
`scheduleNotification(id, title, body, delaySeconds, callback)`, and
|
|
87
|
+
`cancelNotification(id)`. Authorization returns `(granted, error)`; scheduling
|
|
88
|
+
returns an error string (empty on success). Delays must be positive and finite.
|
|
89
|
+
Completion callbacks run on the main queue. Request authorization from the
|
|
90
|
+
signed application before scheduling; the operating system controls delivery.
|
|
91
|
+
|
|
46
92
|
## App Store
|
|
47
93
|
|
|
48
94
|
The package is Apache-2.0, so App Store distribution has no license obstacle
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
const string = { kind: 'primitive', name: 'string' };
|
|
2
|
+
const number = { kind: 'primitive', name: 'number' };
|
|
3
|
+
const boolean = { kind: 'primitive', name: 'boolean' };
|
|
4
|
+
const nothing = { kind: 'primitive', name: 'void' };
|
|
5
|
+
const callback = { kind: 'function', returns: nothing };
|
|
6
|
+
const completion = {
|
|
7
|
+
kind: 'function',
|
|
8
|
+
returns: nothing,
|
|
9
|
+
parameters: [{ name: 'error', type: string }]
|
|
10
|
+
};
|
|
11
|
+
export const foundationServices = [
|
|
12
|
+
{
|
|
13
|
+
name: 'randomUUID',
|
|
14
|
+
returns: string,
|
|
15
|
+
bridgeBody: 'return gea::apple::Foundation::fromNSString([[NSUUID UUID] UUIDString]);'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'localTimeZone',
|
|
19
|
+
returns: string,
|
|
20
|
+
bridgeBody: 'return gea::apple::Foundation::fromNSString([[NSTimeZone localTimeZone] name]);'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'sharedContainerPath',
|
|
24
|
+
returns: string,
|
|
25
|
+
parameters: [{ name: 'groupIdentifier', type: string }],
|
|
26
|
+
bridgeBody: `::NSURL *url = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:gea::apple::Foundation::toNSString(groupIdentifier)];
|
|
27
|
+
if (!url) throw std::runtime_error("App Group container is unavailable; check the application's entitlements");
|
|
28
|
+
return gea::apple::Foundation::fromNSString(url.path);`
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'readTextFile',
|
|
32
|
+
returns: string,
|
|
33
|
+
parameters: [{ name: 'path', type: string }],
|
|
34
|
+
bridgeBody: `NSError *error = nil;
|
|
35
|
+
NSString *text = [NSString stringWithContentsOfFile:gea::apple::Foundation::toNSString(path) encoding:NSUTF8StringEncoding error:&error];
|
|
36
|
+
if (!text) throw std::runtime_error(gea::apple::Foundation::fromNSString(error.localizedDescription));
|
|
37
|
+
return gea::apple::Foundation::fromNSString(text);`
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'writeTextFile',
|
|
41
|
+
returns: nothing,
|
|
42
|
+
parameters: [
|
|
43
|
+
{ name: 'path', type: string },
|
|
44
|
+
{ name: 'text', type: string }
|
|
45
|
+
],
|
|
46
|
+
bridgeBody: `NSError *error = nil;
|
|
47
|
+
if (![gea::apple::Foundation::toNSString(text) writeToFile:gea::apple::Foundation::toNSString(path) atomically:YES encoding:NSUTF8StringEncoding error:&error])
|
|
48
|
+
throw std::runtime_error(gea::apple::Foundation::fromNSString(error.localizedDescription));`
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'watchPath',
|
|
52
|
+
returns: number,
|
|
53
|
+
parameters: [
|
|
54
|
+
{ name: 'path', type: string },
|
|
55
|
+
{ name: 'changed', type: callback }
|
|
56
|
+
],
|
|
57
|
+
bridgeBody: `const int descriptor = open(path.c_str(), O_EVTONLY);
|
|
58
|
+
if (descriptor < 0) throw std::runtime_error("Cannot open path for observation");
|
|
59
|
+
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, descriptor,
|
|
60
|
+
DISPATCH_VNODE_WRITE | DISPATCH_VNODE_DELETE | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_EXTEND | DISPATCH_VNODE_ATTRIB,
|
|
61
|
+
dispatch_get_main_queue());
|
|
62
|
+
if (!source) { close(descriptor); throw std::runtime_error("Cannot observe path"); }
|
|
63
|
+
dispatch_source_set_event_handler(source, ^{ if (changed) changed(); });
|
|
64
|
+
dispatch_source_set_cancel_handler(source, ^{ close(descriptor); });
|
|
65
|
+
const double handle = gea::apple::objc::retain((__bridge void *)source);
|
|
66
|
+
dispatch_resume(source);
|
|
67
|
+
return handle;`
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'stopWatchingPath',
|
|
71
|
+
returns: nothing,
|
|
72
|
+
parameters: [{ name: 'handle', type: number }],
|
|
73
|
+
bridgeBody: `dispatch_source_t source = (__bridge dispatch_source_t)gea::apple::objc::object(handle);
|
|
74
|
+
if (source) { dispatch_source_cancel(source); gea::apple::objc::release(handle); }`
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
export const desktopFrameworks = [
|
|
78
|
+
{
|
|
79
|
+
name: 'Security',
|
|
80
|
+
bridgeHeaders: ['Security/Security.h', 'stdexcept'],
|
|
81
|
+
functions: [
|
|
82
|
+
{
|
|
83
|
+
name: 'writePassword',
|
|
84
|
+
returns: number,
|
|
85
|
+
parameters: [
|
|
86
|
+
{ name: 'service', type: string },
|
|
87
|
+
{ name: 'account', type: string },
|
|
88
|
+
{ name: 'password', type: string }
|
|
89
|
+
],
|
|
90
|
+
bridgeBody: `NSDictionary *query = @{(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
|
|
91
|
+
(__bridge id)kSecAttrService: gea::apple::Foundation::toNSString(service),
|
|
92
|
+
(__bridge id)kSecAttrAccount: gea::apple::Foundation::toNSString(account)};
|
|
93
|
+
NSData *data = [NSData dataWithBytes:password.data() length:password.size()];
|
|
94
|
+
OSStatus status = SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)@{(__bridge id)kSecValueData: data});
|
|
95
|
+
if (status == errSecItemNotFound) {
|
|
96
|
+
NSMutableDictionary *item = [query mutableCopy];
|
|
97
|
+
item[(__bridge id)kSecValueData] = data;
|
|
98
|
+
status = SecItemAdd((__bridge CFDictionaryRef)item, nullptr);
|
|
99
|
+
}
|
|
100
|
+
return status;`
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'readPassword',
|
|
104
|
+
returns: string,
|
|
105
|
+
parameters: [
|
|
106
|
+
{ name: 'service', type: string },
|
|
107
|
+
{ name: 'account', type: string }
|
|
108
|
+
],
|
|
109
|
+
bridgeBody: `NSDictionary *query = @{(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
|
|
110
|
+
(__bridge id)kSecAttrService: gea::apple::Foundation::toNSString(service),
|
|
111
|
+
(__bridge id)kSecAttrAccount: gea::apple::Foundation::toNSString(account),
|
|
112
|
+
(__bridge id)kSecReturnData: @YES, (__bridge id)kSecMatchLimit: (__bridge id)kSecMatchLimitOne};
|
|
113
|
+
CFTypeRef result = nullptr;
|
|
114
|
+
const OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result);
|
|
115
|
+
if (status != errSecSuccess) throw std::runtime_error("Keychain read failed: " + std::to_string(status));
|
|
116
|
+
NSData *data = CFBridgingRelease(result);
|
|
117
|
+
return std::string(static_cast<const char *>(data.bytes), data.length);`
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'deletePassword',
|
|
121
|
+
returns: number,
|
|
122
|
+
parameters: [
|
|
123
|
+
{ name: 'service', type: string },
|
|
124
|
+
{ name: 'account', type: string }
|
|
125
|
+
],
|
|
126
|
+
bridgeBody: `return SecItemDelete((__bridge CFDictionaryRef)@{(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
|
|
127
|
+
(__bridge id)kSecAttrService: gea::apple::Foundation::toNSString(service),
|
|
128
|
+
(__bridge id)kSecAttrAccount: gea::apple::Foundation::toNSString(account)});`
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'UserNotifications',
|
|
134
|
+
bridgeHeaders: ['UserNotifications/UserNotifications.h'],
|
|
135
|
+
functions: [
|
|
136
|
+
{
|
|
137
|
+
name: 'requestAuthorization',
|
|
138
|
+
returns: nothing,
|
|
139
|
+
parameters: [
|
|
140
|
+
{
|
|
141
|
+
name: 'completed',
|
|
142
|
+
type: {
|
|
143
|
+
kind: 'function',
|
|
144
|
+
returns: nothing,
|
|
145
|
+
parameters: [
|
|
146
|
+
{ name: 'granted', type: boolean },
|
|
147
|
+
{ name: 'error', type: string }
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
bridgeBody: `[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
|
|
153
|
+
completionHandler:^(BOOL granted, NSError *error) {
|
|
154
|
+
const std::string message = gea::apple::Foundation::fromNSString(error.localizedDescription);
|
|
155
|
+
dispatch_async(dispatch_get_main_queue(), ^{ if (completed) completed(granted, message); });
|
|
156
|
+
}];`
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: 'scheduleNotification',
|
|
160
|
+
returns: nothing,
|
|
161
|
+
parameters: [
|
|
162
|
+
{ name: 'identifier', type: string },
|
|
163
|
+
{ name: 'title', type: string },
|
|
164
|
+
{ name: 'body', type: string },
|
|
165
|
+
{ name: 'delaySeconds', type: number },
|
|
166
|
+
{ name: 'completed', type: completion }
|
|
167
|
+
],
|
|
168
|
+
bridgeBody: `if (!std::isfinite(delaySeconds) || delaySeconds <= 0) { if (completed) completed("delaySeconds must be positive and finite"); return; }
|
|
169
|
+
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
|
|
170
|
+
content.title = gea::apple::Foundation::toNSString(title);
|
|
171
|
+
content.body = gea::apple::Foundation::toNSString(body);
|
|
172
|
+
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:delaySeconds repeats:NO];
|
|
173
|
+
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:gea::apple::Foundation::toNSString(identifier) content:content trigger:trigger];
|
|
174
|
+
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError *error) {
|
|
175
|
+
const std::string message = gea::apple::Foundation::fromNSString(error.localizedDescription);
|
|
176
|
+
dispatch_async(dispatch_get_main_queue(), ^{ if (completed) completed(message); });
|
|
177
|
+
}];`
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'cancelNotification',
|
|
181
|
+
returns: nothing,
|
|
182
|
+
parameters: [{ name: 'identifier', type: string }],
|
|
183
|
+
bridgeBody: '[[UNUserNotificationCenter currentNotificationCenter] removePendingNotificationRequestsWithIdentifiers:@[gea::apple::Foundation::toNSString(identifier)]];'
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
];
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface ApplePropertyDefinition {
|
|
|
30
30
|
readonly?: boolean;
|
|
31
31
|
}
|
|
32
32
|
export interface AppleFunctionDefinition {
|
|
33
|
+
bridgeBody?: string;
|
|
33
34
|
name: string;
|
|
34
35
|
returns: AppleTypeReference;
|
|
35
36
|
parameters?: AppleParameterDefinition[];
|
|
@@ -79,6 +80,7 @@ export interface AppleBridgeConstantMetadata {
|
|
|
79
80
|
value: string | number | boolean;
|
|
80
81
|
}
|
|
81
82
|
export interface AppleBridgeFunctionMetadata {
|
|
83
|
+
bridgeBody?: string;
|
|
82
84
|
framework: string;
|
|
83
85
|
name: string;
|
|
84
86
|
thunk: string;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { foundationServices, desktopFrameworks } from './desktop-api.js';
|
|
1
2
|
const objcFrameworkImports = {
|
|
2
3
|
AVFoundation: 'AVFoundation/AVFoundation.h',
|
|
3
4
|
CoreMedia: 'CoreMedia/CoreMedia.h',
|
|
@@ -90,6 +91,8 @@ export const appleSdkFixture = {
|
|
|
90
91
|
frameworks: [
|
|
91
92
|
{
|
|
92
93
|
name: 'Foundation',
|
|
94
|
+
bridgeHeaders: ['dispatch/dispatch.h', 'fcntl.h', 'unistd.h', 'stdexcept', 'cmath'],
|
|
95
|
+
functions: foundationServices,
|
|
93
96
|
classes: [
|
|
94
97
|
{ name: 'NSObject' },
|
|
95
98
|
{ name: 'NSData', extends: 'Foundation.NSObject' },
|
|
@@ -1941,6 +1944,40 @@ export const appleSdkFixture = {
|
|
|
1941
1944
|
{ name: 'contentTintColor', type: { kind: 'class', name: 'AppKit.NSColor', nullable: true } },
|
|
1942
1945
|
],
|
|
1943
1946
|
},
|
|
1947
|
+
{
|
|
1948
|
+
name: 'NSMenuItem', extends: 'Foundation.NSObject',
|
|
1949
|
+
constructors: [{ name: 'init', selector: 'init', returns: { kind: 'class', name: 'AppKit.NSMenuItem' } }],
|
|
1950
|
+
properties: [
|
|
1951
|
+
{ name: 'title', type: stringType },
|
|
1952
|
+
{ name: 'keyEquivalent', type: stringType },
|
|
1953
|
+
{ name: 'target', type: { kind: 'class', name: 'Foundation.NSObject', nullable: true } },
|
|
1954
|
+
{ name: 'action', type: selectorType },
|
|
1955
|
+
{ name: 'enabled', type: { kind: 'primitive', name: 'boolean' } },
|
|
1956
|
+
],
|
|
1957
|
+
},
|
|
1958
|
+
{
|
|
1959
|
+
name: 'NSMenu', extends: 'Foundation.NSObject',
|
|
1960
|
+
constructors: [{ name: 'init', selector: 'init', returns: { kind: 'class', name: 'AppKit.NSMenu' } }],
|
|
1961
|
+
properties: [{ name: 'autoenablesItems', type: { kind: 'primitive', name: 'boolean' } }],
|
|
1962
|
+
methods: [{ name: 'addItem', selector: 'addItem:', returns: voidType, parameters: [{ name: 'item', type: { kind: 'class', name: 'AppKit.NSMenuItem' } }] }],
|
|
1963
|
+
},
|
|
1964
|
+
{
|
|
1965
|
+
name: 'NSStatusBar', extends: 'Foundation.NSObject',
|
|
1966
|
+
methods: [
|
|
1967
|
+
{ name: 'systemStatusBar', selector: 'systemStatusBar', static: true, returns: { kind: 'class', name: 'AppKit.NSStatusBar' } },
|
|
1968
|
+
{ name: 'statusItemWithLength', selector: 'statusItemWithLength:', returns: { kind: 'class', name: 'AppKit.NSStatusItem' }, parameters: [{ name: 'length', type: numberType }] },
|
|
1969
|
+
{ name: 'removeStatusItem', selector: 'removeStatusItem:', returns: voidType, parameters: [{ name: 'item', type: { kind: 'class', name: 'AppKit.NSStatusItem' } }] },
|
|
1970
|
+
],
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
name: 'NSStatusItem', extends: 'Foundation.NSObject',
|
|
1974
|
+
properties: [
|
|
1975
|
+
{ name: 'menu', type: { kind: 'class', name: 'AppKit.NSMenu', nullable: true } },
|
|
1976
|
+
{ name: 'button', readonly: true, type: { kind: 'class', name: 'AppKit.NSStatusBarButton', nullable: true } },
|
|
1977
|
+
{ name: 'visible', type: { kind: 'primitive', name: 'boolean' } },
|
|
1978
|
+
{ name: 'length', type: numberType },
|
|
1979
|
+
],
|
|
1980
|
+
},
|
|
1944
1981
|
{
|
|
1945
1982
|
name: 'NSButton',
|
|
1946
1983
|
extends: 'AppKit.NSControl',
|
|
@@ -1950,6 +1987,7 @@ export const appleSdkFixture = {
|
|
|
1950
1987
|
{ name: 'bordered', type: { kind: 'primitive', name: 'boolean' } },
|
|
1951
1988
|
],
|
|
1952
1989
|
},
|
|
1990
|
+
{ name: 'NSStatusBarButton', extends: 'AppKit.NSButton' },
|
|
1953
1991
|
{
|
|
1954
1992
|
name: 'NSViewController',
|
|
1955
1993
|
extends: 'Foundation.NSObject',
|
|
@@ -2126,6 +2164,7 @@ export const appleSdkFixture = {
|
|
|
2126
2164
|
},
|
|
2127
2165
|
],
|
|
2128
2166
|
},
|
|
2167
|
+
...desktopFrameworks,
|
|
2129
2168
|
],
|
|
2130
2169
|
};
|
|
2131
2170
|
export function generateAppleDeclarations(sdk) {
|
|
@@ -2274,7 +2313,7 @@ function sourceBackedBridgeDeclarations(metadata) {
|
|
|
2274
2313
|
declarations.push(bridgeDeclaration(name, returnType, params));
|
|
2275
2314
|
};
|
|
2276
2315
|
for (const fn of Object.values(metadata.functions)) {
|
|
2277
|
-
if (fn.framework === 'Dispatch' || fn.framework === 'Metal') {
|
|
2316
|
+
if (fn.bridgeBody !== undefined || fn.framework === 'Dispatch' || fn.framework === 'Metal') {
|
|
2278
2317
|
append(fn.thunk, cppValueType(fn.returns, fn.framework), fn.parameters.map((parameter) => bridgeParameter(parameter, fn.framework)).join(', '));
|
|
2279
2318
|
}
|
|
2280
2319
|
}
|
|
@@ -2352,6 +2391,12 @@ export function generateAppleNativeBridgeObjCxxSource(metadata) {
|
|
|
2352
2391
|
}
|
|
2353
2392
|
lines.push('', '#include <cstdint>', '#include <functional>', '#include <mutex>', '#include <unordered_map>', '#include <utility>', '#include <vector>', '', 'namespace {', 'std::mutex geaAppleObjectMutex;', 'std::unordered_map<std::uint64_t, void *> geaAppleObjects;', 'std::uint64_t geaAppleNextObjectHandle = 1;', '}', '', 'namespace gea::apple::objc {', 'void *object(double handle) {', ' if (handle <= 0) return nullptr;', ' const auto key = static_cast<std::uint64_t>(handle);', ' std::lock_guard<std::mutex> lock(geaAppleObjectMutex);', ' const auto found = geaAppleObjects.find(key);', ' return found == geaAppleObjects.end() ? nullptr : found->second;', '}', '', 'double retain(void *object) {', ' if (!object) return 0;', ' void *retained = const_cast<void *>(CFRetain(object));', ' std::lock_guard<std::mutex> lock(geaAppleObjectMutex);', ' const auto handle = geaAppleNextObjectHandle++;', ' geaAppleObjects.emplace(handle, retained);', ' return static_cast<double>(handle);', '}', '', 'void release(double handle) {', ' if (handle <= 0) return;', ' void *object = nullptr;', ' {', ' std::lock_guard<std::mutex> lock(geaAppleObjectMutex);', ' const auto key = static_cast<std::uint64_t>(handle);', ' const auto found = geaAppleObjects.find(key);', ' if (found == geaAppleObjects.end()) return;', ' object = found->second;', ' geaAppleObjects.erase(found);', ' }', ' CFRelease(object);', '}', '}', '');
|
|
2354
2393
|
appendFoundationStringConversions(lines, metadata);
|
|
2394
|
+
for (const fn of Object.values(metadata.functions)) {
|
|
2395
|
+
if (fn.bridgeBody === undefined)
|
|
2396
|
+
continue;
|
|
2397
|
+
const parameters = fn.parameters.map((parameter) => bridgeParameter(parameter, fn.framework)).join(', ');
|
|
2398
|
+
lines.push(`${cppValueType(fn.returns, fn.framework)} ${fn.thunk}(${parameters}) {`, fn.bridgeBody, '}', '');
|
|
2399
|
+
}
|
|
2355
2400
|
appendDispatchBridges(lines, metadata);
|
|
2356
2401
|
appendAVFoundationBridges(lines, metadata);
|
|
2357
2402
|
appendPhotosBridges(lines, metadata);
|
|
@@ -2928,6 +2973,7 @@ function functionMetadata(framework, fn) {
|
|
|
2928
2973
|
thunk: frameworkFunctionThunk(framework, fn.name),
|
|
2929
2974
|
returns: fn.returns,
|
|
2930
2975
|
parameters: fn.parameters ?? [],
|
|
2976
|
+
...(fn.bridgeBody !== undefined ? { bridgeBody: fn.bridgeBody } : {}),
|
|
2931
2977
|
};
|
|
2932
2978
|
}
|
|
2933
2979
|
function methodMetadata(framework, cls, method) {
|
package/generated/AppKit.d.ts
CHANGED
|
@@ -57,8 +57,8 @@ export declare const ObjCTargetAction: Selector
|
|
|
57
57
|
export declare function installRootView(view: NSView): void
|
|
58
58
|
export declare function installRootViewController(viewController: NSViewController): void
|
|
59
59
|
export declare function installToolbar(spec: string, newNoteTarget: NSObject | null): void
|
|
60
|
-
export declare function setScrollDocumentTopAligned(scrollView: NSScrollView, content: NSView): void
|
|
61
60
|
export declare function runDeviceCommand(command: string): string
|
|
61
|
+
export declare function setScrollDocumentTopAligned(scrollView: NSScrollView, content: NSView): void
|
|
62
62
|
|
|
63
63
|
export declare class NSColor extends NSObject {
|
|
64
64
|
static whiteColor(): NSColor
|
|
@@ -240,12 +240,43 @@ export declare class NSImageView extends NSView {
|
|
|
240
240
|
contentTintColor: NSColor | null
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
export declare class NSMenuItem extends NSObject {
|
|
244
|
+
constructor()
|
|
245
|
+
title: string
|
|
246
|
+
keyEquivalent: string
|
|
247
|
+
target: NSObject | null
|
|
248
|
+
action: Selector
|
|
249
|
+
enabled: boolean
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export declare class NSMenu extends NSObject {
|
|
253
|
+
constructor()
|
|
254
|
+
autoenablesItems: boolean
|
|
255
|
+
addItem(item: NSMenuItem): void
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export declare class NSStatusBar extends NSObject {
|
|
259
|
+
static systemStatusBar(): NSStatusBar
|
|
260
|
+
statusItemWithLength(length: number): NSStatusItem
|
|
261
|
+
removeStatusItem(item: NSStatusItem): void
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export declare class NSStatusItem extends NSObject {
|
|
265
|
+
menu: NSMenu | null
|
|
266
|
+
readonly button: NSStatusBarButton | null
|
|
267
|
+
visible: boolean
|
|
268
|
+
length: number
|
|
269
|
+
}
|
|
270
|
+
|
|
243
271
|
export declare class NSButton extends NSControl {
|
|
244
272
|
constructor()
|
|
245
273
|
title: string
|
|
246
274
|
bordered: boolean
|
|
247
275
|
}
|
|
248
276
|
|
|
277
|
+
export declare class NSStatusBarButton extends NSButton {
|
|
278
|
+
}
|
|
279
|
+
|
|
249
280
|
export declare class NSViewController extends NSObject {
|
|
250
281
|
constructor()
|
|
251
282
|
view: NSView
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export declare function randomUUID(): string
|
|
2
|
+
export declare function localTimeZone(): string
|
|
3
|
+
export declare function sharedContainerPath(groupIdentifier: string): string
|
|
4
|
+
export declare function readTextFile(path: string): string
|
|
5
|
+
export declare function writeTextFile(path: string, text: string): void
|
|
6
|
+
export declare function watchPath(path: string, changed: () => void): number
|
|
7
|
+
export declare function stopWatchingPath(handle: number): void
|
|
8
|
+
|
|
1
9
|
export declare class NSObject {
|
|
2
10
|
}
|
|
3
11
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function requestAuthorization(completed: (granted: boolean, error: string) => void): void
|
|
2
|
+
export declare function scheduleNotification(identifier: string, title: string, body: string, delaySeconds: number, completed: (error: string) => void): void
|
|
3
|
+
export declare function cancelNotification(identifier: string): void
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/apple",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Generated Apple SDK bindings plus the macOS and iOS native build targets for Gea apps.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
"types": "./generated/Foundation.d.ts",
|
|
25
25
|
"import": "./runtime/Foundation.js"
|
|
26
26
|
},
|
|
27
|
+
"./Security": {
|
|
28
|
+
"types": "./generated/Security.d.ts",
|
|
29
|
+
"import": "./runtime/Security.js"
|
|
30
|
+
},
|
|
31
|
+
"./UserNotifications": {
|
|
32
|
+
"types": "./generated/UserNotifications.d.ts",
|
|
33
|
+
"import": "./runtime/UserNotifications.js"
|
|
34
|
+
},
|
|
27
35
|
"./Dispatch": {
|
|
28
36
|
"types": "./generated/Dispatch.d.ts",
|
|
29
37
|
"import": "./runtime/Dispatch.js"
|
|
@@ -84,7 +92,8 @@
|
|
|
84
92
|
"./targets/*": "./targets/*"
|
|
85
93
|
},
|
|
86
94
|
"files": [
|
|
87
|
-
"dist",
|
|
95
|
+
"dist/*.js",
|
|
96
|
+
"dist/*.d.ts",
|
|
88
97
|
"generated",
|
|
89
98
|
"runtime",
|
|
90
99
|
"targets",
|
|
@@ -107,7 +116,7 @@
|
|
|
107
116
|
"@geastack/elements": "^0.1.2",
|
|
108
117
|
"@geastack/engine": "^0.1.5",
|
|
109
118
|
"@geastack/geaos": "^0.1.3",
|
|
110
|
-
"@geastack/geatsc-plugin-apple-native": "^0.1.
|
|
119
|
+
"@geastack/geatsc-plugin-apple-native": "^0.1.4",
|
|
111
120
|
"@geastack/geatsc-plugin-gea": "^0.1.6",
|
|
112
121
|
"@geastack/host": "^0.1.8"
|
|
113
122
|
},
|
package/runtime/AVFoundation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleAVFoundationNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/AVFoundation ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export const AVMediaTypeVideo = "vide"
|
package/runtime/ActivityKit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleActivityKitNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/ActivityKit ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function requestLiveActivity() {
|
package/runtime/AppKit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleAppKitNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/AppKit ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export const NSViewNotSizable = 0
|
|
@@ -64,14 +64,14 @@ export function installToolbar() {
|
|
|
64
64
|
return geaAppleAppKitNativeOnly("installToolbar")
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export function setScrollDocumentTopAligned() {
|
|
68
|
-
return geaAppleAppKitNativeOnly("setScrollDocumentTopAligned")
|
|
69
|
-
}
|
|
70
|
-
|
|
71
67
|
export function runDeviceCommand() {
|
|
72
68
|
return geaAppleAppKitNativeOnly("runDeviceCommand")
|
|
73
69
|
}
|
|
74
70
|
|
|
71
|
+
export function setScrollDocumentTopAligned() {
|
|
72
|
+
return geaAppleAppKitNativeOnly("setScrollDocumentTopAligned")
|
|
73
|
+
}
|
|
74
|
+
|
|
75
75
|
export class NSColor {
|
|
76
76
|
static whiteColor() {
|
|
77
77
|
return geaAppleAppKitNativeOnly("NSColor.whiteColor")
|
|
@@ -279,12 +279,45 @@ export class NSImageView {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
export class NSMenuItem {
|
|
283
|
+
constructor() {
|
|
284
|
+
geaAppleAppKitNativeOnly("new NSMenuItem")
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export class NSMenu {
|
|
289
|
+
constructor() {
|
|
290
|
+
geaAppleAppKitNativeOnly("new NSMenu")
|
|
291
|
+
}
|
|
292
|
+
addItem() {
|
|
293
|
+
return geaAppleAppKitNativeOnly("NSMenu.addItem")
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export class NSStatusBar {
|
|
298
|
+
static systemStatusBar() {
|
|
299
|
+
return geaAppleAppKitNativeOnly("NSStatusBar.systemStatusBar")
|
|
300
|
+
}
|
|
301
|
+
statusItemWithLength() {
|
|
302
|
+
return geaAppleAppKitNativeOnly("NSStatusBar.statusItemWithLength")
|
|
303
|
+
}
|
|
304
|
+
removeStatusItem() {
|
|
305
|
+
return geaAppleAppKitNativeOnly("NSStatusBar.removeStatusItem")
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export class NSStatusItem {
|
|
310
|
+
}
|
|
311
|
+
|
|
282
312
|
export class NSButton {
|
|
283
313
|
constructor() {
|
|
284
314
|
geaAppleAppKitNativeOnly("new NSButton")
|
|
285
315
|
}
|
|
286
316
|
}
|
|
287
317
|
|
|
318
|
+
export class NSStatusBarButton {
|
|
319
|
+
}
|
|
320
|
+
|
|
288
321
|
export class NSViewController {
|
|
289
322
|
constructor() {
|
|
290
323
|
geaAppleAppKitNativeOnly("new NSViewController")
|
package/runtime/CoreGraphics.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleCoreGraphicsNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/CoreGraphics ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function CGRectMake() {
|
package/runtime/CoreLocation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleCoreLocationNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/CoreLocation ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export const kCLLocationAccuracyBest = -1
|
package/runtime/CoreMedia.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleCoreMediaNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/CoreMedia ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function CMTimeMakeWithSeconds() {
|
package/runtime/Dispatch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleDispatchNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/Dispatch ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function dispatchAsyncGlobal() {
|
package/runtime/Foundation.js
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
function geaAppleFoundationNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/Foundation ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function randomUUID() {
|
|
6
|
+
return geaAppleFoundationNativeOnly("randomUUID")
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function localTimeZone() {
|
|
10
|
+
return geaAppleFoundationNativeOnly("localTimeZone")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function sharedContainerPath() {
|
|
14
|
+
return geaAppleFoundationNativeOnly("sharedContainerPath")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function readTextFile() {
|
|
18
|
+
return geaAppleFoundationNativeOnly("readTextFile")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function writeTextFile() {
|
|
22
|
+
return geaAppleFoundationNativeOnly("writeTextFile")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function watchPath() {
|
|
26
|
+
return geaAppleFoundationNativeOnly("watchPath")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function stopWatchingPath() {
|
|
30
|
+
return geaAppleFoundationNativeOnly("stopWatchingPath")
|
|
3
31
|
}
|
|
4
32
|
|
|
5
33
|
export class NSObject {
|
package/runtime/MapKit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleMapKitNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/MapKit ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export const MKMapTypeStandard = 0
|
package/runtime/Metal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleMetalNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/Metal ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export const MTLPixelFormatInvalid = 0
|
package/runtime/MetalKit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleMetalKitNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/MetalKit ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export class MTKView {
|
package/runtime/Photos.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaApplePhotosNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/Photos ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export class PHPhotoLibrary {
|
package/runtime/QuartzCore.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleQuartzCoreNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/QuartzCore ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export class CALayer {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function geaAppleSecurityNativeOnly(name) {
|
|
2
|
+
throw new Error(`@geastack/apple/Security ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function writePassword() {
|
|
6
|
+
return geaAppleSecurityNativeOnly("writePassword")
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function readPassword() {
|
|
10
|
+
return geaAppleSecurityNativeOnly("readPassword")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function deletePassword() {
|
|
14
|
+
return geaAppleSecurityNativeOnly("deletePassword")
|
|
15
|
+
}
|
package/runtime/SwiftData.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleSwiftDataNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/SwiftData ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function openModelContainer() {
|
package/runtime/UIKit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function geaAppleUIKitNativeOnly(name) {
|
|
2
|
-
throw new Error(`@
|
|
2
|
+
throw new Error(`@geastack/apple/UIKit ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export const UIAlertActionStyleDefault = 0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function geaAppleUserNotificationsNativeOnly(name) {
|
|
2
|
+
throw new Error(`@geastack/apple/UserNotifications ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function requestAuthorization() {
|
|
6
|
+
return geaAppleUserNotificationsNativeOnly("requestAuthorization")
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function scheduleNotification() {
|
|
10
|
+
return geaAppleUserNotificationsNativeOnly("scheduleNotification")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function cancelNotification() {
|
|
14
|
+
return geaAppleUserNotificationsNativeOnly("cancelNotification")
|
|
15
|
+
}
|
package/targets/macos/README.md
CHANGED
|
@@ -20,14 +20,14 @@ bundle, `<app>/dist/macos/<app-id>/build/` for objects and PCHs, and
|
|
|
20
20
|
directory the build runs in: `gea build` runs this script in the app, and a
|
|
21
21
|
direct run uses the invocation directory.
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
Output does not go under the package because the package lives in the app's
|
|
24
|
+
`node_modules`, which npm replaces on reinstall. Set `GEA_MACOS_OUTPUT_DIR` to
|
|
25
|
+
put the whole tree elsewhere.
|
|
26
26
|
|
|
27
27
|
`<app-id>` is currently any name; when no generated app is present under
|
|
28
28
|
`dist/macos/.generated/<app-id>/` the build falls back to a built-in
|
|
29
29
|
Phase B smoke app (`macos_smoke_app.cpp`) that exercises View / Text /
|
|
30
|
-
Button / event dispatch.
|
|
30
|
+
Button / event dispatch. geatsc-compiled apps go into
|
|
31
31
|
`dist/macos/.generated/` and supersede the smoke automatically — the
|
|
32
32
|
JSX → C++ pipeline for the macOS target is a follow-up.
|
|
33
33
|
|
|
@@ -116,12 +116,12 @@ Native: View / Text / Button / Image / Canvas / VirtualList; flex
|
|
|
116
116
|
layout; click + press events; trackpad-momentum scroll; window resize
|
|
117
117
|
(live + final); standard menu bar with Cmd-Q.
|
|
118
118
|
|
|
119
|
-
Audio
|
|
119
|
+
Audio: `targets/shared/apple_audio.mm` (shared with iOS) backs
|
|
120
120
|
`gea::platform::audio` with AVAudioEngine — sample-accurately scheduled,
|
|
121
121
|
mixed oscillators on an `AVAudioSourceNode`, plus `playFile`/`playPcm` on
|
|
122
122
|
`AVAudioPlayerNode`s. `targets/shared/build-audio-selftest.sh` builds and
|
|
123
123
|
runs the measurement harness (offline render, RMS + measured frequency);
|
|
124
|
-
`GEA_AUDIO_CAPTURE_RAW=<path>` captures
|
|
124
|
+
`GEA_AUDIO_CAPTURE_RAW=<path>` captures an app run for
|
|
125
125
|
`targets/shared/analyze-audio-capture.mjs`.
|
|
126
126
|
|
|
127
127
|
Stubbed for v1: WiFi (`macos_wifi`), BLE (`macos_ble`), IMU (`macos_imu`)
|
|
@@ -1893,7 +1893,7 @@ if [[ "$APPLE_NATIVE" == "1" ]]; then
|
|
|
1893
1893
|
LINK_FRAMEWORKS+=(
|
|
1894
1894
|
-framework Metal -framework MetalKit -framework MapKit
|
|
1895
1895
|
-framework CoreLocation -framework AVFoundation -framework CoreMedia
|
|
1896
|
-
-framework Photos
|
|
1896
|
+
-framework Photos -framework Security -framework UserNotifications
|
|
1897
1897
|
)
|
|
1898
1898
|
fi
|
|
1899
1899
|
|
|
@@ -195,16 +195,26 @@ static int geaKeyCodeForCommand(SEL sel)
|
|
|
195
195
|
}
|
|
196
196
|
@end
|
|
197
197
|
|
|
198
|
-
// Root-level
|
|
199
|
-
// MacosRenderer::sync. On
|
|
198
|
+
// Root-level press handler. Installed once on the contentView during
|
|
199
|
+
// MacosRenderer::sync. On mouse-down, asks the recognizer for the location,
|
|
200
200
|
// hit-tests against the root, then walks up via nodeIdForView to find the
|
|
201
|
-
// deepest view that's tagged with a node id, and dispatches
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
//
|
|
201
|
+
// deepest view that's tagged with a node id, and dispatches the gesture —
|
|
202
|
+
// touchstart, touchmove while dragging, touchend, then click — to that nodeId,
|
|
203
|
+
// each carrying tree coordinates. Matches the framework's event-delegation
|
|
204
|
+
// model — listeners bound on document.body fire and check event.target to
|
|
205
|
+
// figure out which node was pressed.
|
|
205
206
|
@interface GeaRootClickBridge : NSObject <NSGestureRecognizerDelegate>
|
|
206
207
|
@property(nonatomic, weak) NSView *rootView;
|
|
207
208
|
@property(nonatomic, assign) int pressedNodeId; // -1 when no press in flight
|
|
209
|
+
// Tree-space origin of rootView: 0,0 for a window root, the pane node's
|
|
210
|
+
// layout.x/y for a split-view pane.
|
|
211
|
+
@property(nonatomic, assign) int originX;
|
|
212
|
+
@property(nonatomic, assign) int originY;
|
|
213
|
+
@property(nonatomic, assign) int startX;
|
|
214
|
+
@property(nonatomic, assign) int startY;
|
|
215
|
+
@property(nonatomic, assign) int lastX;
|
|
216
|
+
@property(nonatomic, assign) int lastY;
|
|
217
|
+
@property(nonatomic, assign) BOOL dragged;
|
|
208
218
|
- (void)fire:(NSGestureRecognizer *)gr;
|
|
209
219
|
@end
|
|
210
220
|
|
|
@@ -234,16 +244,50 @@ int nodeIdForView(NSView *view)
|
|
|
234
244
|
{
|
|
235
245
|
using gea::framework::events::PointerEvent;
|
|
236
246
|
using gea::framework::events::PointerEventType;
|
|
247
|
+
using gea::framework::events::TouchPoint;
|
|
237
248
|
NSView *root = self.rootView;
|
|
238
249
|
if (!root) return;
|
|
239
250
|
|
|
240
|
-
|
|
251
|
+
// Recognizer location → tree coordinates. The root is unflipped and
|
|
252
|
+
// applyViewStyle maps layout units to points 1:1, flipping y against the
|
|
253
|
+
// parent's height, so undo that flip and add the root's tree origin.
|
|
254
|
+
const NSPoint pInRoot = [gr locationInView:root];
|
|
255
|
+
const int x = static_cast<int>(std::lround(pInRoot.x)) + self.originX;
|
|
256
|
+
const int y = static_cast<int>(std::lround(root.bounds.size.height - pInRoot.y)) + self.originY;
|
|
257
|
+
|
|
258
|
+
// Same payload as TouchRuntime's dispatchPointer, so a handler reads
|
|
259
|
+
// clientX/clientY (or touches[0]) identically on a canvas and a view.
|
|
260
|
+
auto fireEvent = [&](int nodeId, PointerEventType type, int px, int py, bool activeTouch) {
|
|
241
261
|
if (nodeId < 0) return;
|
|
242
262
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
243
263
|
if (nodeId >= tree.nodeCount()) return;
|
|
244
264
|
PointerEvent ev;
|
|
245
265
|
ev.type = type;
|
|
246
266
|
ev.targetId = nodeId;
|
|
267
|
+
ev.pointerId = 1;
|
|
268
|
+
ev.x = px;
|
|
269
|
+
ev.y = py;
|
|
270
|
+
ev.clientX = px;
|
|
271
|
+
ev.clientY = py;
|
|
272
|
+
ev.pageX = px;
|
|
273
|
+
ev.pageY = py;
|
|
274
|
+
ev.screenX = px;
|
|
275
|
+
ev.screenY = py;
|
|
276
|
+
ev.touchesLength = activeTouch ? 1 : 0;
|
|
277
|
+
ev.targetTouchesLength = activeTouch ? 1 : 0;
|
|
278
|
+
ev.changedTouchesLength = 1;
|
|
279
|
+
TouchPoint point{};
|
|
280
|
+
point.identifier = 1;
|
|
281
|
+
point.target = gea::framework::events::EventTarget(nodeId);
|
|
282
|
+
point.clientX = px;
|
|
283
|
+
point.clientY = py;
|
|
284
|
+
point.pageX = px;
|
|
285
|
+
point.pageY = py;
|
|
286
|
+
point.screenX = px;
|
|
287
|
+
point.screenY = py;
|
|
288
|
+
ev.touches[0] = point;
|
|
289
|
+
ev.targetTouches[0] = point;
|
|
290
|
+
ev.changedTouches[0] = point;
|
|
247
291
|
tree.dispatchEvent(ev);
|
|
248
292
|
};
|
|
249
293
|
|
|
@@ -258,13 +302,26 @@ int nodeIdForView(NSView *view)
|
|
|
258
302
|
if (root.window.firstResponder != root.window) {
|
|
259
303
|
[root.window makeFirstResponder:nil];
|
|
260
304
|
}
|
|
261
|
-
// Mouse-down: hit-test now, remember the node so the up
|
|
262
|
-
//
|
|
263
|
-
const NSPoint pInRoot = [gr locationInView:root];
|
|
305
|
+
// Mouse-down: hit-test now, remember the node so the move and up
|
|
306
|
+
// phases dispatch to the same target even if the cursor drifts.
|
|
264
307
|
const NSPoint pInSuper = [root convertPoint:pInRoot toView:root.superview];
|
|
265
308
|
NSView *hit = [root.superview hitTest:pInSuper];
|
|
266
309
|
self.pressedNodeId = gea::macos::nodeIdForView(hit);
|
|
267
|
-
|
|
310
|
+
self.startX = x;
|
|
311
|
+
self.startY = y;
|
|
312
|
+
self.lastX = x;
|
|
313
|
+
self.lastY = y;
|
|
314
|
+
self.dragged = NO;
|
|
315
|
+
fireEvent(self.pressedNodeId, PointerEventType::TouchStart, x, y, true);
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
case NSGestureRecognizerStateChanged: {
|
|
319
|
+
if (self.pressedNodeId < 0) break;
|
|
320
|
+
if (x == self.lastX && y == self.lastY) break;
|
|
321
|
+
if (!self.dragged && (std::abs(x - self.startX) > 16 || std::abs(y - self.startY) > 16)) self.dragged = YES;
|
|
322
|
+
self.lastX = x;
|
|
323
|
+
self.lastY = y;
|
|
324
|
+
fireEvent(self.pressedNodeId, PointerEventType::TouchMove, x, y, true);
|
|
268
325
|
break;
|
|
269
326
|
}
|
|
270
327
|
case NSGestureRecognizerStateEnded:
|
|
@@ -272,10 +329,8 @@ int nodeIdForView(NSView *view)
|
|
|
272
329
|
case NSGestureRecognizerStateFailed: {
|
|
273
330
|
const int nodeId = self.pressedNodeId;
|
|
274
331
|
self.pressedNodeId = -1;
|
|
275
|
-
fireEvent(nodeId, PointerEventType::TouchEnd);
|
|
276
|
-
if (gr.state == NSGestureRecognizerStateEnded)
|
|
277
|
-
fireEvent(nodeId, PointerEventType::Click);
|
|
278
|
-
}
|
|
332
|
+
fireEvent(nodeId, PointerEventType::TouchEnd, self.lastX, self.lastY, false);
|
|
333
|
+
if (gr.state == NSGestureRecognizerStateEnded && !self.dragged) fireEvent(nodeId, PointerEventType::Click, self.lastX, self.lastY, false);
|
|
279
334
|
break;
|
|
280
335
|
}
|
|
281
336
|
default:
|
|
@@ -305,6 +360,9 @@ int nodeIdForView(NSView *view)
|
|
|
305
360
|
// (mouseDown/Dragged/Up in GeaCanvasView) — recognizing here too would
|
|
306
361
|
// double-fire the press, with this path's events carrying no coords.
|
|
307
362
|
if ([v isKindOfClass:[GeaCanvasView class]]) return NO;
|
|
363
|
+
// A scroll container's scroller tracks its own knob drag; recognizing
|
|
364
|
+
// the press here took the whole drag and the knob never moved.
|
|
365
|
+
if ([v isKindOfClass:[NSScroller class]]) return NO;
|
|
308
366
|
}
|
|
309
367
|
return YES;
|
|
310
368
|
}
|
|
@@ -316,10 +374,65 @@ int nodeIdForView(NSView *view)
|
|
|
316
374
|
// (unflipped) clip view, short content bottom-aligns, leaving a gap above the
|
|
317
375
|
// first row. The document view itself stays unflipped, so syncRecursive's
|
|
318
376
|
// y-flip against scroll_content_height is unchanged.
|
|
377
|
+
//
|
|
378
|
+
// AppKit owns the scroll position, but the engine has to be told it: a
|
|
379
|
+
// VirtualList windows its rows from Tree::scrollTop, the engine offsets child
|
|
380
|
+
// layout by it, and Tree::setScrollTop is what dispatches `scroll`. Without the
|
|
381
|
+
// commit a trackpad scroll moved the document while the engine stayed at 0, so
|
|
382
|
+
// rows past the first window were blank and onScroll never fired. Like the iOS
|
|
383
|
+
// container, an overscrolled (rubber-banding) offset is not committed; the
|
|
384
|
+
// settled one is.
|
|
385
|
+
static int g_macosSyncDepth = 0;
|
|
386
|
+
struct GeaSyncDepthScope {
|
|
387
|
+
GeaSyncDepthScope() { ++g_macosSyncDepth; }
|
|
388
|
+
~GeaSyncDepthScope() { --g_macosSyncDepth; }
|
|
389
|
+
};
|
|
390
|
+
|
|
319
391
|
@interface GeaFlippedClipView : NSClipView
|
|
392
|
+
@property(nonatomic, assign) int nodeId;
|
|
320
393
|
@end
|
|
321
394
|
@implementation GeaFlippedClipView
|
|
395
|
+
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
396
|
+
{
|
|
397
|
+
if ((self = [super initWithFrame:frameRect])) {
|
|
398
|
+
_nodeId = -1;
|
|
399
|
+
self.postsBoundsChangedNotifications = YES;
|
|
400
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
401
|
+
selector:@selector(geaBoundsDidChange:)
|
|
402
|
+
name:NSViewBoundsDidChangeNotification
|
|
403
|
+
object:self];
|
|
404
|
+
}
|
|
405
|
+
return self;
|
|
406
|
+
}
|
|
407
|
+
- (void)dealloc
|
|
408
|
+
{
|
|
409
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
410
|
+
}
|
|
322
411
|
- (BOOL)isFlipped { return YES; }
|
|
412
|
+
- (void)geaBoundsDidChange:(NSNotification *)notification
|
|
413
|
+
{
|
|
414
|
+
(void)notification;
|
|
415
|
+
// A bounds change made by sync itself (content resized, offset clamped) is
|
|
416
|
+
// committed after the walk: mid-walk it would move scrollTop under children
|
|
417
|
+
// whose layout was computed for the old offset.
|
|
418
|
+
if (g_macosSyncDepth > 0) {
|
|
419
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
420
|
+
[self commitScrollTop];
|
|
421
|
+
});
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
[self commitScrollTop];
|
|
425
|
+
}
|
|
426
|
+
- (void)commitScrollTop
|
|
427
|
+
{
|
|
428
|
+
if (self.nodeId < 0) return;
|
|
429
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
430
|
+
if (self.nodeId >= tree.nodeCount()) return;
|
|
431
|
+
const CGFloat y = self.bounds.origin.y;
|
|
432
|
+
const CGFloat maxY = std::max<CGFloat>(0, NSHeight(self.documentView.frame) - NSHeight(self.bounds));
|
|
433
|
+
if (y < -0.5 || y > maxY + 0.5) return;
|
|
434
|
+
tree.setScrollTop(self.nodeId, static_cast<int>(std::lround(std::clamp<CGFloat>(y, 0, maxY))));
|
|
435
|
+
}
|
|
323
436
|
@end
|
|
324
437
|
|
|
325
438
|
// NSSlider materialized by `<input type="range">`. Continuous; on each value
|
|
@@ -1522,13 +1635,20 @@ void applyScrollContentSize(NSScrollView *sv, const gea::embedded::ui::Node &nod
|
|
|
1522
1635
|
{
|
|
1523
1636
|
NSView *content = sv.documentView;
|
|
1524
1637
|
if (!content) return;
|
|
1638
|
+
// The engine reserves no scrollbar gutter: every target lays content out
|
|
1639
|
+
// across the container's full width and draws its scroller over it. A
|
|
1640
|
+
// legacy (always-shown) NSScroller takes its width out of the clip instead,
|
|
1641
|
+
// hiding that strip of the layout and leaving the document sideways play, so
|
|
1642
|
+
// the scroller stays in the overlay style.
|
|
1643
|
+
if (sv.scrollerStyle != NSScrollerStyleOverlay) sv.scrollerStyle = NSScrollerStyleOverlay;
|
|
1525
1644
|
const CGFloat w = node.layout.width;
|
|
1526
1645
|
const CGFloat h = node.layout.scroll_content_height > 0
|
|
1527
1646
|
? node.layout.scroll_content_height
|
|
1528
1647
|
: node.layout.height;
|
|
1529
1648
|
// documentView always sized to the full scroll content; NSScrollView's
|
|
1530
1649
|
// own scrollers handle the visible window. We don't apply the tree's
|
|
1531
|
-
// scroll_y here — AppKit owns the scroll position via NSScrollView
|
|
1650
|
+
// scroll_y here — AppKit owns the scroll position via NSScrollView, and
|
|
1651
|
+
// GeaFlippedClipView mirrors it into the tree.
|
|
1532
1652
|
if (content.frame.size.width != w || content.frame.size.height != h) {
|
|
1533
1653
|
content.frame = NSMakeRect(0, 0, w, h);
|
|
1534
1654
|
}
|
|
@@ -1574,7 +1694,11 @@ void applyTypeSpecificProps(NSView *view, const gea::embedded::ui::Node &node, i
|
|
|
1574
1694
|
applyTextAreaProps((NSScrollView *)view, node, nodeId);
|
|
1575
1695
|
} else if (isScrollView(view)) {
|
|
1576
1696
|
// Both NodeType::VirtualList and overflow:scroll Views land here.
|
|
1577
|
-
|
|
1697
|
+
NSScrollView *sv = (NSScrollView *)view;
|
|
1698
|
+
if ([sv.contentView isKindOfClass:[GeaFlippedClipView class]]) {
|
|
1699
|
+
((GeaFlippedClipView *)sv.contentView).nodeId = nodeId;
|
|
1700
|
+
}
|
|
1701
|
+
applyScrollContentSize(sv, node);
|
|
1578
1702
|
}
|
|
1579
1703
|
|
|
1580
1704
|
// Per-View click recognizers don't fit the framework's event-delegation
|
|
@@ -1858,6 +1982,9 @@ void syncRecursive(int nodeId, NSView *parent, int parentAbsX, int parentAbsY, i
|
|
|
1858
1982
|
parentHeightForChildren = node.layout.scroll_content_height > 0
|
|
1859
1983
|
? node.layout.scroll_content_height
|
|
1860
1984
|
: node.layout.height;
|
|
1985
|
+
// The engine lays children out at their scrolled position; the document
|
|
1986
|
+
// view is already scrolled by AppKit, so place them in document space.
|
|
1987
|
+
parentAbsYForChildren = node.layout.y - tree.scrollTop(nodeId);
|
|
1861
1988
|
}
|
|
1862
1989
|
|
|
1863
1990
|
for (int child = node.first_child; child >= 0; child = tree.node(child).next_sibling) {
|
|
@@ -1877,34 +2004,41 @@ MacosRenderer &MacosRenderer::instance()
|
|
|
1877
2004
|
namespace {
|
|
1878
2005
|
// Install the centralized press/click handler on a root container once.
|
|
1879
2006
|
// Idempotent via an associated object so repeated sync passes don't stack
|
|
1880
|
-
// recognizers.
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
GeaRootClickBridge *bridge =
|
|
1885
|
-
bridge
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
2007
|
+
// recognizers. The tree origin is refreshed on every pass: a pane's layout
|
|
2008
|
+
// origin moves when its split is resized.
|
|
2009
|
+
void ensureRootClickBridge(NSView *parentForRoot, int originX, int originY)
|
|
2010
|
+
{
|
|
2011
|
+
GeaRootClickBridge *bridge = objc_getAssociatedObject(parentForRoot, "gea.root_click_bridge");
|
|
2012
|
+
if (!bridge) {
|
|
2013
|
+
bridge = [[GeaRootClickBridge alloc] init];
|
|
2014
|
+
bridge.rootView = parentForRoot;
|
|
2015
|
+
objc_setAssociatedObject(parentForRoot, "gea.root_click_bridge", bridge, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
2016
|
+
// NSPressGestureRecognizer (not NSClickGestureRecognizer) — we need the
|
|
2017
|
+
// began/changed/ended state transitions so press-and-hold and drag
|
|
2018
|
+
// semantics work. minimumPressDuration=0 fires began immediately on
|
|
2019
|
+
// mouseDown.
|
|
2020
|
+
NSPressGestureRecognizer *gr =
|
|
2021
|
+
[[NSPressGestureRecognizer alloc] initWithTarget:bridge action:@selector(fire:)];
|
|
2022
|
+
gr.minimumPressDuration = 0;
|
|
2023
|
+
gr.allowableMovement = 10000; // don't cancel on drag — keep the press
|
|
2024
|
+
// The delegate declines clicks on editable text controls so they focus and
|
|
2025
|
+
// edit natively instead of being swallowed by this recognizer.
|
|
2026
|
+
gr.delegate = bridge;
|
|
2027
|
+
[parentForRoot addGestureRecognizer:gr];
|
|
2028
|
+
}
|
|
2029
|
+
bridge.originX = originX;
|
|
2030
|
+
bridge.originY = originY;
|
|
1898
2031
|
}
|
|
1899
2032
|
} // namespace
|
|
1900
2033
|
|
|
1901
2034
|
void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
|
|
1902
2035
|
{
|
|
2036
|
+
const GeaSyncDepthScope syncScope;
|
|
1903
2037
|
using namespace gea::embedded::ui;
|
|
1904
2038
|
Tree &tree = Tree::instance();
|
|
1905
2039
|
if (rootNodeId < 0 || rootNodeId >= tree.nodeCount()) return;
|
|
1906
2040
|
|
|
1907
|
-
ensureRootClickBridge(parentForRoot);
|
|
2041
|
+
ensureRootClickBridge(parentForRoot, 0, 0);
|
|
1908
2042
|
|
|
1909
2043
|
// Mark every existing entry stale; syncRecursive removes the keys it
|
|
1910
2044
|
// touches. Anything still in the set after the walk corresponds to a
|
|
@@ -1928,6 +2062,7 @@ void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
|
|
|
1928
2062
|
|
|
1929
2063
|
void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
|
|
1930
2064
|
{
|
|
2065
|
+
const GeaSyncDepthScope syncScope;
|
|
1931
2066
|
using namespace gea::embedded::ui;
|
|
1932
2067
|
Tree &tree = Tree::instance();
|
|
1933
2068
|
const NSUInteger paneCount = paneViews.count;
|
|
@@ -1943,11 +2078,11 @@ void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
|
|
|
1943
2078
|
NSView *paneView = paneViews[i];
|
|
1944
2079
|
const int rootNodeId = rootNodeIds[i];
|
|
1945
2080
|
if (rootNodeId < 0 || rootNodeId >= tree.nodeCount()) continue;
|
|
1946
|
-
ensureRootClickBridge(paneView);
|
|
1947
2081
|
const int parentHeight = static_cast<int>(paneView.bounds.size.height);
|
|
1948
2082
|
// Each pane node's own layout.x/y act as its document origin, so the
|
|
1949
2083
|
// pane's children land relative to the pane container's top-left.
|
|
1950
2084
|
const Node &paneNode = tree.node(rootNodeId);
|
|
2085
|
+
ensureRootClickBridge(paneView, paneNode.layout.x, paneNode.layout.y);
|
|
1951
2086
|
syncRecursive(rootNodeId, paneView, paneNode.layout.x, paneNode.layout.y, parentHeight, unseen);
|
|
1952
2087
|
}
|
|
1953
2088
|
|