Skip to content

Commit

Permalink
Merge pull request #3820 from pqrs-org/service-management
Browse files Browse the repository at this point in the history
Stop using the legacy /Library/LaunchDaemons, /Library/LaunchAgents
  • Loading branch information
tekezo authored May 21, 2024
2 parents 104c216 + 3c90c27 commit 07643e2
Show file tree
Hide file tree
Showing 66 changed files with 402 additions and 497 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Beta

- 💥 Breaking changes
- macOS 11 and macOS 12 are no longer supported.
- ✨ New Features
- Added the ability to duplicate and reorder profiles.
- Added the ability to restart Karabiner-Elements from the menu.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra or later.
Karabiner-Elements is a powerful key remapper for macOS.

## Download

Expand All @@ -17,10 +17,10 @@ You can download previous versions of Karabiner-Elements from [here](https://kar

## Supported systems

- macOS 11 Big Sur
- macOS 12 Monterey
- macOS 13 Ventura
- macOS 14 Sonoma
- Both Intel-based Macs and Apple Silicon Macs
- macOS 13 Ventura
- Both Intel-based Macs and Apple Silicon Macs

## Usage

Expand Down
2 changes: 1 addition & 1 deletion appendix/GamePadViewer/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets:
- ../../src/vendor/cget/include
type: application
platform: macOS
deploymentTarget: 11.0
deploymentTarget: 13.0
sources:
- path: src
compilerFlags:
Expand Down
2 changes: 1 addition & 1 deletion appendix/common.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum OS X deployment version")
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0" CACHE STRING "Minimum OS X deployment version")

set(CMAKE_CXX_STANDARD 20)

Expand Down
2 changes: 1 addition & 1 deletion appendix/dump_libkrbn/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets:
- ../../src/vendor/Karabiner-DriverKit-VirtualHIDDevice/include
type: tool
platform: macOS
deploymentTarget: 11.0
deploymentTarget: 13.0
sources:
- path: main.cpp
compilerFlags:
Expand Down
32 changes: 1 addition & 31 deletions make-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@
set -u # forbid undefined variables
set -e # forbid command failure

#
# Check Xcode version
#

# Note:
# Using `xcrun --show-sdk-version` in GitHub Actions results in the following error.
#
# ```
# xcodebuild: error: SDK "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" cannot be located.
# xcrun: error: unable to lookup item 'SDKVersion' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
# ```
#
# Therefore, we extract the version from the Info.plist of Xcode.app

xcodeVersion=$(plutil -extract CFBundleShortVersionString raw "$(xcode-select -p)/../Info.plist")
xcodeMajorVersion=$(echo "$xcodeVersion" | sed 's|\..*$||')
echo "Xcode version: $xcodeVersion"
echo "Xcode major version: $xcodeMajorVersion"
if [[ "$xcodeMajorVersion" -lt 15 ]]; then
echo
echo 'ERROR:'
echo ' Xcode is too old.'
echo ' You have to use Xcode 15.0.1 or later.'
echo
exit 1
fi

version=$(cat version)

#
Expand Down Expand Up @@ -59,6 +32,7 @@ cp -R "src/apps/AppIconSwitcher/build/Release/Karabiner-AppIconSwitcher.app" "$b
cp -R "src/apps/Menu/build/Release/Karabiner-Menu.app" "$basedir"
cp -R "src/apps/MultitouchExtension/build/Release/Karabiner-MultitouchExtension.app" "$basedir"
cp -R "src/apps/NotificationWindow/build/Release/Karabiner-NotificationWindow.app" "$basedir"
cp -R "src/apps/Services/build/Release/Karabiner-Elements-Services.app" "$basedir"

basedir="pkgroot/Library/Application Support/org.pqrs/Karabiner-Elements/scripts"
mkdir -p "$basedir"
Expand All @@ -73,10 +47,6 @@ cp src/core/console_user_server/build/Release/karabiner_console_user_server "$ba
cp src/core/grabber/build/Release/karabiner_grabber "$basedir"
cp src/core/session_monitor/build/Release/karabiner_session_monitor "$basedir"

mkdir -p "pkgroot/Library"
cp -R files/LaunchDaemons "pkgroot/Library"
cp -R files/LaunchAgents "pkgroot/Library"

basedir="pkgroot/Applications"
mkdir -p "$basedir"
cp -R "src/apps/EventViewer/build/Release/Karabiner-EventViewer.app" "$basedir"
Expand Down
2 changes: 1 addition & 1 deletion pkginfo/Distribution.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>Karabiner-Elements @VERSION@</title>
<volume-check>
<allowed-os-versions>
<os-version min="11.0" />
<os-version min="13.0" />
</allowed-os-versions>
</volume-check>
<!--
Expand Down
9 changes: 1 addition & 8 deletions pkginfo/Scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ chmod 4755 '/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabin
# Register /Applications/Karabiner-Elements.app in the Launch Services database.
#

'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli' --lsregister-karabiner-elements
'/Library/Application Support/org.pqrs/Karabiner-Elements/Karabiner-Elements-Services.app/Contents/MacOS/Karabiner-Elements-Services' register-core-daemons

#
# Relaunch karabiner processes
Expand All @@ -32,13 +32,6 @@ cp \
'/Library/Application Support/org.pqrs/Karabiner-Elements/package-version' \
'/Library/Application Support/org.pqrs/Karabiner-Elements/version'

# If plistFilePath is already bootstrapped and disabled, launchctl bootstrap will fail until it is enabled again.
# So we should enable it first, and then bootstrap and enable it.

launchctl enable system/org.pqrs.karabiner.karabiner_grabber
launchctl bootstrap system /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_grabber.plist
launchctl enable system/org.pqrs.karabiner.karabiner_grabber

#
# Create a backup to allow recovery if the user manually deletes Karabiner-Elements without using the uninstaller
#
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ all:
$(MAKE) -C apps/Menu
$(MAKE) -C apps/MultitouchExtension
$(MAKE) -C apps/NotificationWindow
$(MAKE) -C apps/Services
$(MAKE) -C apps/SettingsWindow
$(MAKE) -C bin/cli
$(MAKE) -C core/console_user_server
Expand All @@ -17,6 +18,7 @@ clean:
$(MAKE) -C apps/Menu clean
$(MAKE) -C apps/MultitouchExtension clean
$(MAKE) -C apps/NotificationWindow clean
$(MAKE) -C apps/Services clean
$(MAKE) -C apps/SettingsWindow clean
$(MAKE) -C bin/cli clean
$(MAKE) -C core/console_user_server clean
Expand Down
2 changes: 1 addition & 1 deletion src/apps/AppIconSwitcher/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ targets:
OTHER_SWIFT_FLAGS: '-warnings-as-errors'
type: application
platform: macOS
deploymentTarget: 11.0
deploymentTarget: 13.0
sources:
- path: src
compilerFlags:
Expand Down
2 changes: 1 addition & 1 deletion src/apps/EventViewer/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets:
- ../../vendor/cget/include
type: application
platform: macOS
deploymentTarget: 11.0
deploymentTarget: 13.0
sources:
- path: src
compilerFlags:
Expand Down
2 changes: 1 addition & 1 deletion src/apps/Menu/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets:
- ../../vendor/cget/include
type: application
platform: macOS
deploymentTarget: 11.0
deploymentTarget: 13.0
sources:
- path: src
compilerFlags:
Expand Down
2 changes: 1 addition & 1 deletion src/apps/Menu/src/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public class MenuController: NSObject, NSMenuDelegate {

@objc
func restartKarabiner(_: Any) {
libkrbn_launchctl_restart_console_user_server()
libkrbn_services_restart_console_user_server_agent()
}

@objc
Expand Down
2 changes: 1 addition & 1 deletion src/apps/MultitouchExtension/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets:
SWIFT_OBJC_BRIDGING_HEADER: src/Bridging-Header.h
type: application
platform: macOS
deploymentTarget: 11.0
deploymentTarget: 13.0
sources:
- path: src
compilerFlags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private func callback(
class MultitouchDeviceManager {
static let shared = MultitouchDeviceManager()

private let notificationPort = IONotificationPortCreate(kIOMasterPortDefault)
private let notificationPort = IONotificationPortCreate(kIOMainPortDefault)

private var devices: [MTDevice] = []
private var wakeObserver: NSObjectProtocol?
Expand Down
2 changes: 1 addition & 1 deletion src/apps/NotificationWindow/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets:
SWIFT_OBJC_BRIDGING_HEADER: src/Bridging-Header.h
type: application
platform: macOS
deploymentTarget: 11.0
deploymentTarget: 13.0
sources:
- path: src
compilerFlags:
Expand Down
2 changes: 2 additions & 0 deletions src/apps/Services/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/*.xcodeproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.pqrs.karabiner.NotificationWindow</string>
<key>AssociatedBundleIdentifiers</key>
<array>
<string>org.pqrs.Karabiner-Elements.Settings</string>
</array>
<key>Disabled</key>
<true/>
<string>org.pqrs.service.agent.Karabiner-NotificationWindow</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.pqrs.karabiner.karabiner_console_user_server</string>
<key>AssociatedBundleIdentifiers</key>
<array>
<string>org.pqrs.Karabiner-Elements.Settings</string>
</array>
<key>Disabled</key>
<true/>
<string>org.pqrs.service.agent.karabiner_console_user_server</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.pqrs.karabiner.agent.karabiner_grabber</string>
<key>AssociatedBundleIdentifiers</key>
<array>
<string>org.pqrs.Karabiner-Elements.Settings</string>
</array>
<key>Disabled</key>
<false/>
<string>org.pqrs.service.agent.karabiner_grabber</string>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.pqrs.karabiner.karabiner_session_monitor</string>
<key>AssociatedBundleIdentifiers</key>
<array>
<string>org.pqrs.Karabiner-Elements.Settings</string>
</array>
<key>Disabled</key>
<false/>
<string>org.pqrs.service.agent.karabiner_session_monitor</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.pqrs.karabiner.karabiner_grabber</string>
<key>AssociatedBundleIdentifiers</key>
<array>
<string>org.pqrs.Karabiner-Elements.Settings</string>
</array>
<key>Disabled</key>
<false/>
<string>org.pqrs.service.daemon.karabiner.karabiner_grabber</string>
<key>KeepAlive</key>
<true/>
<key>ProcessType</key>
Expand Down
18 changes: 18 additions & 0 deletions src/apps/Services/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
all:
python3 ../../../scripts/update_version.py
xcodegen generate
xcodebuild -configuration Release -alltargets SYMROOT="$(CURDIR)/build"
# Copy LaunchAgents
mkdir -p build/Release/Karabiner-Elements-Services.app/Contents/Library/LaunchAgents
cp LaunchAgents/*.plist build/Release/Karabiner-Elements-Services.app/Contents/Library/LaunchAgents
# Copy LaunchDaemons
mkdir -p build/Release/Karabiner-Elements-Services.app/Contents/Library/LaunchDaemons
cp ../../vendor/Karabiner-DriverKit-VirtualHIDDevice/files/LaunchDaemons/*.plist build/Release/Karabiner-Elements-Services.app/Contents/Library/LaunchDaemons
cp LaunchDaemons/*.plist build/Release/Karabiner-Elements-Services.app/Contents/Library/LaunchDaemons

clean:
rm -rf *.xcodeproj
rm -rf build

xcode:
open *.xcodeproj
1 change: 1 addition & 0 deletions src/apps/Services/Resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Info.plist
30 changes: 30 additions & 0 deletions src/apps/Services/Resources/Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string>app.icns</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>@VERSION@</string>
<key>CFBundleVersion</key>
<string>@VERSION@</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2024 Takayama Fumihiko. All rights reserved.</string>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
24 changes: 24 additions & 0 deletions src/apps/Services/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Karabiner-Elements-Services

targets:
Karabiner-Elements-Services:
settings:
PRODUCT_BUNDLE_IDENTIFIER: org.pqrs.Karabiner-Elements-Services
# SMAppService requires codesigning
CODE_SIGN_ENTITLEMENTS: ''
CODE_SIGN_IDENTITY: 'Apple Development'
CODE_SIGN_STYLE: Automatic
# Sign to Run Locally
CODE_SIGN_IDENTITY[sdk=macosx*]: '-'
OTHER_SWIFT_FLAGS: '-warnings-as-errors'
type: application
platform: macOS
deploymentTarget: 13.0
sources:
- path: src
- path: Resources
excludes:
- Info.plist.in
- path: ../share/Resources/app.icns
dependencies:
- sdk: ServiceManagement.framework
Loading

0 comments on commit 07643e2

Please sign in to comment.