macoc/Taskfile.yml

134 lines
5.5 KiB
YAML

version: '3'
vars:
APP_NAME: Capswitch
APP_DIR: build/Capswitch.app
RELEASE_BINARY: .build/release/Capswitch
tasks:
default:
cmds:
- task: verify
test:
desc: Run XCTest on macOS, or report the host limitation on Linux
cmds:
- |
if command -v swift >/dev/null 2>&1 && [ "$(uname -s)" = "Darwin" ]; then
swift test
else
echo "SKIP: Swift/XCTest requires macOS with Command Line Tools"
fi
build:
desc: Build the macOS executable with SwiftPM
cmds:
- |
if [ "$(uname -s)" != "Darwin" ]; then
echo "SKIP: macOS build requires Darwin with Command Line Tools"
exit 0
fi
swift build -c release
bundle:
desc: Assemble and ad-hoc sign the menu-bar .app
deps: [build]
cmds:
- |
if [ "$(uname -s)" != "Darwin" ]; then
echo "SKIP: macOS app bundle requires Darwin with Command Line Tools"
exit 0
fi
if pgrep -x Capswitch >/dev/null 2>&1; then
echo "ERROR: Quit running Capswitch from its menu before rebuilding." >&2
exit 1
fi
rm -rf "{{.APP_DIR}}"
mkdir -p "{{.APP_DIR}}/Contents/MacOS" "{{.APP_DIR}}/Contents/Resources"
cp "{{.RELEASE_BINARY}}" "{{.APP_DIR}}/Contents/MacOS/{{.APP_NAME}}"
cp Resources/Info.plist "{{.APP_DIR}}/Contents/Info.plist"
codesign --force --sign - "{{.APP_DIR}}"
lint:
desc: Run host-independent source and bundle checks
cmds:
- git diff --check
- test -f Package.swift
- test -f Resources/Info.plist
- test -f Sources/Capswitch/CapsGestureMachine.swift
- test -f Sources/CapswitchApp/MacOSInputController.swift
- grep -q "LSUIElement" Resources/Info.plist
- grep -q "CGEventType.keyDown" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CGEventType.keyUp" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "keyboardEventKeycode" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CapsInputRouter.f19VirtualKeyCode" Sources/CapswitchApp/MacOSInputController.swift
- test -f Sources/CapswitchApp/HIDRemappingController.swift
- test -f Sources/Capswitch/HIDMapping.swift
- test -f Sources/CapswitchHID/CapswitchHID.c
- test -f Tests/CapswitchCoreTests/CapsInputRouterTests.swift
- test -f Tests/CapswitchCoreTests/HIDMappingCodecTests.swift
- grep -q "CGEvent.tapCreate" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CGEvent.tapEnable" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CGPreflightListenEventAccess" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CGRequestListenEventAccess" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CGEvent.tapIsEnabled" Sources/CapswitchApp/MacOSInputController.swift
- test "$(grep -c "CGEventTapCreate" Sources/CapswitchApp/MacOSInputController.swift || true)" -eq 0
- test "$(grep -c "CGEventTapEnable" Sources/CapswitchApp/MacOSInputController.swift || true)" -eq 0
- grep -q "TISSelectInputSource" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "switchToNextInputSource" Sources/Capswitch/CapsGestureMachine.swift
doctor:
desc: Inspect macOS Caps preferences, remapping and running Capswitch processes
cmds:
- |
if [ "$(uname -s)" != "Darwin" ]; then
echo "SKIP: HID diagnostics require macOS."
exit 0
fi
echo "=== macOS ==="
sw_vers
echo "=== Native Caps input-source setting (1=enabled, 0=disabled) ==="
defaults read -g TISRomanSwitchState 2>/dev/null || true
defaults read com.apple.HIToolbox TISRomanSwitchState 2>/dev/null || true
echo "=== Global HID remappings ==="
mapping="$(hidutil property --get UserKeyMapping 2>&1)" || {
echo "$mapping"
echo "ERROR: hidutil could not read UserKeyMapping." >&2
exit 1
}
echo "$mapping"
echo "=== HID keyboard services (may vary by keyboard) ==="
hidutil property --matching '{"PrimaryUsagePage":1,"PrimaryUsage":6}' --get UserKeyMapping || true
echo "=== Running Capswitch processes ==="
pgrep -fl Capswitch || true
echo "=== Diagnosis ==="
case "$mapping" in
*"(null)"* | *"()"*)
echo "NO HID REMAP ACTIVE: physical Caps cannot arrive as F19."
echo "Capswitch can be running without a working event tap or remap."
echo "Check Capswitch menu: Accessibility, Event tap, HID and Error."
echo "On Sonoma, /usr/bin/hidutil may need its OWN Input Monitoring approval."
echo "Grant it via Privacy & Security -> Input Monitoring -> + -> Cmd+Shift+G -> /usr/bin/hidutil."
echo "That is separate from permission for Capswitch.app."
;;
*"HIDKeyboardModifierMappingSrc"*)
echo "Mapping entries exist. Verify Caps -> F19 in the output above."
;;
*)
echo "Unrecognized mapping output. Check the raw values above."
;;
esac
echo "=== Privacy permissions ==="
echo "The terminal cannot verify the running app's TCC status."
echo "Inspect Accessibility / Input Monitoring / Event tap / Error in its menu."
clean:
desc: Remove build outputs
cmds:
- rm -rf build .build
verify:
desc: Run all checks available on the current host
cmds:
- task: lint
- task: test