Fix Gatekeeper stopping BGMXPCHelper from launching on macOS 14.

Also, build the ListInputDevices tool as a universal binary.

Contributed by modue sp. z o.o..
This commit is contained in:
Kyle Neideck 2024-04-25 08:46:54 +10:00
parent e655d571e0
commit 8b2bf56eca
No known key found for this signature in database
GPG key ID: CAA8D9B8E39EC18C
2 changed files with 17 additions and 1 deletions

View file

@ -21,6 +21,7 @@
#
# Copyright © 2017-2022 Kyle Neideck
# Copyright © 2016, 2017 Takayama Fumihiko
# Copyright © 2023 modue sp. z o.o.
#
# Builds Background Music and packages it into a .pkg file. Call this script with -d to use the
# debug build configuration.
@ -141,7 +142,12 @@ fi
echo "Compiling ListInputDevices"
if ! [[ $packaging_operation == "repackage" ]]; then
swiftc pkg/ListInputDevices.swift -o pkg/ListInputDevices
echo "Compiling ListInputDevices"
swiftc pkg/ListInputDevices.swift -o pkg/ListInputDevices-x86_64 -target x86_64-apple-macos13.0
swiftc pkg/ListInputDevices.swift -o pkg/ListInputDevices-arm64 -target arm64-apple-macos13.0
# Combine the x86_64 and arm64 binaries into a universal binary.
lipo -create pkg/ListInputDevices-x86_64 pkg/ListInputDevices-arm64 -output pkg/ListInputDevices
rm pkg/ListInputDevices-x86_64 pkg/ListInputDevices-arm64
fi
# --------------------------------------------------

View file

@ -20,6 +20,7 @@
# postinstall
#
# Copyright © 2017-2022, 2024 Kyle Neideck
# Copyright © 2023 modue sp. z o.o.
#
# Make sure we use the built-in versions of programs, for consistency. Probably not necessary
@ -44,6 +45,15 @@ log "Installing BGMXPCHelper to $xpc_helper_install_path"
rm -rf "${xpc_helper_install_path}/BGMXPCHelper.xpc"
cp -Rf "BGMXPCHelper.xpc" "$xpc_helper_install_path"
# Remove the quarantine attribute from BGMXPCHelper. Since macOS 14.0, this is needed to keep
# Gatekeeper from trying to show a permission prompt when BGMXPCHelper is launched. That would
# fail because BGMXPCHelper is a daemon, and Gatekeeper would prevent it from launching.
#
# TODO: I think, ideally, we should use the new Service Management API to install BGMXPCHelper,
# which would probably avoid this issue. See
# <https://developer.apple.com/documentation/servicemanagement/updating_your_app_package_installer_to_use_the_new_service_management_api>.
sudo xattr -d com.apple.quarantine "${xpc_helper_install_path}/BGMXPCHelper.xpc"
# TODO: Fail the install and show an error message if this fails.
bash "post_install.sh" "$xpc_helper_install_path" "BGMXPCHelper.xpc/Contents/MacOS/BGMXPCHelper" "."