Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

build(desktop): sign Andee.app with one fixed local identity

booboosuidd56e62938ad
diff --git a/desktop/README-signing.md b/desktop/README-signing.md
new file mode 100644
index 0000000..556b739
--- /dev/null
+++ b/desktop/README-signing.md
@@ -0,0 +1,48 @@
+# Signing the Mac app
+
+macOS remembers Accessibility and Screen Recording against an app's code
+signature. An ad-hoc signed `Andee.app` is a new app on every build, so every
+grant lapses after each rebuild (the switch in System Settings still shows *on*
+for the old build). Signing with one fixed identity keeps grants across builds.
+
+Only the person who **packages** Andee needs this. Anyone who just uses the
+built `Andee.app` needs nothing.
+
+## What is set up
+
+- `~/Andee-signing/andee.p12` — a self-signed code-signing certificate,
+ "Andee Local Signing" (10 years). **Back this file up**: a new certificate is
+ a new app to macOS, and every user would have to grant permissions again.
+- `~/Library/Keychains/andee-signing.keychain-db` — a keychain holding only
+ that identity, unlocked by `~/Andee-signing/keychain-password`, so builds
+ sign without a password prompt.
+- `./gradlew :desktop:createDistributable` runs `signApp` after packaging. With
+ no such keychain it skips signing and the app stays ad-hoc.
+
+Override with `-Pandee.signing.identity=…` / `-Pandee.signing.keychain=…`
+(e.g. a real "Developer ID Application" identity later).
+
+## On a new packaging machine
+
+```sh
+mkdir -p ~/Andee-signing && cp andee.p12 ~/Andee-signing/ # the backed-up file
+cd ~/Andee-signing
+PW=$(openssl rand -hex 16); echo -n "$PW" > keychain-password; chmod 600 keychain-password
+KC=~/Library/Keychains/andee-signing.keychain-db
+security create-keychain -p "$PW" $KC
+security set-keychain-settings $KC
+security unlock-keychain -p "$PW" $KC
+security import andee.p12 -k $KC -P andee -T /usr/bin/codesign
+security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$PW" $KC
+security list-keychains -d user -s $(security list-keychains -d user | tr -d '"') $KC
+```
+
+## What users see
+
+The certificate is not from Apple, so Gatekeeper still blocks the first open of
+a downloaded copy: right-click Andee → Open, or System Settings → Privacy &
+Security → Open Anyway. Once. After that, and after every update signed with
+the same certificate, Accessibility and Screen Recording stay granted.
+
+Removing that first-open step needs an Apple Developer ID ($99/year) and
+notarization; pass its identity with `-Pandee.signing.identity`.
diff --git a/desktop/build.gradle b/desktop/build.gradle
index ff035c9..6c80077 100644
--- a/desktop/build.gradle
+++ b/desktop/build.gradle
@@ -111,3 +111,34 @@ tasks.register('ballshot', JavaExec) {
mainClass = 'net.kuafuai.andee.desktop.BallShotKt'
}
+// One fixed signing identity, so macOS keeps Accessibility and Screen Recording
+// across rebuilds: an ad-hoc signature is a new app every build, and every grant
+// silently lapses. Signed here with codesign rather than through Compose's own
+// signing, which only accepts Apple "Developer ID Application" names.
+//
+// The identity is the packager's alone (see desktop/README-signing.md); users of
+// the built app never need it. Without it the app stays ad-hoc and still builds.
+def signIdentity = providers.gradleProperty('andee.signing.identity').orElse('Andee Local Signing')
+def signKeychain = providers.gradleProperty('andee.signing.keychain')
+ .orElse("${System.getProperty('user.home')}/Library/Keychains/andee-signing.keychain-db")
+def signPasswordFile = file("${System.getProperty('user.home')}/Andee-signing/keychain-password")
+
+tasks.register('signApp') {
+ def app = layout.buildDirectory.dir('compose/binaries/main/app/Andee.app')
+ def entitlements = file('entitlements.plist')
+ onlyIf { file(signKeychain.get()).exists() }
+ doLast {
+ def kc = signKeychain.get()
+ if (signPasswordFile.exists()) {
+ exec { commandLine 'security', 'unlock-keychain', '-p', signPasswordFile.text.trim(), kc }
+ }
+ exec {
+ commandLine 'codesign', '--force', '--deep', '--options', 'runtime', '--timestamp=none',
+ '--entitlements', entitlements.path, '--keychain', kc,
+ '--sign', signIdentity.get(), app.get().asFile.path
+ }
+ exec { commandLine 'codesign', '--verify', '--deep', '--strict', app.get().asFile.path }
+ logger.lifecycle("Andee.app signed as '${signIdentity.get()}'")
+ }
+}
+tasks.matching { it.name == 'createDistributable' }.configureEach { finalizedBy('signApp') }