@octane-xplat/calendar 0.18.0 → 0.20.0
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 +3 -23
- package/package.json +86 -93
- package/src/calendar.macos.ts +255 -11
- package/src/calendar.ts +389 -258
- package/src/calendar.web.ts +11 -9
- package/src/calendar.windows.ts +12 -10
- package/src/types.ts +69 -31
- package/types/generated/.tsrx-typegen-manifest.json +0 -6
- package/types/generated/calendar.d.ts +1 -0
- package/types/generated/types.d.ts +38 -0
- package/LICENSE +0 -21
- package/types/generated/calendar.linux.d.ts +0 -1
- package/types/generated/calendar.macos.d.ts +0 -2
- package/types/generated/calendar.web.d.ts +0 -2
- package/types/generated/calendar.windows.d.ts +0 -2
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
package/src/calendar.ts
CHANGED
|
@@ -14,129 +14,154 @@ declare const NSDate: any
|
|
|
14
14
|
|
|
15
15
|
let store: any = null
|
|
16
16
|
const eventStore = () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (!store && typeof EKEventStore !== 'undefined') {
|
|
18
|
+
store = EKEventStore.new()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return store
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
function iosEnsure(): Promise<PermissionResult> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
25
|
+
const s = eventStore()
|
|
26
|
+
|
|
27
|
+
if (!s || typeof EKEntityTypeEvent === 'undefined') {
|
|
28
|
+
return Promise.resolve('unsupported')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const status = EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent)
|
|
32
|
+
|
|
33
|
+
// 0 notDetermined 1 restricted 2 denied 3 fullAccess/authorized 4 writeOnly
|
|
34
|
+
if (status === 3 || status === 4) {
|
|
35
|
+
return Promise.resolve('granted')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (status === 1 || status === 2) {
|
|
39
|
+
return Promise.resolve('denied')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
if (typeof s.requestFullAccessToEventsWithCompletion === 'function') {
|
|
44
|
+
s.requestFullAccessToEventsWithCompletion((granted: boolean) =>
|
|
45
|
+
resolve(granted ? 'granted' : 'denied'),
|
|
46
|
+
)
|
|
47
|
+
} else {
|
|
48
|
+
s.requestAccessToEntityTypeCompletion(EKEntityTypeEvent, (granted: boolean) =>
|
|
49
|
+
resolve(granted ? 'granted' : 'denied'),
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
let calRequestCode = 7731
|
|
50
56
|
|
|
51
57
|
function androidEnsure(): Promise<PermissionResult> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
58
|
+
const perm = 'android.permission.READ_CALENDAR'
|
|
59
|
+
const activity = Application.android.foregroundActivity ?? Application.android.startActivity
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
if (
|
|
63
|
+
activity?.checkSelfPermission?.(perm) === android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
64
|
+
) {
|
|
65
|
+
return Promise.resolve('granted')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!activity) {
|
|
69
|
+
return Promise.resolve('denied')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return new Promise<PermissionResult>((resolve) => {
|
|
73
|
+
const requestCode = calRequestCode++
|
|
74
|
+
const event = Application.android.activityRequestPermissionsEvent
|
|
75
|
+
const onResult = (args: any) => {
|
|
76
|
+
if (args.requestCode !== requestCode) {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Application.android.off(event, onResult)
|
|
81
|
+
resolve(
|
|
82
|
+
args.grantResults?.[0] === android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
83
|
+
? 'granted'
|
|
84
|
+
: 'denied',
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Application.android.on(event, onResult)
|
|
89
|
+
try {
|
|
90
|
+
activity.requestPermissions([perm, 'android.permission.WRITE_CALENDAR'], requestCode)
|
|
91
|
+
} catch {
|
|
92
|
+
Application.android.off(event, onResult)
|
|
93
|
+
resolve('denied')
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
} catch {
|
|
97
|
+
return Promise.resolve('denied')
|
|
98
|
+
}
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
function iosCalendars(): CalendarInfo[] {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const s = eventStore()
|
|
103
|
+
const out: CalendarInfo[] = []
|
|
104
|
+
const list = s?.calendarsForEntityType?.(EKEntityTypeEvent ?? 0)
|
|
105
|
+
|
|
106
|
+
for (let i = 0; i < (list?.count ?? 0); i++) {
|
|
107
|
+
const c = list.objectAtIndex(i)
|
|
108
|
+
|
|
109
|
+
out.push({
|
|
110
|
+
id: String(c.calendarIdentifier ?? ''),
|
|
111
|
+
title: String(c.title ?? ''),
|
|
112
|
+
color: c.CGColor ? String(c.CGColor) : undefined,
|
|
113
|
+
source: c.source?.title ? String(c.source.title) : undefined,
|
|
114
|
+
allowsModifications: !!c.allowsContentModifications,
|
|
115
|
+
isPrimary: false,
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return out
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
function iosEvent(e: any): CalendarEvent {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
return {
|
|
124
|
+
id: String(e.eventIdentifier ?? ''),
|
|
125
|
+
calendarId: e.calendar?.calendarIdentifier ? String(e.calendar.calendarIdentifier) : undefined,
|
|
126
|
+
title: String(e.title ?? ''),
|
|
127
|
+
startDate: new Date((e.startDate?.timeIntervalSince1970 ?? 0) * 1000),
|
|
128
|
+
endDate: new Date((e.endDate?.timeIntervalSince1970 ?? 0) * 1000),
|
|
129
|
+
allDay: !!e.allDay,
|
|
130
|
+
location: e.location ? String(e.location) : undefined,
|
|
131
|
+
notes: e.notes ? String(e.notes) : undefined,
|
|
132
|
+
timeZone: e.timeZone?.name ? String(e.timeZone.name) : undefined,
|
|
133
|
+
}
|
|
120
134
|
}
|
|
121
135
|
|
|
122
136
|
const androidUtils = Utils.android as any
|
|
123
137
|
const resolver = () => androidUtils?.getApplicationContext?.()?.getContentResolver()
|
|
124
138
|
|
|
125
|
-
function androidQuery(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
function androidQuery(
|
|
140
|
+
uri: any,
|
|
141
|
+
projection: string[],
|
|
142
|
+
selection: string,
|
|
143
|
+
args: string[],
|
|
144
|
+
sort: string,
|
|
145
|
+
): any[] {
|
|
146
|
+
const cursor = resolver()?.query(uri, projection, selection, args, sort)
|
|
147
|
+
const out: any[] = []
|
|
148
|
+
|
|
149
|
+
if (!cursor) {
|
|
150
|
+
return out
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
while (cursor.moveToNext()) {
|
|
154
|
+
const row: Record<string, any> = {}
|
|
155
|
+
|
|
156
|
+
for (let i = 0; i < cursor.getColumnCount(); i++) {
|
|
157
|
+
row[cursor.getColumnName(i)] = cursor.getString(i)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
out.push(row)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
cursor.close()
|
|
164
|
+
return out
|
|
140
165
|
}
|
|
141
166
|
|
|
142
167
|
const CAL_URI = () => android.provider.CalendarContract.Calendars.CONTENT_URI
|
|
@@ -144,167 +169,273 @@ const EVENTS_URI = () => android.provider.CalendarContract.Events.CONTENT_URI
|
|
|
144
169
|
const INSTANCES_URI = () => android.provider.CalendarContract.Instances.CONTENT_URI
|
|
145
170
|
|
|
146
171
|
function androidCalendars(): CalendarInfo[] {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
172
|
+
return androidQuery(
|
|
173
|
+
CAL_URI(),
|
|
174
|
+
[
|
|
175
|
+
'_id',
|
|
176
|
+
'calendar_displayName',
|
|
177
|
+
'calendar_color',
|
|
178
|
+
'account_name',
|
|
179
|
+
'calendar_access_level',
|
|
180
|
+
'isPrimary',
|
|
181
|
+
],
|
|
182
|
+
'',
|
|
183
|
+
[],
|
|
184
|
+
'calendar_displayName ASC',
|
|
185
|
+
).map((row) => ({
|
|
186
|
+
id: String(row._id),
|
|
187
|
+
title: String(row.calendar_displayName ?? ''),
|
|
188
|
+
color: row.calendar_color,
|
|
189
|
+
source: row.account_name,
|
|
190
|
+
allowsModifications: Number(row.calendar_access_level) >= 500,
|
|
191
|
+
isPrimary: row.isPrimary === '1' || row.isPrimary === 'true',
|
|
192
|
+
}))
|
|
155
193
|
}
|
|
156
194
|
|
|
157
195
|
function androidEvent(row: any): CalendarEvent {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
196
|
+
return {
|
|
197
|
+
id: String(row._id ?? row.event_id ?? ''),
|
|
198
|
+
calendarId: row.calendar_id ? String(row.calendar_id) : undefined,
|
|
199
|
+
title: String(row.title ?? ''),
|
|
200
|
+
startDate: new Date(Number(row.dtstart ?? row.begin ?? 0)),
|
|
201
|
+
endDate: new Date(Number(row.dtend ?? row.end ?? 0)),
|
|
202
|
+
allDay: row.allDay === '1' || row.allDay === 1,
|
|
203
|
+
location: row.eventLocation,
|
|
204
|
+
notes: row.description,
|
|
205
|
+
}
|
|
168
206
|
}
|
|
169
207
|
|
|
208
|
+
/** Calendar service — EventKit/CalendarContract. */
|
|
170
209
|
export const calendar: Calendar = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
210
|
+
supported: isIOS ? typeof EKEventStore !== 'undefined' : true,
|
|
211
|
+
|
|
212
|
+
ensure(): Promise<PermissionResult> {
|
|
213
|
+
return isIOS ? iosEnsure() : androidEnsure()
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
async getCalendars(): Promise<CalendarInfo[]> {
|
|
217
|
+
return isIOS ? iosCalendars() : androidCalendars()
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
async getDefaultCalendar(): Promise<CalendarInfo | null> {
|
|
221
|
+
if (isIOS) {
|
|
222
|
+
const s = eventStore()
|
|
223
|
+
const def = s?.defaultCalendarForNewEvents
|
|
224
|
+
|
|
225
|
+
return def
|
|
226
|
+
? {
|
|
227
|
+
id: String(def.calendarIdentifier),
|
|
228
|
+
title: String(def.title ?? ''),
|
|
229
|
+
allowsModifications: !!def.allowsContentModifications,
|
|
230
|
+
}
|
|
231
|
+
: null
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return androidCalendars().find((c) => c.isPrimary) ?? androidCalendars()[0] ?? null
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
async getEvents(
|
|
238
|
+
startDate: Date,
|
|
239
|
+
endDate: Date,
|
|
240
|
+
calendarIds?: string[],
|
|
241
|
+
): Promise<CalendarEvent[]> {
|
|
242
|
+
if (isIOS) {
|
|
243
|
+
const s = eventStore()
|
|
244
|
+
const begin = NSDate.dateWithTimeIntervalSince1970(startDate.getTime() / 1000)
|
|
245
|
+
const end = NSDate.dateWithTimeIntervalSince1970(endDate.getTime() / 1000)
|
|
246
|
+
const predicate = s.predicateForEventsWithStartDateEndDateCalendars(begin, end, null)
|
|
247
|
+
const list = s.eventsMatchingPredicate(predicate)
|
|
248
|
+
const out: CalendarEvent[] = []
|
|
249
|
+
|
|
250
|
+
for (let i = 0; i < (list?.count ?? 0); i++) {
|
|
251
|
+
const e = iosEvent(list.objectAtIndex(i))
|
|
252
|
+
|
|
253
|
+
if (!calendarIds?.length || calendarIds.includes(e.calendarId ?? '')) {
|
|
254
|
+
out.push(e)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return out
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const selection = calendarIds?.length
|
|
262
|
+
? `calendar_id IN (${calendarIds.map(() => '?').join(',')})`
|
|
263
|
+
: ''
|
|
264
|
+
|
|
265
|
+
const args = calendarIds ?? []
|
|
266
|
+
|
|
267
|
+
return androidQuery(
|
|
268
|
+
INSTANCES_URI(),
|
|
269
|
+
[
|
|
270
|
+
'event_id',
|
|
271
|
+
'calendar_id',
|
|
272
|
+
'title',
|
|
273
|
+
'begin',
|
|
274
|
+
'end',
|
|
275
|
+
'allDay',
|
|
276
|
+
'eventLocation',
|
|
277
|
+
'description',
|
|
278
|
+
],
|
|
279
|
+
selection,
|
|
280
|
+
args,
|
|
281
|
+
'begin ASC',
|
|
282
|
+
)
|
|
283
|
+
.map((row) => androidEvent(row))
|
|
284
|
+
.filter((e) => e.startDate <= endDate && e.endDate >= startDate)
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
async getEvent(id: string): Promise<CalendarEvent | null> {
|
|
288
|
+
if (isIOS) {
|
|
289
|
+
const e = eventStore()?.eventWithIdentifier?.(id)
|
|
290
|
+
|
|
291
|
+
return e ? iosEvent(e) : null
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const rows = androidQuery(
|
|
295
|
+
(android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)),
|
|
296
|
+
['_id', 'calendar_id', 'title', 'dtstart', 'dtend', 'allDay', 'eventLocation', 'description'],
|
|
297
|
+
'',
|
|
298
|
+
[],
|
|
299
|
+
'',
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
return rows.length ? androidEvent(rows[0]) : null
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
async createEvent(calendarId: string | undefined, event: NewEvent): Promise<string> {
|
|
306
|
+
if (isIOS) {
|
|
307
|
+
const s = eventStore()
|
|
308
|
+
const e = EKEvent.eventWithEventStore(s)
|
|
309
|
+
|
|
310
|
+
e.title = event.title
|
|
311
|
+
e.startDate = NSDate.dateWithTimeIntervalSince1970(event.startDate.getTime() / 1000)
|
|
312
|
+
e.endDate = NSDate.dateWithTimeIntervalSince1970(event.endDate.getTime() / 1000)
|
|
313
|
+
e.allDay = !!event.allDay
|
|
314
|
+
e.location = event.location
|
|
315
|
+
e.notes = event.notes
|
|
316
|
+
e.calendar = calendarId
|
|
317
|
+
? (s.calendarWithIdentifier?.(calendarId) ?? s.defaultCalendarForNewEvents)
|
|
318
|
+
: s.defaultCalendarForNewEvents
|
|
319
|
+
|
|
320
|
+
if (!s.saveEventSpanError(e, 0, null)) {
|
|
321
|
+
throw new Error('calendar.createEvent: EKEventStore.saveEvent failed')
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return String(e.eventIdentifier ?? '')
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const values = new android.content.ContentValues()
|
|
328
|
+
const def = await calendar.getDefaultCalendar()
|
|
329
|
+
|
|
330
|
+
values.put('calendar_id', java.lang.Long.valueOf(calendarId ?? def?.id ?? '0'))
|
|
331
|
+
values.put('title', event.title)
|
|
332
|
+
values.put('dtstart', java.lang.Long.valueOf(event.startDate.getTime()))
|
|
333
|
+
values.put('dtend', java.lang.Long.valueOf(event.endDate.getTime()))
|
|
334
|
+
values.put('allDay', java.lang.Integer.valueOf(event.allDay ? 1 : 0))
|
|
335
|
+
if (event.location) {
|
|
336
|
+
values.put('eventLocation', event.location)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (event.notes) {
|
|
340
|
+
values.put('description', event.notes)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
values.put('eventTimezone', event.timeZone ?? 'UTC')
|
|
344
|
+
|
|
345
|
+
const uri = resolver()?.insert(EVENTS_URI(), values)
|
|
346
|
+
|
|
347
|
+
return uri ? String(uri.getLastPathSegment()) : ''
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
async updateEvent(id: string, patch: Partial<NewEvent>): Promise<string> {
|
|
351
|
+
if (isIOS) {
|
|
352
|
+
const s = eventStore()
|
|
353
|
+
const e = s.eventWithIdentifier?.(id)
|
|
354
|
+
|
|
355
|
+
if (!e) {
|
|
356
|
+
throw new Error(`calendar.updateEvent: no event ${id}`)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (patch.title !== undefined) {
|
|
360
|
+
e.title = patch.title
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (patch.startDate) {
|
|
364
|
+
e.startDate = NSDate.dateWithTimeIntervalSince1970(patch.startDate.getTime() / 1000)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (patch.endDate) {
|
|
368
|
+
e.endDate = NSDate.dateWithTimeIntervalSince1970(patch.endDate.getTime() / 1000)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (patch.allDay !== undefined) {
|
|
372
|
+
e.allDay = patch.allDay
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (patch.location !== undefined) {
|
|
376
|
+
e.location = patch.location
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (patch.notes !== undefined) {
|
|
380
|
+
e.notes = patch.notes
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
s.saveEventSpanError(e, 0, null)
|
|
384
|
+
return id
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const values = new android.content.ContentValues()
|
|
388
|
+
|
|
389
|
+
if (patch.title !== undefined) {
|
|
390
|
+
values.put('title', patch.title)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (patch.startDate) {
|
|
394
|
+
values.put('dtstart', java.lang.Long.valueOf(patch.startDate.getTime()))
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (patch.endDate) {
|
|
398
|
+
values.put('dtend', java.lang.Long.valueOf(patch.endDate.getTime()))
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (patch.location !== undefined) {
|
|
402
|
+
values.put('eventLocation', patch.location)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (patch.notes !== undefined) {
|
|
406
|
+
values.put('description', patch.notes)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
resolver()?.update(
|
|
410
|
+
(android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)),
|
|
411
|
+
values,
|
|
412
|
+
null,
|
|
413
|
+
null,
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
return id
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
async deleteEvent(id: string): Promise<void> {
|
|
420
|
+
if (isIOS) {
|
|
421
|
+
const s = eventStore()
|
|
422
|
+
const e = s.eventWithIdentifier?.(id)
|
|
423
|
+
|
|
424
|
+
if (e) {
|
|
425
|
+
s.removeEventSpanError(e, 0, null)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
resolver()?.delete(
|
|
432
|
+
(android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)),
|
|
433
|
+
null,
|
|
434
|
+
null,
|
|
435
|
+
)
|
|
436
|
+
},
|
|
307
437
|
}
|
|
308
438
|
|
|
309
439
|
const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
|
|
440
|
+
|
|
310
441
|
permissionOwners.calendar = () => calendar.ensure()
|