From 6b5147b98cef9602ce56c5a3e44ff7dfbb317a5e Mon Sep 17 00:00:00 2001 From: fabiomsnunes Date: Tue, 17 Nov 2026 16:28:20 +0000 Subject: [PATCH 1/7] build(release): sign with a stable self-signed certificate Ad-hoc signing pins the designated requirement to the binary's hash, so macOS treats every release as a new app and users have to grant Accessibility again after each update. Re-sign the exported app with the 'WindowLatch Release' certificate, whose fingerprint scripts/sign-app.sh pins and checks, so the requirement and the grant survive updates. --- .github/workflows/release.yml | 22 +++++++++++++++++- README.md | 14 +++++++----- scripts/sign-app.sh | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 7 deletions(-) create mode 100755 scripts/sign-app.sh 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/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)" From 6ebab91aa559e3957a530187876e7d69a89e56e1 Mon Sep 17 00:00:00 2001 From: fabiomsnunes Date: Tue, 17 Nov 2026 17:10:17 +0000 Subject: [PATCH 2/7] style: apply SwiftFormat 0.64 wrapIfStatementBodies CI installs the latest SwiftFormat, whose new rule has failed the lint on main since 2026-11-10. Formatting only, no behaviour change. --- WindowLatch/Core/AccessibilityClient.swift | 4 ++- WindowLatch/Core/ScreenManager.swift | 4 ++- WindowLatch/Cycle/CycleEngine.swift | 32 ++++++++++------------ WindowLatch/Zones/ZoneGroup.swift | 12 ++++++-- WindowLatch/Zones/ZoneStore.swift | 4 ++- 5 files changed, 33 insertions(+), 23 deletions(-) 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 { From e0a688633c9f3d348b5ea53f21fd97aea24deabd Mon Sep 17 00:00:00 2001 From: fabiomsnunes Date: Tue, 17 Nov 2026 16:33:26 +0000 Subject: [PATCH 3/7] feat(updates): auto-update with Sparkle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Sparkle 2 with a 'Check for Updates…' menu item. The release workflow signs the .dmg with the EdDSA key (SPARKLE_ED_PRIVATE_KEY) and publishes a one-item appcast.xml next to it, so SUFeedURL can point at releases/latest/download/appcast.xml. sign-app.sh now also signs the Autoupdate helper, which has no bundle extension. --- .github/workflows/release.yml | 23 +++++++++++++- README.md | 13 +++++--- Support/WindowLatch-Info.plist | 10 ++++++ WindowLatch.xcodeproj/project.pbxproj | 19 +++++++++++ WindowLatch/App/AppDelegate.swift | 15 +++++++++ scripts/make-appcast.sh | 45 +++++++++++++++++++++++++++ scripts/sign-app.sh | 6 ++-- 7 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 Support/WindowLatch-Info.plist create mode 100755 scripts/make-appcast.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7eac934..59030e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,9 +65,30 @@ jobs: "build/WindowLatch-${GITHUB_REF_NAME}.dmg" \ build/export/WindowLatch.app + - name: Create Sparkle appcast + env: + SPARKLE_VERSION: 2.10.1 + SPARKLE_SHA256: 1a856d2a9edb8e628de88121d7be04cf0e2167f8641650b78fca00b14244cf27 + SPARKLE_ED_PRIVATE_KEY: ${{ secrets.SPARKLE_ED_PRIVATE_KEY }} + run: | + sparkle="$RUNNER_TEMP/sparkle" + mkdir -p "$sparkle" + curl -fsSL -o "$sparkle/sparkle.tar.xz" \ + "https://github.com/sparkle-project/Sparkle/releases/download/$SPARKLE_VERSION/Sparkle-$SPARKLE_VERSION.tar.xz" + echo "$SPARKLE_SHA256 $sparkle/sparkle.tar.xz" | shasum -a 256 -c - + tar -xf "$sparkle/sparkle.tar.xz" -C "$sparkle" + key_file="$RUNNER_TEMP/sparkle_ed_key" + printf '%s' "$SPARKLE_ED_PRIVATE_KEY" > "$key_file" + SPARKLE_BIN="$sparkle/bin" SPARKLE_ED_KEY_FILE="$key_file" scripts/make-appcast.sh \ + "$GITHUB_REF_NAME" build/export/WindowLatch.app \ + "build/WindowLatch-${GITHUB_REF_NAME}.dmg" build/appcast.xml + rm "$key_file" + - name: Publish GitHub Release uses: softprops/action-gh-release@v2 with: - files: build/WindowLatch-*.dmg + files: | + build/WindowLatch-*.dmg + build/appcast.xml draft: false generate_release_notes: true diff --git a/README.md b/README.md index 3253a2c..a1a8e3e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Platform: macOS 26+](https://img.shields.io/badge/platform-macOS%2026%2B-lightgrey.svg)](#install) [![Built with Swift 6](https://img.shields.io/badge/swift-6-orange.svg)](https://swift.org) -**A fast, focused window manager for macOS.** [**⬇ Download the latest `.dmg`**](https://github.com/fabiomsnunes/WindowLatch/releases/latest) — ~400 KB, no installer, no account. +**A fast, focused window manager for macOS.** [**⬇ Download the latest `.dmg`**](https://github.com/fabiomsnunes/WindowLatch/releases/latest) — ~2 MB, no installer, no account. Cycle the focused window through ⅔ → ½ → ⅓ zones with one keyboard shortcut per direction. Combine directions for quadrants. Jump across monitors when you run out of room. Inspired by Microsoft PowerToys' **FancyZones**. @@ -15,7 +15,8 @@ Cycle the focused window through ⅔ → ½ → ⅓ zones with one keyboard shor - **It works across monitors.** When the cycle exhausts, the window leaps to the next display. Press the opposite arrow within 1.5 s to snap straight back. - **It does directional combos.** `⌃⌥ ←` then `⌃⌥ ↑` = top-left quadrant. No extra keys to memorise. - **It respects each monitor.** Configure halves / thirds / quarters independently per display — your ultrawide and your 4K don't have to agree. -- **It's a 400 KB download.** Native Swift + AppKit. No Electron, no background daemons, no analytics. +- **It's a 2 MB download.** Native Swift + AppKit. No Electron, no background daemons, no analytics. +- **It updates itself.** New versions install from the menu bar, and the Accessibility permission carries over. - **It's MIT-licensed and open source.** Read the code. Fork it. ![WindowLatch — four windows snapped into a clean grid on a macOS desktop](assets/hero.jpg) @@ -41,6 +42,7 @@ The modifier is reconfigurable in Settings (Ctrl+Option, Ctrl+Cmd, Cmd+Option, o - **Per-monitor zone configuration:** enable/disable halves, thirds, and quarters independently per display. - **Configurable** gap, cycle reset delay, and modifier key. - **Menu-bar app** — no Dock clutter. +- **Auto-update:** checks GitHub Releases for new versions (after asking you once), or on demand with **Check for Updates…** in the menu. ## Install @@ -109,6 +111,7 @@ Have an idea? [Open an issue](https://github.com/fabiomsnunes/WindowLatch/issues - **Swift 6** + **SwiftUI** (Settings) + **AppKit** (menu bar, windows) - **Accessibility API** for window manipulation - [**KeyboardShortcuts**](https://github.com/sindresorhus/KeyboardShortcuts) by Sindre Sorhus for global hotkeys +- [**Sparkle**](https://sparkle-project.org) for updates, verified with an EdDSA signature on every release - Pure `CycleEngine` state machine — fully unit-tested, no AX or `Date.now` dependency - `ScreenAdjacency` is a pure helper — also unit-tested - Hybrid persistence: UserDefaults (gap, delay, modifier) + JSON (per-monitor zone groups) @@ -124,13 +127,15 @@ xcodebuild test -scheme WindowLatch -destination 'platform=macOS' -only-testing: CI runs SwiftFormat lint on every PR. Tests must pass locally before cutting a release tag. +To cut a release, bump both `MARKETING_VERSION` and `CURRENT_PROJECT_VERSION` (Sparkle compares the build number), then push a `vX.Y.Z` tag matching `MARKETING_VERSION`. The release workflow signs the app, builds the `.dmg` and publishes it with its `appcast.xml`. + ## FAQ **How is this different from Rectangle, Magnet, or Moom?** The cycle behaviour. WindowLatch presses the same arrow repeatedly to step through `⅔ → ½ → ⅓` — Rectangle and Magnet require separate shortcuts for each size, Moom needs you to open a palette. WindowLatch also auto-jumps to the next monitor when the cycle exhausts, which none of them do natively. **Does it phone home?** -No. There is no network code in the app. +Only to look for updates. On second launch it asks whether to check automatically; if you say yes, it fetches `appcast.xml` from this repo's GitHub Releases about once a day. Sparkle sends nothing else: no analytics, no system profile. Say no, and it only checks when you pick **Check for Updates…**. **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. @@ -144,4 +149,4 @@ Apple Developer notarisation costs €99/year for a personal-use, free app. A se ## Acknowledgements -Inspired by Microsoft PowerToys **FancyZones**. Built on top of Sindre Sorhus's **KeyboardShortcuts**. +Inspired by Microsoft PowerToys **FancyZones**. Built on top of Sindre Sorhus's **KeyboardShortcuts** and **Sparkle**. diff --git a/Support/WindowLatch-Info.plist b/Support/WindowLatch-Info.plist new file mode 100644 index 0000000..e782f5e --- /dev/null +++ b/Support/WindowLatch-Info.plist @@ -0,0 +1,10 @@ + + + + + SUFeedURL + https://github.com/fabiomsnunes/WindowLatch/releases/latest/download/appcast.xml + SUPublicEDKey + CIK7T5aopcPLmyaFooZGAaTVS9fQoTUfJIZW8+HlCJg= + + diff --git a/WindowLatch.xcodeproj/project.pbxproj b/WindowLatch.xcodeproj/project.pbxproj index c57d86d..a89e7c4 100644 --- a/WindowLatch.xcodeproj/project.pbxproj +++ b/WindowLatch.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ BD514AC02FAF78C800E3D6C5 /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = BD514A8B2FAF779400E3D6C6 /* KeyboardShortcuts */; }; + BD514AC12FAF78C800E3D6C5 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = BD514AC32FAF78C800E3D6C5 /* Sparkle */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -57,6 +58,7 @@ buildActionMask = 2147483647; files = ( BD514AC02FAF78C800E3D6C5 /* KeyboardShortcuts in Frameworks */, + BD514AC12FAF78C800E3D6C5 /* Sparkle in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -118,6 +120,7 @@ name = WindowLatch; packageProductDependencies = ( BD514A8B2FAF779400E3D6C6 /* KeyboardShortcuts */, + BD514AC32FAF78C800E3D6C5 /* Sparkle */, ); productName = WindowLatch; productReference = BD35746F2FAD145A00AFC5DB /* WindowLatch.app */; @@ -203,6 +206,7 @@ minimizedProjectReferenceProxies = 1; packageReferences = ( BD514A8A2FAF779400E3D6C5 /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */, + BD514AC22FAF78C800E3D6C5 /* XCRemoteSwiftPackageReference "Sparkle" */, ); preferredProjectObjectVersion = 77; productRefGroup = BD3574702FAD145A00AFC5DB /* Products */; @@ -409,6 +413,7 @@ ENABLE_PREVIEWS = YES; ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = Support/WindowLatch-Info.plist; INFOPLIST_KEY_LSUIElement = YES; INFOPLIST_KEY_NSAccessibilityUsageDescription = "WindowLatch uses Accessibility to read window positions and move/resize windows when you trigger a snap or shortcut."; INFOPLIST_KEY_NSHumanReadableCopyright = ""; @@ -441,6 +446,7 @@ ENABLE_PREVIEWS = YES; ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = Support/WindowLatch-Info.plist; INFOPLIST_KEY_LSUIElement = YES; INFOPLIST_KEY_NSAccessibilityUsageDescription = "WindowLatch uses Accessibility to read window positions and move/resize windows when you trigger a snap or shortcut."; INFOPLIST_KEY_NSHumanReadableCopyright = ""; @@ -587,6 +593,14 @@ minimumVersion = 2.0.0; }; }; + BD514AC22FAF78C800E3D6C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sparkle-project/Sparkle"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.10.1; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -595,6 +609,11 @@ package = BD514A8A2FAF779400E3D6C5 /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */; productName = KeyboardShortcuts; }; + BD514AC32FAF78C800E3D6C5 /* Sparkle */ = { + isa = XCSwiftPackageProductDependency; + package = BD514AC22FAF78C800E3D6C5 /* XCRemoteSwiftPackageReference "Sparkle" */; + productName = Sparkle; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = BD3574672FAD145A00AFC5DB /* Project object */; diff --git a/WindowLatch/App/AppDelegate.swift b/WindowLatch/App/AppDelegate.swift index 35ed956..6985d12 100644 --- a/WindowLatch/App/AppDelegate.swift +++ b/WindowLatch/App/AppDelegate.swift @@ -1,5 +1,6 @@ import AppKit import KeyboardShortcuts +import Sparkle import SwiftUI final class AppDelegate: NSObject, NSApplicationDelegate { @@ -7,6 +8,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate { private var onboardingController: OnboardingWindowController? private var settingsController: SettingsWindowController? private let cycleCoordinator = CycleCoordinator(settings: .shared, zones: .shared) + /// Reads the feed and public key from Info.plist (SUFeedURL, SUPublicEDKey). + private let updaterController = SPUStandardUpdaterController( + startingUpdater: true, + updaterDelegate: nil, + userDriverDelegate: nil + ) let permissions = PermissionsManager() func applicationDidFinishLaunching(_: Notification) { @@ -77,6 +84,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate { settingsItem.target = self menu.addItem(settingsItem) + let updatesItem = NSMenuItem( + title: "Check for Updates…", + action: #selector(SPUStandardUpdaterController.checkForUpdates(_:)), + keyEquivalent: "" + ) + updatesItem.target = updaterController + menu.addItem(updatesItem) + menu.addItem(.separator()) let quitItem = NSMenuItem( diff --git a/scripts/make-appcast.sh b/scripts/make-appcast.sh new file mode 100755 index 0000000..12c8b04 --- /dev/null +++ b/scripts/make-appcast.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Writes the Sparkle appcast for one release: a feed with a single item pointing at the +# release's .dmg, signed with the EdDSA key whose public half is SUPublicEDKey. +# +# The feed is published as a release asset, so SUFeedURL +# (releases/latest/download/appcast.xml) always serves the newest release's feed. +# +# Usage: SPARKLE_BIN= SPARKLE_ED_KEY_FILE= \ +# scripts/make-appcast.sh +set -euo pipefail + +readonly TAG="${1:?tag}" APP="${2:?app}" DMG="${3:?dmg}" OUT="${4:?output}" +readonly REPO_URL="https://github.com/fabiomsnunes/WindowLatch" + +plist() { /usr/libexec/PlistBuddy -c "Print :$1" "$APP/Contents/Info.plist"; } + +bundle_version="$(plist CFBundleVersion)" +short_version="$(plist CFBundleShortVersionString)" +minimum_system="$(plist LSMinimumSystemVersion)" +if [[ "v$short_version" != "$TAG" ]]; then + echo "Tag $TAG does not match the app version $short_version" >&2 + exit 1 +fi + +# Prints: sparkle:edSignature="..." length="..." +enclosure_signature="$("${SPARKLE_BIN:?}/sign_update" --ed-key-file "${SPARKLE_ED_KEY_FILE:?}" "$DMG")" + +cat > "$OUT" < + + + WindowLatch + + WindowLatch $short_version + $(LC_ALL=C date -u "+%a, %d %b %Y %H:%M:%S +0000") + $bundle_version + $short_version + $minimum_system + $REPO_URL/releases/tag/$TAG + + + + +XML +echo "Wrote $OUT for $short_version (build $bundle_version)" diff --git a/scripts/sign-app.sh b/scripts/sign-app.sh index 89ad91a..0cff6f3 100755 --- a/scripts/sign-app.sh +++ b/scripts/sign-app.sh @@ -22,11 +22,13 @@ sign() { } # 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. +# signature covers what it contains, so it has to be signed last. Autoupdate is the +# Sparkle helper executable, which has no bundle extension to match on. 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 + find "$APP/Contents" -depth \( -name '*.framework' -o -name '*.xpc' -o -name '*.app' -o -name '*.dylib' \ + -o \( -name Autoupdate -type f \) \) -print ) sign "$APP" From d194aad503197aa1c141381b415b964bb4389ad4 Mon Sep 17 00:00:00 2001 From: fabiomsnunes Date: Tue, 17 Nov 2026 17:02:30 +0000 Subject: [PATCH 4/7] fix(release): sign without the hardened runtime The hardened runtime turns on library validation, which only loads frameworks signed with the app's Apple Team ID. The self-signed certificate has no Team ID, so dyld refused the embedded Sparkle framework and the app died at launch. The hardened runtime is only needed for notarisation, which these builds skip. --- scripts/sign-app.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/sign-app.sh b/scripts/sign-app.sh index 0cff6f3..4baad05 100755 --- a/scripts/sign-app.sh +++ b/scripts/sign-app.sh @@ -15,8 +15,12 @@ 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}" +# No hardened runtime (--options runtime): it turns on library validation, which only +# loads frameworks signed with the app's Apple Team ID. A self-signed certificate has no +# Team ID, so dyld refuses the embedded Sparkle.framework and the app dies at launch. +# The hardened runtime is only required for notarisation, which these builds skip. sign() { - codesign --force --options runtime --timestamp=none \ + codesign --force --timestamp=none \ --preserve-metadata=entitlements \ --keychain "$KEYCHAIN" --sign "$CERT_SHA1" "$1" } From d820d4a0ff556383be943bf6d680170844f40349 Mon Sep 17 00:00:00 2001 From: fabiomsnunes Date: Tue, 17 Nov 2026 17:02:30 +0000 Subject: [PATCH 5/7] chore(accessibility): log AX error codes when the focused window cannot be read A failed read logged only 'No focused window', which hid whether the cause was a missing grant (-25211) or an app that does not publish its windows. --- WindowLatch/Core/AccessibilityClient.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/WindowLatch/Core/AccessibilityClient.swift b/WindowLatch/Core/AccessibilityClient.swift index 45c5a4f..f118cb8 100644 --- a/WindowLatch/Core/AccessibilityClient.swift +++ b/WindowLatch/Core/AccessibilityClient.swift @@ -1,5 +1,8 @@ import AppKit import ApplicationServices +import OSLog + +private let log = Logger(subsystem: "com.fabiomsnunes.WindowLatch", category: "accessibility") /// Thin wrapper over the AX C API. **All AX I/O lives here** — no other file should call AX* directly. /// @@ -92,7 +95,10 @@ enum AccessibilityClient { private static func copyElement(_ element: AXUIElement, _ attribute: String) -> AXUIElement? { var ref: CFTypeRef? let result = AXUIElementCopyAttributeValue(element, attribute as CFString, &ref) - guard result == .success, let ref else { return nil } + guard result == .success, let ref else { + log.debug("\(attribute, privacy: .public) unavailable: AXError \(result.rawValue, privacy: .public)") + return nil + } return (ref as! AXUIElement) } @@ -101,6 +107,7 @@ enum AccessibilityClient { var ref: CFTypeRef? let result = AXUIElementCopyAttributeValue(app, kAXWindowsAttribute as CFString, &ref) guard result == .success, let windows = ref as? [AXUIElement], !windows.isEmpty else { + log.debug("No windows listed: AXError \(result.rawValue, privacy: .public)") return nil } let main = windows.first { window in From 74acf6011eba0167c23e049523d4262706c3d218 Mon Sep 17 00:00:00 2001 From: fabiomsnunes Date: Tue, 17 Nov 2026 17:02:53 +0000 Subject: [PATCH 6/7] docs(readme): explain the one-time Accessibility reset after updating from 1.0.2 Tested 1.0.2 -> 1.1: the old ad-hoc entry stays in the list switched on, AXIsProcessTrusted reports true, but every AX read fails with -25211, so onboarding never shows and shortcuts do nothing until the entry is reset. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1a8e3e..2b6f894 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ 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.) +You grant it once. Every release is signed with the same certificate, so macOS keeps the permission when you update. **Updating from 1.0.2 or earlier:** those releases were ad-hoc signed, and macOS keeps their old Accessibility entry, which no longer matches the new signature. The toggle shows as on but shortcuts do nothing. Once, after updating, open **Settings → Reset Accessibility Permission** (or remove WindowLatch from the Accessibility list with **−** and add it again), then grant it. From then on it carries over. The app detects the change automatically — no restart needed. From 96956af173b70eef77109dcdac0095fac3f4b164 Mon Sep 17 00:00:00 2001 From: fabiomsnunes Date: Tue, 17 Nov 2026 17:07:53 +0000 Subject: [PATCH 7/7] build(release): refuse a release whose build number does not go up Sparkle compares CFBundleVersion, so a release that bumps only MARKETING_VERSION is never offered to anyone. Compare against the published appcast and fail the release instead. --- scripts/make-appcast.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/make-appcast.sh b/scripts/make-appcast.sh index 12c8b04..9af4d64 100755 --- a/scripts/make-appcast.sh +++ b/scripts/make-appcast.sh @@ -22,6 +22,17 @@ if [[ "v$short_version" != "$TAG" ]]; then exit 1 fi +# Sparkle offers an update only when the build number (CFBundleVersion) goes up, so a +# release that bumps MARKETING_VERSION alone would reach nobody. Releases before 1.1.0 +# have no appcast; then there is nothing to compare against. +if published_feed="$(curl -fsSL "$REPO_URL/releases/latest/download/appcast.xml" 2>/dev/null)"; then + published_build="$(sed -n 's:.*\(.*\).*:\1:p' <<<"$published_feed" | head -1)" + if [[ -n "$published_build" ]] && ((bundle_version <= published_build)); then + echo "CURRENT_PROJECT_VERSION ($bundle_version) must be above the published build ($published_build)" >&2 + exit 1 + fi +fi + # Prints: sparkle:edSignature="..." length="..." enclosure_signature="$("${SPARKLE_BIN:?}/sign_update" --ed-key-file "${SPARKLE_ED_KEY_FILE:?}" "$DMG")"