Skip to content

Commit b85e256

Browse files
committed
Fix Capacitor local notification patching
- Restore correct JSObject array handling for notification and type guards - Keep the generated Swift patch in sync with Capacitor handler changes
1 parent 3b442d3 commit b85e256

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

scripts/patch-capacitor-local-notifications.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,70 @@ const HANDLER_FILE = resolve(
1414
const REPLACEMENTS: ReadonlyArray<[string, string]> = [
1515
[
1616
[
17-
' guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }) else {\n',
17+
' guard let notifications = call.getArray("notifications", JSObject.self) else {\n',
1818
' call.reject("Must provide notifications array as notifications option")\n',
1919
" return\n",
2020
" }\n",
2121
].join(""),
2222
[
23-
' guard call.getValue("notifications") != nil else {\n',
23+
' guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }) else {\n',
2424
' call.reject("Must provide notifications array as notifications option")\n',
2525
" return\n",
2626
" }\n",
27-
' let notifications = call.getArray("notifications", JSObject.self) ?? []\n',
2827
].join(""),
2928
],
3029
[
3130
[
32-
' guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }), notifications.count > 0 else {\n',
31+
' guard let notifications = call.getArray("notifications", JSObject.self), notifications.count > 0 else {\n',
3332
' call.reject("Must supply notifications to cancel")\n',
3433
" return\n",
3534
" }\n",
3635
].join(""),
3736
[
38-
' guard call.getValue("notifications") != nil else {\n',
39-
' call.reject("Must supply notifications to cancel")\n',
40-
" return\n",
41-
" }\n",
42-
' let notifications = call.getArray("notifications", JSObject.self) ?? []\n',
43-
" guard notifications.count > 0 else {\n",
37+
' guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }), notifications.count > 0 else {\n',
4438
' call.reject("Must supply notifications to cancel")\n',
4539
" return\n",
4640
" }\n",
4741
].join(""),
4842
],
4943
[
5044
[
51-
' guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }), notifications.count > 0 else {\n',
52-
' call.reject("Must supply notifications to remove")\n',
45+
' guard let types = call.getArray("types", JSObject.self) else {\n',
5346
" return\n",
5447
" }\n",
5548
].join(""),
5649
[
57-
' guard call.getValue("notifications") != nil else {\n',
50+
' guard let types = call.getArray("types")?.compactMap({ $0 as? JSObject }) else {\n',
51+
" return\n",
52+
" }\n",
53+
].join(""),
54+
],
55+
[
56+
[
57+
' guard let notifications = call.getArray("notifications", JSObject.self) else {\n',
5858
' call.reject("Must supply notifications to remove")\n',
5959
" return\n",
6060
" }\n",
61-
' let notifications = call.getArray("notifications", JSObject.self) ?? []\n',
62-
" guard notifications.count > 0 else {\n",
61+
].join(""),
62+
[
63+
' guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }) else {\n',
6364
' call.reject("Must supply notifications to remove")\n',
6465
" return\n",
6566
" }\n",
6667
].join(""),
6768
],
6869
[
6970
[
70-
' guard let types = call.getArray("types")?.compactMap({ $0 as? JSObject }) else {\n',
71+
' guard let notifications = call.getArray("notifications", JSObject.self), notifications.count > 0 else {\n',
72+
' call.reject("Must supply notifications to remove")\n',
7173
" return\n",
7274
" }\n",
7375
].join(""),
7476
[
75-
' guard call.getValue("types") != nil else {\n',
77+
' guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }), notifications.count > 0 else {\n',
78+
' call.reject("Must supply notifications to remove")\n',
7679
" return\n",
7780
" }\n",
78-
' let types = call.getArray("types", JSObject.self) ?? []\n',
7981
].join(""),
8082
],
8183
[

0 commit comments

Comments
 (0)