diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 09317f7..7eac934 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,8 @@ jobs: with: xcode-version: latest-stable - - name: Build archive (ad-hoc signed) + # Built ad-hoc, then re-signed with the release certificate by scripts/sign-app.sh. + - name: Build archive run: | xcodebuild -scheme WindowLatch \ -configuration Release \ @@ -34,6 +35,25 @@ jobs: -exportPath build/export \ -exportOptionsPlist scripts/exportOptions.plist + - name: Import signing certificate + env: + P12_BASE64: ${{ secrets.MACOS_SIGNING_P12_BASE64 }} + P12_PASSWORD: ${{ secrets.MACOS_SIGNING_P12_PASSWORD }} + run: | + keychain="$RUNNER_TEMP/signing.keychain-db" + keychain_password="$(openssl rand -hex 16)" + echo "$P12_BASE64" | base64 --decode > "$RUNNER_TEMP/signing.p12" + security create-keychain -p "$keychain_password" "$keychain" + security set-keychain-settings "$keychain" + security unlock-keychain -p "$keychain_password" "$keychain" + security import "$RUNNER_TEMP/signing.p12" -k "$keychain" -P "$P12_PASSWORD" -T /usr/bin/codesign + security set-key-partition-list -S apple-tool:,apple: -k "$keychain_password" "$keychain" > /dev/null + rm "$RUNNER_TEMP/signing.p12" + echo "SIGNING_KEYCHAIN=$keychain" >> "$GITHUB_ENV" + + - name: Sign .app with the release certificate + run: scripts/sign-app.sh build/export/WindowLatch.app + - name: Create .dmg run: | brew install create-dmg diff --git a/README.md b/README.md index 7ca623c..3253a2c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ The modifier is reconfigurable in Settings (Ctrl+Option, Ctrl+Cmd, Cmd+Option, o 1. Download `WindowLatch-vX.Y.Z.dmg` from [Releases](https://github.com/fabiomsnunes/WindowLatch/releases/latest). 2. Open the `.dmg` and drag **WindowLatch** to `/Applications`. -3. **First launch.** The build is ad-hoc signed (not notarised), so Gatekeeper blocks it. On macOS 15 and later the old right-click → Open trick no longer works — use the steps below: +3. **First launch.** The build is signed with WindowLatch's own certificate but not notarised by Apple, so Gatekeeper blocks it. On macOS 15 and later the old right-click → Open trick no longer works — use the steps below: 1. Double-click **WindowLatch**. macOS shows _"Apple could not verify 'WindowLatch' is free of malware…"_ — click **Done** (the app does not open yet). 2. Open **System Settings → Privacy & Security** and scroll down. You'll see _"WindowLatch was blocked to protect your Mac."_ — click **Open Anyway**. 3. Authenticate with Touch ID or your password, then click **Open Anyway** in the final confirmation dialog. @@ -60,13 +60,13 @@ WindowLatch is a **menu-bar app** — once running, look for its icon in the men ### Verify the download (optional) -The release is built by [GitHub Actions](.github/workflows/release.yml) straight from a tagged commit — no manual upload. To confirm the `.app` is the unmodified ad-hoc build: +The release is built by [GitHub Actions](.github/workflows/release.yml) straight from a tagged commit — no manual upload. To confirm the `.app` is the unmodified release build: ```bash codesign --verify --deep --strict --verbose=2 /Applications/WindowLatch.app # expected: "valid on disk" and "satisfies its Designated Requirement" -codesign -dvv /Applications/WindowLatch.app 2>&1 | grep -E 'Identifier|Signature' -# expected: Identifier=com.fabiomsnunes.WindowLatch, Signature=adhoc +codesign -d -r- /Applications/WindowLatch.app 2>&1 | grep designated +# expected: certificate leaf = H"6677765cd4bd5c85108b1b925e74fa3039e12a27" ``` ### Build from source @@ -88,6 +88,8 @@ On first launch the onboarding screen explains this and links to the right pane: **System Settings → Privacy & Security → Accessibility → toggle WindowLatch on.** +You grant it once. Every release is signed with the same certificate, so macOS keeps the permission when you update. (Releases up to 1.0.2 were ad-hoc signed and asked again after each update; the first update from 1.0.2 asks one last time.) + The app detects the change automatically — no restart needed. ## Roadmap @@ -133,8 +135,8 @@ No. There is no network code in the app. **Will it work on macOS 15 or earlier?** Not in this release. The deployment target is macOS 26 (Tahoe). Backporting is possible but not planned. -**Why ad-hoc signed instead of notarised?** -Apple Developer notarisation costs €99/year for a personal-use, free app. Ad-hoc signing means one extra Gatekeeper click on first launch, then it's invisible. +**Why self-signed instead of notarised?** +Apple Developer notarisation costs €99/year for a personal-use, free app. A self-signed certificate means one extra Gatekeeper click on first launch, then it's invisible, and the Accessibility permission carries over between updates. ## License diff --git a/WindowLatch/Core/AccessibilityClient.swift b/WindowLatch/Core/AccessibilityClient.swift index f0b43ce..45c5a4f 100644 --- a/WindowLatch/Core/AccessibilityClient.swift +++ b/WindowLatch/Core/AccessibilityClient.swift @@ -14,7 +14,9 @@ enum AccessibilityClient { /// registers the app in the Accessibility pane and is correct on the happy /// path — but fall back to a live AX read, which reflects the real grant. static func isTrusted() -> Bool { - if AXIsProcessTrusted() { return true } + if AXIsProcessTrusted() { + return true + } let systemWide = AXUIElementCreateSystemWide() var ref: CFTypeRef? diff --git a/WindowLatch/Core/ScreenManager.swift b/WindowLatch/Core/ScreenManager.swift index 489dc95..b42165a 100644 --- a/WindowLatch/Core/ScreenManager.swift +++ b/WindowLatch/Core/ScreenManager.swift @@ -82,7 +82,9 @@ final class ScreenManager { func screen(forFocusedWindow window: AXUIElement) -> ScreenInfo? { if let frame = AccessibilityClient.frame(of: window) { let mid = CGPoint(x: frame.midX, y: frame.midY) // AX coords - if let s = screen(containingAXPoint: mid) { return s } + if let s = screen(containingAXPoint: mid) { + return s + } } return screenUnderCursor() ?? primary } diff --git a/WindowLatch/Cycle/CycleEngine.swift b/WindowLatch/Cycle/CycleEngine.swift index f11290a..449a917 100644 --- a/WindowLatch/Cycle/CycleEngine.swift +++ b/WindowLatch/Cycle/CycleEngine.swift @@ -133,24 +133,22 @@ nonisolated struct CycleEngine { let next = directionSequence[idx + 1] let newState = CycleState(lastDirection: input.direction, lastZone: next, lastTimestamp: input.now) return (.apply(next, on: .current), newState) + } else if input.hasNeighbour { + let entry = crossMonitorEntry(input.direction) + let newState = CycleState( + lastDirection: input.direction, + lastZone: entry, + lastTimestamp: input.now, + lastJumpDirection: input.direction + ) + return (.apply(entry, on: .neighbour), newState) } else { - if input.hasNeighbour { - let entry = crossMonitorEntry(input.direction) - let newState = CycleState( - lastDirection: input.direction, - lastZone: entry, - lastTimestamp: input.now, - lastJumpDirection: input.direction - ) - return (.apply(entry, on: .neighbour), newState) - } else { - let newState = CycleState( - lastDirection: input.direction, - lastZone: input.state.lastZone, - lastTimestamp: input.now - ) - return (.noOp, newState) - } + let newState = CycleState( + lastDirection: input.direction, + lastZone: input.state.lastZone, + lastTimestamp: input.now + ) + return (.noOp, newState) } } diff --git a/WindowLatch/Zones/ZoneGroup.swift b/WindowLatch/Zones/ZoneGroup.swift index caaa18f..1e38d45 100644 --- a/WindowLatch/Zones/ZoneGroup.swift +++ b/WindowLatch/Zones/ZoneGroup.swift @@ -60,9 +60,15 @@ nonisolated enum ZoneGroup: String, CaseIterable, Codable, Identifiable { } var seq: [Zone] = [] - if hasThirds { seq.append(twoThirds) } - if hasHalves { seq.append(half) } - if hasThirds { seq.append(third) } + if hasThirds { + seq.append(twoThirds) + } + if hasHalves { + seq.append(half) + } + if hasThirds { + seq.append(third) + } return seq } } diff --git a/WindowLatch/Zones/ZoneStore.swift b/WindowLatch/Zones/ZoneStore.swift index 724c1fa..88e48c8 100644 --- a/WindowLatch/Zones/ZoneStore.swift +++ b/WindowLatch/Zones/ZoneStore.swift @@ -72,7 +72,9 @@ final class ZoneStore { let decoded = try JSONDecoder().decode(Persisted.self, from: data) var out: [CGDirectDisplayID: Set] = [:] for (k, v) in decoded.groups { - if let id = UInt32(k) { out[id] = Set(v) } + if let id = UInt32(k) { + out[id] = Set(v) + } } return out } catch { diff --git a/scripts/sign-app.sh b/scripts/sign-app.sh new file mode 100755 index 0000000..89ad91a --- /dev/null +++ b/scripts/sign-app.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# Signs WindowLatch.app with the stable self-signed "WindowLatch Release" certificate. +# +# macOS ties the Accessibility grant to the app's designated requirement. An ad-hoc +# signature makes that requirement the binary's own hash, so every new build looks like +# a different app and users have to grant Accessibility again. Signing every release +# with the same certificate pins the requirement to the certificate instead, and the +# grant survives updates. Changing the certificate breaks that for every user, which is +# why its fingerprint is pinned here and checked after signing. +# +# Usage: SIGNING_KEYCHAIN= scripts/sign-app.sh +set -euo pipefail + +readonly CERT_SHA1="6677765CD4BD5C85108B1B925E74FA3039E12A27" +readonly APP="${1:?usage: sign-app.sh }" +readonly KEYCHAIN="${SIGNING_KEYCHAIN:?SIGNING_KEYCHAIN must point to the keychain holding the certificate}" + +sign() { + codesign --force --options runtime --timestamp=none \ + --preserve-metadata=entitlements \ + --keychain "$KEYCHAIN" --sign "$CERT_SHA1" "$1" +} + +# Nested code first (find -depth lists children before their parent): a bundle's +# signature covers what it contains, so it has to be signed last. +while IFS= read -r nested; do + sign "$nested" +done < <( + find "$APP/Contents" -depth \( -name '*.framework' -o -name '*.xpc' -o -name '*.app' -o -name '*.dylib' \) -print +) +sign "$APP" + +codesign --verify --deep --strict --verbose=2 "$APP" + +requirement="$(codesign -d -r- "$APP" 2>&1)" +expected="certificate leaf = H\"$(tr '[:upper:]' '[:lower:]' <<<"$CERT_SHA1")\"" +if [[ "$requirement" != *"$expected"* ]]; then + echo "Designated requirement is not pinned to the release certificate:" >&2 + echo "$requirement" >&2 + exit 1 +fi +echo "Signed with WindowLatch Release ($CERT_SHA1)"