Skip to content

Commit 63eece5

Browse files
authored
fix(macos): add Apple Events entitlement for browser URLs (#1411)
1 parent 607b83a commit 63eece5

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

aw.spec

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def build_analysis(name, location, binaries=[], datas=[], hiddenimports=[]):
3636
)
3737

3838

39-
def build_collect(analysis, name, console=True):
39+
def build_collect(analysis, name, console=True, entitlements=None):
4040
"""Used to build the COLLECT statements for each module"""
4141
pyz = PYZ(analysis.pure, analysis.zipped_data)
4242
exe = EXE(
@@ -49,7 +49,7 @@ def build_collect(analysis, name, console=True):
4949
upx=True,
5050
console=console,
5151
contents_directory=".",
52-
entitlements_file=entitlements_file,
52+
entitlements_file=entitlements or entitlements_file,
5353
codesign_identity=codesign_identity,
5454
)
5555
return COLLECT(
@@ -74,6 +74,7 @@ print("bundling activitywatch version " + current_release)
7474

7575
# Get entitlements and codesign identity
7676
entitlements_file = Path(".") / "scripts" / "package" / "entitlements.plist"
77+
app_entitlements_file = Path(".") / "scripts" / "package" / "app-entitlements.plist"
7778
codesign_identity = os.environ.get("APPLE_PERSONALID", "").strip()
7879
if not codesign_identity:
7980
print("Environment variable APPLE_PERSONALID not set. Releases won't be signed.")
@@ -92,6 +93,8 @@ awi_location = Path("aw-watcher-input")
9293
aw_notify_location = Path("aw-notify")
9394

9495
if platform.system() == "Darwin":
96+
from PyInstaller.utils import osx as osxutils
97+
9598
icon = aw_qt_location / "media/logo/logo.icns"
9699
else:
97100
icon = aw_qt_location / "media/logo/logo.ico"
@@ -208,6 +211,7 @@ awq_coll = build_collect(
208211
aw_qt_a,
209212
"aw-qt",
210213
console=False if platform.system() == "Windows" else True,
214+
entitlements=app_entitlements_file,
211215
)
212216

213217
# aw-watcher-input
@@ -244,3 +248,8 @@ if platform.system() == "Darwin":
244248
# "CFBundleShortVersionString": current_release.lstrip('v'),
245249
},
246250
)
251+
252+
# BUNDLE inherits signing settings from the last COLLECT and deep-signs the
253+
# assembled bundle with them. Re-sign the application layer so its responsible
254+
# executable retains app-only capabilities without propagating them to helpers.
255+
osxutils.sign_binary(app.name, codesign_identity, app_entitlements_file)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<!-- These are required for binaries built by PyInstaller -->
6+
<key>com.apple.security.cs.allow-jit</key>
7+
<true/>
8+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
9+
<true/>
10+
<!-- The responsible application needs this to prompt for browser Apple Events access. -->
11+
<key>com.apple.security.automation.apple-events</key>
12+
<true/>
13+
</dict>
14+
</plist>

scripts/package/build_app_tauri.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ if [ -n "$APPLE_PERSONALID" ]; then
144144
# then .framework bundles, then the top-level .app last.
145145
# --timestamp is required for notarization (Apple rejects submissions without it).
146146
ENTITLEMENTS="scripts/package/entitlements.plist"
147+
APP_ENTITLEMENTS="scripts/package/app-entitlements.plist"
147148

148149
sign_binary() {
149150
echo " Signing: $1"
@@ -263,7 +264,10 @@ if [ -n "$APPLE_PERSONALID" ]; then
263264

264265
# Step 3: Sign the top-level .app bundle last.
265266
echo " Signing top-level .app bundle..."
266-
sign_binary "dist/${APP_NAME}.app"
267+
codesign --force --options runtime --timestamp \
268+
--entitlements "$APP_ENTITLEMENTS" \
269+
--sign "$APPLE_PERSONALID" \
270+
"dist/${APP_NAME}.app"
267271

268272
echo "App signing complete."
269273
else

scripts/package/entitlements.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<!-- Shared by nested binaries; app-only capabilities belong in app-entitlements.plist. -->
56
<!-- These are required for binaries built by PyInstaller -->
67
<key>com.apple.security.cs.allow-jit</key>
78
<true/>

0 commit comments

Comments
 (0)