Open source CapCut alternative.
TypeScript
feat(app): drive Sparkle updates silently from the notch
David Le0b76f341b838
diff --git a/apps/Donkey/Sources/Donkey/SparkleUpdateController.swift b/apps/Donkey/Sources/Donkey/SparkleUpdateController.swiftindex 0f73cba1..6b386253 100644--- a/apps/Donkey/Sources/Donkey/SparkleUpdateController.swift+++ b/apps/Donkey/Sources/Donkey/SparkleUpdateController.swift@@ -9,12 +9,18 @@ protocol DonkeyUpdateChecking: AnyObject {func start()func checkForUpdatesInBackground()- func showUpdateUI()+ func installAvailableUpdate()}+/// Drives Sparkle with no windows. A background check that finds an update surfaces the notch+/// "Update Available" button; tapping it (`installAvailableUpdate`) downloads, installs, and+/// relaunches silently. Sparkle's standard update dialog is never shown.@MainActor-final class SparkleUpdateController: NSObject, DonkeyUpdateChecking, SPUUpdaterDelegate {- private var updaterController: SPUStandardUpdaterController?+final class SparkleUpdateController: NSObject, DonkeyUpdateChecking, SPUUserDriver {+ private var updater: SPUUpdater?+ /// The install decision Sparkle hands us when it finds an update. We hold it until the user+ /// taps the notch button, then answer `.install` to begin the silent download.+ private var pendingInstall: ((SPUUserUpdateChoice) -> Void)?var updateStateChanged: ((UserQueryUpdateState) -> Void)?@@ -24,53 +30,46 @@ final class SparkleUpdateController: NSObject, DonkeyUpdateChecking, SPUUpdaterD}func start() {- guard updaterController == nil else { return }+ guard updater == nil else { return }guard isSparkleConfigured else {- updateStateChanged?(- UserQueryUpdateState(- status: .unavailable,- currentVersion: currentVersion,- message: "Sparkle feed not configured"- )- )+ emit(.unavailable, message: "Sparkle feed not configured")return}- updaterController = SPUStandardUpdaterController(- startingUpdater: true,- updaterDelegate: self,- userDriverDelegate: nil+ let updater = SPUUpdater(+ hostBundle: .main,+ applicationBundle: .main,+ userDriver: self,+ delegate: nil)+ do {+ try updater.start()+ self.updater = updater+ } catch {+ emit(.unavailable, message: error.localizedDescription)+ }}func checkForUpdatesInBackground() {- guard let updaterController else {- updateStateChanged?(- UserQueryUpdateState(- status: .unavailable,- currentVersion: currentVersion,- message: "Updater unavailable"- )- )+ guard let updater else {+ emit(.unavailable, message: "Updater unavailable")return}- updateStateChanged?(- UserQueryUpdateState(- status: .checking,- currentVersion: currentVersion- )- )- updaterController.updater.checkForUpdatesInBackground()+ emit(.checking)+ updater.checkForUpdatesInBackground()}- func showUpdateUI() {- guard let updaterController else {+ /// The user tapped the notch button. Resume the update Sparkle already found and let it run to+ /// completion silently; if nothing is pending, kick a fresh background check.+ func installAvailableUpdate() {+ guard let pendingInstall else {checkForUpdatesInBackground()return}- updaterController.checkForUpdates(nil)+ self.pendingInstall = nil+ pendingInstall(.install)}private var isSparkleConfigured: Bool {@@ -80,23 +79,77 @@ final class SparkleUpdateController: NSObject, DonkeyUpdateChecking, SPUUpdaterDreturn feedURL?.isEmpty == false && publicKey?.isEmpty == false}- func updater(_ updater: SPUUpdater, didFindValidUpdate item: SUAppcastItem) {+ private func emit(+ _ status: UserQueryUpdateStatus,+ latestVersion: String? = nil,+ message: String? = nil+ ) {updateStateChanged?(UserQueryUpdateState(- status: .available,+ status: status,currentVersion: currentVersion,- latestVersion: item.displayVersionString+ latestVersion: latestVersion,+ message: message))}- func updaterDidNotFindUpdate(_ updater: SPUUpdater, error: any Error) {- updateStateChanged?(- UserQueryUpdateState(- status: .upToDate,- currentVersion: currentVersion,- message: error.localizedDescription- )- )+ // MARK: - SPUUserDriver++ func show(+ _ request: SPUUpdatePermissionRequest,+ reply: @escaping (SUUpdatePermissionResponse) -> Void+ ) {+ reply(SUUpdatePermissionResponse(automaticUpdateChecks: true, sendSystemProfile: false))+ }++ func showUserInitiatedUpdateCheck(cancellation: @escaping () -> Void) {}++ func showUpdateFound(+ with appcastItem: SUAppcastItem,+ state: SPUUserUpdateState,+ reply: @escaping (SPUUserUpdateChoice) -> Void+ ) {+ // Hold the decision and light up the notch button instead of installing immediately.+ pendingInstall = reply+ emit(.available, latestVersion: appcastItem.displayVersionString)+ }++ func showUpdateReleaseNotes(with downloadData: SPUDownloadData) {}++ func showUpdateReleaseNotesFailedToDownloadWithError(_ error: any Error) {}++ func showUpdateNotFoundWithError(_ error: any Error) async {+ emit(.upToDate, message: error.localizedDescription)+ }++ func showUpdaterError(_ error: any Error) async {+ pendingInstall = nil+ emit(.failed, message: error.localizedDescription)+ }++ func showDownloadInitiated(cancellation: @escaping () -> Void) {}++ func showDownloadDidReceiveExpectedContentLength(_ expectedContentLength: UInt64) {}++ func showDownloadDidReceiveData(ofLength length: UInt64) {}++ func showDownloadDidStartExtractingUpdate() {}++ func showExtractionReceivedProgress(_ progress: Double) {}++ func showReady(toInstallAndRelaunch reply: @escaping (SPUUserUpdateChoice) -> Void) {+ reply(.install)+ }++ func showInstallingUpdate(+ withApplicationTerminated applicationTerminated: Bool,+ retryTerminatingApplication: @escaping () -> Void+ ) {}++ func showUpdateInstalledAndRelaunched(_ relaunched: Bool) async {}++ func dismissUpdateInstallation() {+ pendingInstall = nil}}diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swiftindex 5063af2f..8ee64513 100644--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift@@ -761,7 +761,7 @@ final class UserQueryOverlayController {}private func openAvailableUpdate() {- model.showUpdateUI()+ model.installAvailableUpdate()}/// Brings back a pointer the user dismissed when its conversation is clicked indiff --git a/docs/guides/install-donkey.md b/docs/guides/install-donkey.mdindex c0c7a8f7..ddfa8f96 100644--- a/docs/guides/install-donkey.md+++ b/docs/guides/install-donkey.md@@ -55,9 +55,11 @@ immediately after opening `Donkey.dmg`.## Sparkle Updates-Donkey uses Sparkle for app updates. Do not add a Donkey-specific update-installer or custom replacement flow; Sparkle owns appcast parsing, update-validation, download, install, relaunch, and user-facing update UI.+Donkey uses Sparkle for app updates. Sparkle owns appcast parsing, update+validation, download, install, and relaunch; do not add a Donkey-specific+installer or replacement flow for those. Donkey drives Sparkle through a silent+user driver and surfaces the update itself in the notch, so Sparkle's standard+update windows are never shown.The public Sparkle feed lives in `site/public/appcast.xml`, served as`https://donkeyuse.com/appcast.xml`. Appcast enclosure URLs point to the@@ -88,8 +90,8 @@ For local update testing, use Sparkle's standard local appcast workflow:`DONKEY_SPARKLE_PUBLIC_ED_KEY` set to the matching public EdDSA key.When Sparkle finds a valid signed update, the expanded notch task panel shows-an update button in its header. Clicking it invokes Sparkle's standard update-UI.+an Update Available button in its header. Clicking it downloads, installs, and+relaunches silently through Sparkle, with no update window shown.## Hosted Models