@geastack/apple 0.2.16 → 0.2.19
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 +81 -0
- package/dist/desktop-api.js +295 -0
- package/generated/EventKit.d.ts +16 -0
- package/package.json +8 -4
- package/runtime/EventKit.js +35 -0
- package/targets/ios/Info-tvOS.plist.in +39 -0
- package/targets/ios/Info.plist.in +14 -0
- package/targets/ios/README.md +21 -0
- package/targets/ios/build-ios.sh +98 -52
- package/targets/ios/generate-xcode-project.mjs +28 -11
- package/targets/ios/main/canvas_view.mm +4 -13
- package/targets/ios/main/font_registry.mm +6 -0
- package/targets/ios/main/ios_camera.mm +10 -0
- package/targets/ios/main/ios_display.mm +25 -6
- package/targets/ios/main/ios_main.mm +259 -6
- package/targets/ios/main/ios_sensors.mm +22 -0
- package/targets/ios/main/renderer/native_scroll_container.mm +3 -0
- package/targets/macos/build-child-lifecycle.sh +4 -1
- package/targets/macos/build-macos.sh +17 -10
- package/targets/macos/merge-info-plist.mjs +35 -0
package/README.md
CHANGED
|
@@ -89,6 +89,87 @@ returns an error string (empty on success). Delays must be positive and finite.
|
|
|
89
89
|
Completion callbacks run on the main queue. Request authorization from the
|
|
90
90
|
signed application before scheduling; the operating system controls delivery.
|
|
91
91
|
|
|
92
|
+
`@geastack/apple/EventKit` reads and writes the calendars the user has added to
|
|
93
|
+
macOS (iCloud, Google, Exchange and other accounts in System Settings → Internet
|
|
94
|
+
Accounts) through one shared `EKEventStore` for the process. Results are JSON
|
|
95
|
+
strings, like `SwiftData.fetchModelsJSON`; parse them with `JSON.parse`.
|
|
96
|
+
|
|
97
|
+
- `authorizationStatus()` returns `notDetermined`, `restricted`, `denied`,
|
|
98
|
+
`fullAccess` or `writeOnly`.
|
|
99
|
+
- `requestFullAccess((granted, error) => …)` shows the system prompt once
|
|
100
|
+
(`requestFullAccessToEventsWithCompletion:` on macOS 14 and later, the older
|
|
101
|
+
event access request below).
|
|
102
|
+
- `calendars()` returns
|
|
103
|
+
`[{ id, title, color, source, sourceType, allowsModifications }]`. `id` is the
|
|
104
|
+
calendar identifier, `source` the account title (the address for a Google
|
|
105
|
+
account), `color` is `#RRGGBB`, and `sourceType` is one of `local`,
|
|
106
|
+
`exchange`, `calDAV` (Google and most other servers), `mobileMe`,
|
|
107
|
+
`subscribed` or `birthdays`. It is `[]` until access is granted.
|
|
108
|
+
- `events(startISO, endISO, calendarIdsJSON)` returns the events overlapping
|
|
109
|
+
the range, sorted by start:
|
|
110
|
+
`[{ id, externalId, calendarId, title, start, end, occurrenceDate, allDay,
|
|
111
|
+
availability, recurring, status }]`. Pass `'[]'` for all calendars. Times are
|
|
112
|
+
ISO 8601 with the local offset; input accepts any offset, with or without
|
|
113
|
+
fractional seconds. `availability` is `busy`, `free`, `tentative`,
|
|
114
|
+
`unavailable` or `notSupported`; `status` is `none`, `confirmed`, `tentative`
|
|
115
|
+
or `canceled`. Occurrences of a recurring event share `id`; `id` plus
|
|
116
|
+
`occurrenceDate` names one occurrence. EventKit limits a query to four years.
|
|
117
|
+
- `watchChanges(() => …)` returns a handle; the callback runs on the main queue
|
|
118
|
+
after any change to the store (from this app, Calendar or a sync). Re-read
|
|
119
|
+
what you show; the notification carries no details. Stop it with
|
|
120
|
+
`stopWatchingChanges(handle)`.
|
|
121
|
+
- `saveEvent(eventJSON, span, (id, error) => …)` creates an event when
|
|
122
|
+
`eventJSON` has no `id`, and otherwise updates the event (with
|
|
123
|
+
`occurrenceDate`, that occurrence; without it, the first occurrence). Fields:
|
|
124
|
+
`calendarId`, `title`, `start`, `end`, `allDay`, `location`, `notes`,
|
|
125
|
+
`availability`; a new event needs `calendarId`, `start` and `end`, and an
|
|
126
|
+
update changes only the fields given. `span` is `thisEvent` or
|
|
127
|
+
`futureEvents`.
|
|
128
|
+
- `removeEvent(id, occurrenceDate, span, error => …)` removes an event or
|
|
129
|
+
occurrence. A single event is found by `id` alone, so its `occurrenceDate`
|
|
130
|
+
may be `''` or out of date after the event moved.
|
|
131
|
+
|
|
132
|
+
Writes to a calendar whose `allowsModifications` is false return an error.
|
|
133
|
+
EventKit cannot add attendees or send invitations; an event saved here has no
|
|
134
|
+
invitees. Completion callbacks run on the main queue; errors are an empty
|
|
135
|
+
string on success. A located occurrence must lie within a week of its
|
|
136
|
+
`occurrenceDate`.
|
|
137
|
+
|
|
138
|
+
macOS ends a process that asks for calendar access without a usage
|
|
139
|
+
description. Add both keys to `apps/<id>/macos.json`; its optional `infoPlist`
|
|
140
|
+
object is merged over the shared `Info.plist` template:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"window": { "width": 1280, "height": 800 },
|
|
145
|
+
"infoPlist": {
|
|
146
|
+
"NSCalendarsFullAccessUsageDescription": "Shows your meetings next to your tasks.",
|
|
147
|
+
"NSCalendarsUsageDescription": "Shows your meetings next to your tasks."
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
macOS records the grant against the code signature. A development build is
|
|
153
|
+
signed ad hoc, so every rebuild that changes the executable asks again, and
|
|
154
|
+
`tccutil reset Calendar com.gea.<app-id>` forgets it. A sandboxed or
|
|
155
|
+
hardened-runtime signed build also needs the
|
|
156
|
+
`com.apple.security.personal-information.calendars` entitlement. A Google
|
|
157
|
+
account in macOS syncs only its own calendars by default; switch on shared and
|
|
158
|
+
secondary calendars once at https://www.google.com/calendar/syncselect.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { authorizationStatus, requestFullAccess, calendars, events, watchChanges } from '@geastack/apple/EventKit'
|
|
162
|
+
|
|
163
|
+
const load = () => {
|
|
164
|
+
const accounts = JSON.parse(calendars())
|
|
165
|
+
const week = JSON.parse(events('2026-11-02T00:00:00+01:00', '2026-11-09T00:00:00+01:00', '[]'))
|
|
166
|
+
// Group accounts by `source`, render `week`.
|
|
167
|
+
}
|
|
168
|
+
if (authorizationStatus() === 'fullAccess') load()
|
|
169
|
+
else requestFullAccess((granted) => { if (granted) load() })
|
|
170
|
+
const watch = watchChanges(load)
|
|
171
|
+
```
|
|
172
|
+
|
|
92
173
|
## App Store
|
|
93
174
|
|
|
94
175
|
The package is Apache-2.0, so App Store distribution has no license obstacle
|
package/dist/desktop-api.js
CHANGED
|
@@ -8,6 +8,83 @@ const completion = {
|
|
|
8
8
|
returns: nothing,
|
|
9
9
|
parameters: [{ name: 'error', type: string }]
|
|
10
10
|
};
|
|
11
|
+
const savedEventCompletion = {
|
|
12
|
+
kind: 'function',
|
|
13
|
+
returns: nothing,
|
|
14
|
+
parameters: [
|
|
15
|
+
{ name: 'id', type: string },
|
|
16
|
+
{ name: 'error', type: string }
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
// Each bridge body is a separate function, so the process-wide EKEventStore is
|
|
20
|
+
// kept as an associated object on the EKEventStore class.
|
|
21
|
+
const eventStore = `EKEventStore *store = nil;
|
|
22
|
+
@synchronized ([EKEventStore class]) {
|
|
23
|
+
store = objc_getAssociatedObject([EKEventStore class], @selector(geaSharedEventStore));
|
|
24
|
+
if (!store) {
|
|
25
|
+
store = [[EKEventStore alloc] init];
|
|
26
|
+
objc_setAssociatedObject([EKEventStore class], @selector(geaSharedEventStore), store, OBJC_ASSOCIATION_RETAIN);
|
|
27
|
+
}
|
|
28
|
+
}`;
|
|
29
|
+
// ISO 8601 with the local offset out; with or without fractional seconds in,
|
|
30
|
+
// so JavaScript's toISOString() round-trips.
|
|
31
|
+
const eventDates = `NSISO8601DateFormatter *iso = [[NSISO8601DateFormatter alloc] init];
|
|
32
|
+
iso.timeZone = [NSTimeZone localTimeZone];
|
|
33
|
+
NSISO8601DateFormatter *isoFraction = [[NSISO8601DateFormatter alloc] init];
|
|
34
|
+
isoFraction.formatOptions = NSISO8601DateFormatWithInternetDateTime | NSISO8601DateFormatWithFractionalSeconds;
|
|
35
|
+
auto parseDate = [&](NSString *value) -> NSDate * {
|
|
36
|
+
if (![value isKindOfClass:[NSString class]]) return nil;
|
|
37
|
+
return [iso dateFromString:value] ?: [isoFraction dateFromString:value];
|
|
38
|
+
};`;
|
|
39
|
+
const jsonText = `auto jsonText = [](id object) -> std::string {
|
|
40
|
+
NSData *data = [NSJSONSerialization dataWithJSONObject:object options:0 error:nil];
|
|
41
|
+
return data ? std::string(static_cast<const char *>(data.bytes), data.length) : std::string("[]");
|
|
42
|
+
};`;
|
|
43
|
+
const eventJSON = `auto availabilityName = [](EKEventAvailability availability) -> NSString * {
|
|
44
|
+
switch (availability) {
|
|
45
|
+
case EKEventAvailabilityBusy: return @"busy";
|
|
46
|
+
case EKEventAvailabilityFree: return @"free";
|
|
47
|
+
case EKEventAvailabilityTentative: return @"tentative";
|
|
48
|
+
case EKEventAvailabilityUnavailable: return @"unavailable";
|
|
49
|
+
default: return @"notSupported";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
auto statusName = [](EKEventStatus status) -> NSString * {
|
|
53
|
+
switch (status) {
|
|
54
|
+
case EKEventStatusConfirmed: return @"confirmed";
|
|
55
|
+
case EKEventStatusTentative: return @"tentative";
|
|
56
|
+
case EKEventStatusCanceled: return @"canceled";
|
|
57
|
+
default: return @"none";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
auto eventObject = [&](EKEvent *event) -> NSDictionary * {
|
|
61
|
+
return @{@"id": event.eventIdentifier ?: @"", @"externalId": event.calendarItemExternalIdentifier ?: @"",
|
|
62
|
+
@"calendarId": event.calendar.calendarIdentifier ?: @"", @"title": event.title ?: @"",
|
|
63
|
+
@"start": [iso stringFromDate:event.startDate], @"end": [iso stringFromDate:event.endDate],
|
|
64
|
+
@"occurrenceDate": [iso stringFromDate:event.occurrenceDate ?: event.startDate],
|
|
65
|
+
@"allDay": @(event.allDay), @"availability": availabilityName(event.availability),
|
|
66
|
+
@"recurring": @(event.hasRecurrenceRules), @"status": statusName(event.status)};
|
|
67
|
+
};`;
|
|
68
|
+
// An occurrence of a recurring event is addressed by its id plus the
|
|
69
|
+
// occurrenceDate events() reported; it is searched for a week either side.
|
|
70
|
+
// A single event's occurrenceDate is its start, which moves with the event, so
|
|
71
|
+
// a stale one still finds it by id.
|
|
72
|
+
const findEvent = `auto findEvent = [&](NSString *identifier, NSString *occurrence) -> EKEvent * {
|
|
73
|
+
if (occurrence.length == 0) return [store eventWithIdentifier:identifier];
|
|
74
|
+
if (NSDate *date = parseDate(occurrence)) {
|
|
75
|
+
NSPredicate *predicate = [store predicateForEventsWithStartDate:[date dateByAddingTimeInterval:-7 * 86400]
|
|
76
|
+
endDate:[date dateByAddingTimeInterval:7 * 86400] calendars:nil];
|
|
77
|
+
for (EKEvent *candidate in [store eventsMatchingPredicate:predicate])
|
|
78
|
+
if ([candidate.eventIdentifier isEqualToString:identifier] && fabs([candidate.occurrenceDate timeIntervalSinceDate:date]) < 1) return candidate;
|
|
79
|
+
}
|
|
80
|
+
EKEvent *single = [store eventWithIdentifier:identifier];
|
|
81
|
+
return single && !single.hasRecurrenceRules ? single : nil;
|
|
82
|
+
};
|
|
83
|
+
auto eventSpan = [](const std::string &value, EKSpan *span) -> bool {
|
|
84
|
+
if (value == "thisEvent") { *span = EKSpanThisEvent; return true; }
|
|
85
|
+
if (value == "futureEvents") { *span = EKSpanFutureEvents; return true; }
|
|
86
|
+
return false;
|
|
87
|
+
};`;
|
|
11
88
|
export const foundationServices = [
|
|
12
89
|
{
|
|
13
90
|
name: 'randomUUID',
|
|
@@ -183,5 +260,223 @@ UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:ge
|
|
|
183
260
|
bridgeBody: '[[UNUserNotificationCenter currentNotificationCenter] removePendingNotificationRequestsWithIdentifiers:@[gea::apple::Foundation::toNSString(identifier)]];'
|
|
184
261
|
}
|
|
185
262
|
]
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: 'EventKit',
|
|
266
|
+
bridgeHeaders: ['EventKit/EventKit.h', 'objc/runtime.h', 'cmath', 'stdexcept'],
|
|
267
|
+
functions: [
|
|
268
|
+
{
|
|
269
|
+
name: 'authorizationStatus',
|
|
270
|
+
returns: string,
|
|
271
|
+
// Raw values: 3 is fullAccess on macOS 14+ and the older "authorized".
|
|
272
|
+
bridgeBody: `switch (static_cast<NSInteger>([EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent])) {
|
|
273
|
+
case 1: return "restricted";
|
|
274
|
+
case 2: return "denied";
|
|
275
|
+
case 3: return "fullAccess";
|
|
276
|
+
case 4: return "writeOnly";
|
|
277
|
+
default: return "notDetermined";
|
|
278
|
+
}`
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
name: 'requestFullAccess',
|
|
282
|
+
returns: nothing,
|
|
283
|
+
parameters: [
|
|
284
|
+
{
|
|
285
|
+
name: 'completed',
|
|
286
|
+
type: {
|
|
287
|
+
kind: 'function',
|
|
288
|
+
returns: nothing,
|
|
289
|
+
parameters: [
|
|
290
|
+
{ name: 'granted', type: boolean },
|
|
291
|
+
{ name: 'error', type: string }
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
],
|
|
296
|
+
bridgeBody: `${eventStore}
|
|
297
|
+
void (^finish)(BOOL, NSError *) = ^(BOOL granted, NSError *error) {
|
|
298
|
+
const std::string message = gea::apple::Foundation::fromNSString(error.localizedDescription);
|
|
299
|
+
dispatch_async(dispatch_get_main_queue(), ^{ if (completed) completed(granted, message); });
|
|
300
|
+
};
|
|
301
|
+
if (@available(macOS 14.0, iOS 17.0, *)) {
|
|
302
|
+
[store requestFullAccessToEventsWithCompletion:finish];
|
|
303
|
+
} else {
|
|
304
|
+
#pragma clang diagnostic push
|
|
305
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
306
|
+
[store requestAccessToEntityType:EKEntityTypeEvent completion:finish];
|
|
307
|
+
#pragma clang diagnostic pop
|
|
308
|
+
}`
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: 'calendars',
|
|
312
|
+
returns: string,
|
|
313
|
+
bridgeBody: `${eventStore}
|
|
314
|
+
${jsonText}
|
|
315
|
+
auto sourceTypeName = [](EKSourceType type) -> NSString * {
|
|
316
|
+
switch (type) {
|
|
317
|
+
case EKSourceTypeLocal: return @"local";
|
|
318
|
+
case EKSourceTypeExchange: return @"exchange";
|
|
319
|
+
case EKSourceTypeCalDAV: return @"calDAV";
|
|
320
|
+
case EKSourceTypeMobileMe: return @"mobileMe";
|
|
321
|
+
case EKSourceTypeSubscribed: return @"subscribed";
|
|
322
|
+
case EKSourceTypeBirthdays: return @"birthdays";
|
|
323
|
+
default: return @"unknown";
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
|
327
|
+
NSMutableArray *result = [NSMutableArray array];
|
|
328
|
+
NSArray<EKCalendar *> *calendars = [[store calendarsForEntityType:EKEntityTypeEvent] sortedArrayUsingDescriptors:@[
|
|
329
|
+
[NSSortDescriptor sortDescriptorWithKey:@"source.title" ascending:YES],
|
|
330
|
+
[NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES]]];
|
|
331
|
+
for (EKCalendar *calendar in calendars) {
|
|
332
|
+
NSString *color = @"";
|
|
333
|
+
CGColorRef matched = calendar.CGColor ? CGColorCreateCopyByMatchingToColorSpace(srgb, kCGRenderingIntentDefault, calendar.CGColor, nullptr) : nullptr;
|
|
334
|
+
if (matched && CGColorGetNumberOfComponents(matched) >= 3) {
|
|
335
|
+
const CGFloat *rgb = CGColorGetComponents(matched);
|
|
336
|
+
auto channel = [](CGFloat value) { return static_cast<int>(std::lround(std::fmin(std::fmax(value, 0.0), 1.0) * 255)); };
|
|
337
|
+
color = [NSString stringWithFormat:@"#%02X%02X%02X", channel(rgb[0]), channel(rgb[1]), channel(rgb[2])];
|
|
338
|
+
}
|
|
339
|
+
if (matched) CGColorRelease(matched);
|
|
340
|
+
[result addObject:@{@"id": calendar.calendarIdentifier ?: @"", @"title": calendar.title ?: @"", @"color": color,
|
|
341
|
+
@"source": calendar.source.title ?: @"", @"sourceType": sourceTypeName(calendar.source.sourceType),
|
|
342
|
+
@"allowsModifications": @(calendar.allowsContentModifications)}];
|
|
343
|
+
}
|
|
344
|
+
if (srgb) CGColorSpaceRelease(srgb);
|
|
345
|
+
return jsonText(result);`
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: 'events',
|
|
349
|
+
returns: string,
|
|
350
|
+
parameters: [
|
|
351
|
+
{ name: 'startISO', type: string },
|
|
352
|
+
{ name: 'endISO', type: string },
|
|
353
|
+
{ name: 'calendarIdsJSON', type: string }
|
|
354
|
+
],
|
|
355
|
+
bridgeBody: `${eventStore}
|
|
356
|
+
${eventDates}
|
|
357
|
+
${jsonText}
|
|
358
|
+
${eventJSON}
|
|
359
|
+
NSDate *start = parseDate(gea::apple::Foundation::toNSString(startISO));
|
|
360
|
+
NSDate *end = parseDate(gea::apple::Foundation::toNSString(endISO));
|
|
361
|
+
if (!start || !end) throw std::runtime_error("events: start and end must be ISO 8601 date-times");
|
|
362
|
+
NSMutableArray<EKCalendar *> *calendars = nil;
|
|
363
|
+
if (!calendarIdsJSON.empty()) {
|
|
364
|
+
NSData *data = [gea::apple::Foundation::toNSString(calendarIdsJSON) dataUsingEncoding:NSUTF8StringEncoding];
|
|
365
|
+
id ids = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
|
366
|
+
if (![ids isKindOfClass:[NSArray class]]) throw std::runtime_error("events: calendarIdsJSON must be a JSON array of calendar ids");
|
|
367
|
+
if ([ids count] > 0) {
|
|
368
|
+
calendars = [NSMutableArray array];
|
|
369
|
+
for (id identifier in ids) {
|
|
370
|
+
EKCalendar *calendar = [identifier isKindOfClass:[NSString class]] ? [store calendarWithIdentifier:identifier] : nil;
|
|
371
|
+
if (calendar) [calendars addObject:calendar];
|
|
372
|
+
}
|
|
373
|
+
if (calendars.count == 0) return "[]";
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
NSPredicate *predicate = [store predicateForEventsWithStartDate:start endDate:end calendars:calendars];
|
|
377
|
+
NSArray<EKEvent *> *events = [[store eventsMatchingPredicate:predicate] sortedArrayUsingSelector:@selector(compareStartDateWithEvent:)];
|
|
378
|
+
NSMutableArray *result = [NSMutableArray arrayWithCapacity:events.count];
|
|
379
|
+
for (EKEvent *event in events) [result addObject:eventObject(event)];
|
|
380
|
+
return jsonText(result);`
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: 'watchChanges',
|
|
384
|
+
returns: number,
|
|
385
|
+
parameters: [{ name: 'changed', type: callback }],
|
|
386
|
+
bridgeBody: `${eventStore}
|
|
387
|
+
id observer = [[NSNotificationCenter defaultCenter] addObserverForName:EKEventStoreChangedNotification object:store
|
|
388
|
+
queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *) { if (changed) changed(); }];
|
|
389
|
+
return gea::apple::objc::retain((__bridge void *)observer);`
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
name: 'stopWatchingChanges',
|
|
393
|
+
returns: nothing,
|
|
394
|
+
parameters: [{ name: 'handle', type: number }],
|
|
395
|
+
bridgeBody: `id observer = (__bridge id)gea::apple::objc::object(handle);
|
|
396
|
+
if (observer) { [[NSNotificationCenter defaultCenter] removeObserver:observer]; gea::apple::objc::release(handle); }`
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
name: 'saveEvent',
|
|
400
|
+
returns: nothing,
|
|
401
|
+
parameters: [
|
|
402
|
+
{ name: 'eventJSON', type: string },
|
|
403
|
+
{ name: 'span', type: string },
|
|
404
|
+
{ name: 'completed', type: savedEventCompletion }
|
|
405
|
+
],
|
|
406
|
+
bridgeBody: `${eventStore}
|
|
407
|
+
${eventDates}
|
|
408
|
+
${findEvent}
|
|
409
|
+
// The block copies what it names; a reference the lambda captured would
|
|
410
|
+
// dangle once this function returns, so copy the callback into the lambda.
|
|
411
|
+
auto finish = [&](NSString *identifier, std::string error) {
|
|
412
|
+
auto callback = completed;
|
|
413
|
+
const std::string saved = gea::apple::Foundation::fromNSString(identifier);
|
|
414
|
+
dispatch_async(dispatch_get_main_queue(), ^{ if (callback) callback(saved, error); });
|
|
415
|
+
};
|
|
416
|
+
EKSpan eventKitSpan;
|
|
417
|
+
if (!eventSpan(span, &eventKitSpan)) return finish(nil, "span must be thisEvent or futureEvents");
|
|
418
|
+
NSData *data = [gea::apple::Foundation::toNSString(eventJSON) dataUsingEncoding:NSUTF8StringEncoding];
|
|
419
|
+
NSDictionary *fields = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
420
|
+
if (![fields isKindOfClass:[NSDictionary class]]) return finish(nil, "eventJSON must be a JSON object");
|
|
421
|
+
auto text = [&](NSString *key) -> NSString * { id value = fields[key]; return [value isKindOfClass:[NSString class]] ? value : nil; };
|
|
422
|
+
EKEvent *event = nil;
|
|
423
|
+
if (text(@"id").length) {
|
|
424
|
+
event = findEvent(text(@"id"), text(@"occurrenceDate"));
|
|
425
|
+
if (!event) return finish(nil, "No event with that id and occurrenceDate");
|
|
426
|
+
if (!event.calendar.allowsContentModifications) return finish(nil, "The event's calendar does not allow modifications");
|
|
427
|
+
} else {
|
|
428
|
+
event = [EKEvent eventWithEventStore:store];
|
|
429
|
+
if (!text(@"calendarId") || !fields[@"start"] || !fields[@"end"]) return finish(nil, "A new event needs calendarId, start and end");
|
|
430
|
+
}
|
|
431
|
+
if (text(@"calendarId")) {
|
|
432
|
+
EKCalendar *calendar = [store calendarWithIdentifier:text(@"calendarId")];
|
|
433
|
+
if (!calendar) return finish(nil, "No calendar with that calendarId");
|
|
434
|
+
if (!calendar.allowsContentModifications) return finish(nil, "The calendar does not allow modifications");
|
|
435
|
+
event.calendar = calendar;
|
|
436
|
+
}
|
|
437
|
+
if (fields[@"start"]) { NSDate *date = parseDate(fields[@"start"]); if (!date) return finish(nil, "start must be an ISO 8601 date-time"); event.startDate = date; }
|
|
438
|
+
if (fields[@"end"]) { NSDate *date = parseDate(fields[@"end"]); if (!date) return finish(nil, "end must be an ISO 8601 date-time"); event.endDate = date; }
|
|
439
|
+
if ([event.endDate compare:event.startDate] == NSOrderedAscending) return finish(nil, "end must not be before start");
|
|
440
|
+
if (fields[@"title"]) event.title = text(@"title") ?: @"";
|
|
441
|
+
if (fields[@"location"]) event.location = text(@"location");
|
|
442
|
+
if (fields[@"notes"]) event.notes = text(@"notes");
|
|
443
|
+
if ([fields[@"allDay"] isKindOfClass:[NSNumber class]]) event.allDay = [fields[@"allDay"] boolValue];
|
|
444
|
+
if (text(@"availability")) {
|
|
445
|
+
NSDictionary *availability = @{@"busy": @(EKEventAvailabilityBusy), @"free": @(EKEventAvailabilityFree),
|
|
446
|
+
@"tentative": @(EKEventAvailabilityTentative), @"unavailable": @(EKEventAvailabilityUnavailable)};
|
|
447
|
+
NSNumber *value = availability[text(@"availability")];
|
|
448
|
+
if (!value) return finish(nil, "availability must be busy, free, tentative or unavailable");
|
|
449
|
+
event.availability = static_cast<EKEventAvailability>(value.integerValue);
|
|
450
|
+
}
|
|
451
|
+
NSError *error = nil;
|
|
452
|
+
if (![store saveEvent:event span:eventKitSpan commit:YES error:&error]) return finish(nil, gea::apple::Foundation::fromNSString(error.localizedDescription));
|
|
453
|
+
finish(event.eventIdentifier, "");`
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
name: 'removeEvent',
|
|
457
|
+
returns: nothing,
|
|
458
|
+
parameters: [
|
|
459
|
+
{ name: 'eventId', type: string },
|
|
460
|
+
{ name: 'occurrenceDate', type: string },
|
|
461
|
+
{ name: 'span', type: string },
|
|
462
|
+
{ name: 'completed', type: completion }
|
|
463
|
+
],
|
|
464
|
+
bridgeBody: `${eventStore}
|
|
465
|
+
${eventDates}
|
|
466
|
+
${findEvent}
|
|
467
|
+
auto finish = [&](std::string error) {
|
|
468
|
+
auto callback = completed;
|
|
469
|
+
dispatch_async(dispatch_get_main_queue(), ^{ if (callback) callback(error); });
|
|
470
|
+
};
|
|
471
|
+
EKSpan eventKitSpan;
|
|
472
|
+
if (!eventSpan(span, &eventKitSpan)) return finish("span must be thisEvent or futureEvents");
|
|
473
|
+
EKEvent *event = findEvent(gea::apple::Foundation::toNSString(eventId), gea::apple::Foundation::toNSString(occurrenceDate));
|
|
474
|
+
if (!event) return finish("No event with that id and occurrenceDate");
|
|
475
|
+
if (!event.calendar.allowsContentModifications) return finish("The event's calendar does not allow modifications");
|
|
476
|
+
NSError *error = nil;
|
|
477
|
+
if (![store removeEvent:event span:eventKitSpan commit:YES error:&error]) return finish(gea::apple::Foundation::fromNSString(error.localizedDescription));
|
|
478
|
+
finish("");`
|
|
479
|
+
}
|
|
480
|
+
]
|
|
186
481
|
}
|
|
187
482
|
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @gea-host-no-property-writes */
|
|
2
|
+
export declare function authorizationStatus(): string
|
|
3
|
+
/** @gea-host-no-property-writes */
|
|
4
|
+
export declare function requestFullAccess(completed: (granted: boolean, error: string) => void): void
|
|
5
|
+
/** @gea-host-no-property-writes */
|
|
6
|
+
export declare function calendars(): string
|
|
7
|
+
/** @gea-host-no-property-writes */
|
|
8
|
+
export declare function events(startISO: string, endISO: string, calendarIdsJSON: string): string
|
|
9
|
+
/** @gea-host-no-property-writes */
|
|
10
|
+
export declare function watchChanges(changed: () => void): number
|
|
11
|
+
/** @gea-host-no-property-writes */
|
|
12
|
+
export declare function stopWatchingChanges(handle: number): void
|
|
13
|
+
/** @gea-host-no-property-writes */
|
|
14
|
+
export declare function saveEvent(eventJSON: string, span: string, completed: (id: string, error: string) => void): void
|
|
15
|
+
/** @gea-host-no-property-writes */
|
|
16
|
+
export declare function removeEvent(eventId: string, occurrenceDate: string, span: string, completed: (error: string) => void): void
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/apple",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.19",
|
|
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": {
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"types": "./generated/UserNotifications.d.ts",
|
|
33
33
|
"import": "./runtime/UserNotifications.js"
|
|
34
34
|
},
|
|
35
|
+
"./EventKit": {
|
|
36
|
+
"types": "./generated/EventKit.d.ts",
|
|
37
|
+
"import": "./runtime/EventKit.js"
|
|
38
|
+
},
|
|
35
39
|
"./Dispatch": {
|
|
36
40
|
"types": "./generated/Dispatch.d.ts",
|
|
37
41
|
"import": "./runtime/Dispatch.js"
|
|
@@ -112,13 +116,13 @@
|
|
|
112
116
|
},
|
|
113
117
|
"dependencies": {
|
|
114
118
|
"@geastack/compiler": "^1.0.34",
|
|
115
|
-
"@geastack/core": "^0.1.
|
|
119
|
+
"@geastack/core": "^0.1.51",
|
|
116
120
|
"@geastack/elements": "^0.1.6",
|
|
117
|
-
"@geastack/engine": "^0.1.
|
|
121
|
+
"@geastack/engine": "^0.1.22",
|
|
118
122
|
"@geastack/geaos": "^0.1.3",
|
|
119
123
|
"@geastack/geatsc-plugin-apple-native": "^0.1.4",
|
|
120
124
|
"@geastack/geatsc-plugin-gea": "^0.1.24",
|
|
121
|
-
"@geastack/host": "^0.1.
|
|
125
|
+
"@geastack/host": "^0.1.23"
|
|
122
126
|
},
|
|
123
127
|
"scripts": {
|
|
124
128
|
"prepublishOnly": "npm run build",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function geaAppleEventKitNativeOnly(name) {
|
|
2
|
+
throw new Error(`@geastack/apple/EventKit ${name} is native-only and must be lowered by @geastack/geatsc-plugin-apple-native.`)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function authorizationStatus() {
|
|
6
|
+
return geaAppleEventKitNativeOnly("authorizationStatus")
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function requestFullAccess() {
|
|
10
|
+
return geaAppleEventKitNativeOnly("requestFullAccess")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function calendars() {
|
|
14
|
+
return geaAppleEventKitNativeOnly("calendars")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function events() {
|
|
18
|
+
return geaAppleEventKitNativeOnly("events")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function watchChanges() {
|
|
22
|
+
return geaAppleEventKitNativeOnly("watchChanges")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function stopWatchingChanges() {
|
|
26
|
+
return geaAppleEventKitNativeOnly("stopWatchingChanges")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function saveEvent() {
|
|
30
|
+
return geaAppleEventKitNativeOnly("saveEvent")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function removeEvent() {
|
|
34
|
+
return geaAppleEventKitNativeOnly("removeEvent")
|
|
35
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key><string>en</string>
|
|
6
|
+
<key>CFBundleExecutable</key><string>@APP_EXEC@</string>
|
|
7
|
+
<key>CFBundleIdentifier</key><string>@BUNDLE_ID@</string>
|
|
8
|
+
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
|
|
9
|
+
<key>CFBundleName</key><string>@APP_NAME@</string>
|
|
10
|
+
<key>CFBundlePackageType</key><string>APPL</string>
|
|
11
|
+
<key>CFBundleShortVersionString</key><string>0.1.0</string>
|
|
12
|
+
<key>CFBundleVersion</key><string>1</string>
|
|
13
|
+
<key>NSCameraUsageDescription</key><string>Gea native examples use the camera to demonstrate AVFoundation preview layers from TypeScript.</string>
|
|
14
|
+
<key>NSLocationWhenInUseUsageDescription</key><string>Gea native examples use location to demonstrate CoreLocation and MapKit from TypeScript.</string>
|
|
15
|
+
<key>UIRequiresFullScreen</key><true/>
|
|
16
|
+
<key>GCSupportsControllerUserInteraction</key><true/>
|
|
17
|
+
<key>GCSupportsMultipleMicroGamepads</key><true/>
|
|
18
|
+
<key>GCSupportedGameControllers</key>
|
|
19
|
+
<array>
|
|
20
|
+
<dict><key>ProfileName</key><string>MicroGamepad</string></dict>
|
|
21
|
+
<dict><key>ProfileName</key><string>DirectionalGamepad</string></dict>
|
|
22
|
+
<dict><key>ProfileName</key><string>ExtendedGamepad</string></dict>
|
|
23
|
+
</array>
|
|
24
|
+
<key>UIApplicationSceneManifest</key>
|
|
25
|
+
<dict>
|
|
26
|
+
<key>UIApplicationSupportsMultipleScenes</key><false/>
|
|
27
|
+
<key>UISceneConfigurations</key>
|
|
28
|
+
<dict>
|
|
29
|
+
<key>UIWindowSceneSessionRoleApplication</key>
|
|
30
|
+
<array>
|
|
31
|
+
<dict>
|
|
32
|
+
<key>UISceneConfigurationName</key><string>Default</string>
|
|
33
|
+
<key>UISceneDelegateClassName</key><string>GeaSceneDelegate</string>
|
|
34
|
+
</dict>
|
|
35
|
+
</array>
|
|
36
|
+
</dict>
|
|
37
|
+
</dict>
|
|
38
|
+
</dict>
|
|
39
|
+
</plist>
|
|
@@ -21,5 +21,19 @@
|
|
|
21
21
|
<array>
|
|
22
22
|
<string>UIInterfaceOrientationPortrait</string>
|
|
23
23
|
</array>
|
|
24
|
+
<key>UIApplicationSceneManifest</key>
|
|
25
|
+
<dict>
|
|
26
|
+
<key>UIApplicationSupportsMultipleScenes</key><false/>
|
|
27
|
+
<key>UISceneConfigurations</key>
|
|
28
|
+
<dict>
|
|
29
|
+
<key>UIWindowSceneSessionRoleApplication</key>
|
|
30
|
+
<array>
|
|
31
|
+
<dict>
|
|
32
|
+
<key>UISceneConfigurationName</key><string>Default</string>
|
|
33
|
+
<key>UISceneDelegateClassName</key><string>GeaSceneDelegate</string>
|
|
34
|
+
</dict>
|
|
35
|
+
</array>
|
|
36
|
+
</dict>
|
|
37
|
+
</dict>
|
|
24
38
|
</dict>
|
|
25
39
|
</plist>
|
package/targets/ios/README.md
CHANGED
|
@@ -59,3 +59,24 @@ The Xcode project is generated under
|
|
|
59
59
|
`<app>/dist/ios/<app-id>/GeaIos.xcodeproj`. Open it after running the script
|
|
60
60
|
if you want to inspect signing or launch through Xcode. Do not hand-edit it as
|
|
61
61
|
the source of truth.
|
|
62
|
+
|
|
63
|
+
## tvOS
|
|
64
|
+
|
|
65
|
+
Apps that declare `gea.targets.tvos` can use the shared UIKit host on tvOS 17
|
|
66
|
+
or later. Install the tvOS platform in Xcode's Components settings. From the
|
|
67
|
+
Geastack examples project, run the JSX demo on an Apple TV simulator:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
gea run --target tvos --app bouncing-balls-jsx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For a physical Apple TV, pair it with Xcode over the local network and use an
|
|
74
|
+
Apple development team configured for the device:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 gea run --target tvos --mode device --app bouncing-balls-jsx
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Use `gea build` with the same options to generate the Xcode project and build
|
|
81
|
+
without launching. Outputs are under the app's `dist/tvos`. The UIKit build
|
|
82
|
+
script shares its signing, device selection, and simulator overrides with iOS.
|