Skip to content

Commit a19d671

Browse files
committed
fix: patch capacitor local notifications for xcode 15
1 parent 1b7bcc8 commit a19d671

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ jobs:
349349
- name: Install dependencies
350350
run: bun install --frozen-lockfile
351351

352+
- name: Patch Capacitor local-notifications for Xcode 15
353+
run: bun run patch:capacitor-local-notifications
354+
352355
- name: Align package versions to release version
353356
run: node scripts/update-release-package-versions.ts "$RELEASE_VERSION"
354357

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"release:smoke": "node scripts/release-smoke.ts",
5757
"dist:mobile:build": "bun run --cwd apps/mobile build",
5858
"dist:mobile:sync:ios": "cd apps/mobile && bunx cap sync ios --deployment",
59+
"patch:capacitor-local-notifications": "node scripts/patch-capacitor-local-notifications.ts",
5960
"dist:mobile:update-ios-version": "node scripts/update-ios-version.ts",
6061
"review": "bash scripts/pr-review-workspace.sh",
6162
"review:dump": "bash scripts/pr-review-dump.sh",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
2+
import { resolve } from "node:path";
3+
4+
const ROOT_DIR = resolve(process.cwd());
5+
const TARGET_FILE = resolve(
6+
ROOT_DIR,
7+
"node_modules/@capacitor/local-notifications/ios/Sources/LocalNotificationsPlugin/LocalNotificationsPlugin.swift",
8+
);
9+
10+
const REPLACEMENTS: ReadonlyArray<[RegExp, string]> = [
11+
[
12+
/guard let notifications = call\.getArray\("notifications", JSObject\.self\) else \{/g,
13+
'guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }) else {',
14+
],
15+
[
16+
/guard let notifications = call\.getArray\("notifications", JSObject\.self\), notifications\.count > 0 else \{/g,
17+
'guard let notifications = call.getArray("notifications")?.compactMap({ $0 as? JSObject }), notifications.count > 0 else {',
18+
],
19+
[
20+
/guard let types = call\.getArray\("types", JSObject\.self\) else \{/g,
21+
'guard let types = call.getArray("types")?.compactMap({ $0 as? JSObject }) else {',
22+
],
23+
[
24+
/return bridge\?\.localURL\(fromWebURL: webURL\)/g,
25+
[
26+
" switch webURL.scheme {",
27+
' case "res":',
28+
" return bridge?.config.appLocation.appendingPathComponent(webURL.path)",
29+
' case "file":',
30+
" return webURL",
31+
" default:",
32+
" return nil",
33+
" }",
34+
].join("\n"),
35+
],
36+
];
37+
38+
if (!existsSync(TARGET_FILE)) {
39+
console.log(`Skipping Capacitor local-notifications patch; missing file: ${TARGET_FILE}`);
40+
process.exit(0);
41+
}
42+
43+
const original = readFileSync(TARGET_FILE, "utf8");
44+
let updated = original;
45+
46+
for (const [pattern, replacement] of REPLACEMENTS) {
47+
updated = updated.replace(pattern, replacement);
48+
}
49+
50+
if (updated !== original) {
51+
writeFileSync(TARGET_FILE, updated);
52+
console.log(`Patched ${TARGET_FILE}`);
53+
} else {
54+
console.log(`No patch needed for ${TARGET_FILE}`);
55+
}

0 commit comments

Comments
 (0)