From 69211cc0fd94c17b36d6b7b8c729dff4264207c5 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 19 Mar 2022 10:20:05 +0100 Subject: [PATCH] Adapt code and scripts for Sparkle v2 --- .../xcshareddata/swiftpm/Package.resolved | 4 +- VimR/VimR.xcodeproj/project.pbxproj | 2 +- VimR/VimR/AppDelegate.swift | 57 +++++++++++-------- bin/sign_vimr.sh | 21 +++++-- 4 files changed, 52 insertions(+), 32 deletions(-) diff --git a/VimR.xcworkspace/xcshareddata/swiftpm/Package.resolved b/VimR.xcworkspace/xcshareddata/swiftpm/Package.resolved index d2e59037..51d5100b 100644 --- a/VimR.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/VimR.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -114,8 +114,8 @@ "repositoryURL": "https://github.com/sparkle-project/Sparkle", "state": { "branch": null, - "revision": "7918c1c8fc68baa37917eeaa67286b077ad5e393", - "version": "1.27.1" + "revision": "286edd1fa22505a9e54d170e9fd07d775ea233f2", + "version": "2.1.0" } }, { diff --git a/VimR/VimR.xcodeproj/project.pbxproj b/VimR/VimR.xcodeproj/project.pbxproj index 2ca9c988..e494c561 100644 --- a/VimR/VimR.xcodeproj/project.pbxproj +++ b/VimR/VimR.xcodeproj/project.pbxproj @@ -1417,7 +1417,7 @@ repositoryURL = "https://github.com/sparkle-project/Sparkle"; requirement = { kind = exactVersion; - version = 1.27.1; + version = 2.1.0; }; }; 4BD5655124E8014100D52809 /* XCRemoteSwiftPackageReference "swifter" */ = { diff --git a/VimR/VimR/AppDelegate.swift b/VimR/VimR/AppDelegate.swift index 3339b54e..71215403 100644 --- a/VimR/VimR/AppDelegate.swift +++ b/VimR/VimR/AppDelegate.swift @@ -14,6 +14,18 @@ import Sparkle let debugMenuItemIdentifier = NSUserInterfaceItemIdentifier("debug-menu-item") +class UpdaterDelegate: NSObject, SPUUpdaterDelegate { + var useSnapshotChannel = false + + func feedURLString(for _: SPUUpdater) -> String? { + if self.useSnapshotChannel { + return "https://raw.githubusercontent.com/qvacua/vimr/develop/appcast_snapshot.xml" + } else { + return "https://raw.githubusercontent.com/qvacua/vimr/master/appcast.xml" + } + } +} + @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate { struct OpenConfig { @@ -55,7 +67,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele self.openNewMainWindowOnLaunch = initialAppState.openNewMainWindowOnLaunch self.openNewMainWindowOnReactivation = initialAppState.openNewMainWindowOnReactivation - self.useSnapshot = initialAppState.useSnapshotUpdate + self.updaterDelegate.useSnapshotChannel = initialAppState.useSnapshotUpdate super.init() @@ -85,9 +97,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele self.openNewMainWindowOnLaunch = appState.openNewMainWindowOnLaunch self.openNewMainWindowOnReactivation = appState.openNewMainWindowOnReactivation - if self.useSnapshot != appState.useSnapshotUpdate { - self.useSnapshot = appState.useSnapshotUpdate - self.setSparkleUrl(self.useSnapshot) + if self.updaterDelegate.useSnapshotChannel != appState.useSnapshotUpdate { + self.updaterDelegate.useSnapshotChannel = appState.useSnapshotUpdate } if appState.quit { NSApp.terminate(self) } @@ -105,25 +116,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele private var openNewMainWindowOnLaunch: Bool private var openNewMainWindowOnReactivation: Bool - private var useSnapshot: Bool private let disposeBag = DisposeBag() private var launching = true - private let log = OSLog(subsystem: Defs.loggerSubsystem, category: Defs.LoggerCategory.general) + private let updaterDelegate = UpdaterDelegate() - private func setSparkleUrl(_ snapshot: Bool) { - if snapshot { - updater.feedURL = URL( - string: "https://raw.githubusercontent.com/qvacua/vimr/develop/appcast_snapshot.xml" - ) - } else { - updater.feedURL = URL( - string: "https://raw.githubusercontent.com/qvacua/vimr/master/appcast.xml" - ) - } - } + private let log = OSLog(subsystem: Defs.loggerSubsystem, category: Defs.LoggerCategory.general) } // MARK: - NSApplicationDelegate @@ -144,6 +144,8 @@ extension AppDelegate { func applicationDidFinishLaunching(_: Notification) { self.launching = false + updaterController.startUpdater() + #if DEBUG NSApp.mainMenu?.items.first { $0.identifier == debugMenuItemIdentifier }?.isHidden = false #endif @@ -215,9 +217,9 @@ extension AppDelegate { ) switch self.context.state.openFilesFromApplicationsAction { case .inCurrentWindow: - self.emit(.openInKeyWindow(config: config)) + self.emit(.openInKeyWindow(config: config)) default: - self.emit(.newMainWindow(config: config)) + self.emit(.newMainWindow(config: config)) } sender.reply(toOpenOrPrint: .success) @@ -378,10 +380,11 @@ extension AppDelegate { return nil } - private func queryParam(_ prefix: String, - from rawParams: [String], - transforming transform: (String) -> T) -> [T] - { + private func queryParam( + _ prefix: String, + from rawParams: [String], + transforming transform: (String) -> T + ) -> [T] { rawParams .filter { $0.hasPrefix(prefix) } .compactMap { $0.without(prefix: prefix).removingPercentEncoding } @@ -393,7 +396,7 @@ extension AppDelegate { extension AppDelegate { @IBAction func checkForUpdates(_ sender: Any?) { - updater.checkForUpdates(sender) + updaterController.checkForUpdates(sender) } @IBAction func newDocument(_: Any?) { @@ -444,7 +447,11 @@ private enum VimRUrlAction: String { case nvim } -private let updater = SUUpdater() +private let updaterController = SPUStandardUpdaterController( + startingUpdater: false, + updaterDelegate: nil, + userDriverDelegate: nil +) // Keep in sync with QueryParamKey in the `vimr` Python script. private let filePrefix = "file=" diff --git a/bin/sign_vimr.sh b/bin/sign_vimr.sh index fd9e8c7c..1360b4f7 100755 --- a/bin/sign_vimr.sh +++ b/bin/sign_vimr.sh @@ -4,6 +4,13 @@ set -Eeuo pipefail readonly vimr_app_path=${vimr_app_path:?"Path to VimR.app"} readonly identity="Developer ID Application: Tae Won Ha (H96Q2NKTQH)" +remove_sparkle_xpc () { + # VimR is not sandboxed, so, remove the XPCs + # https://sparkle-project.org/documentation/sandboxing/#removing-xpc-services + rm -rf "${vimr_app_path}/Contents/Frameworks/Sparkle.framework/Versions/B/XPCServices/org.sparkle-project.InstallerLauncher.xpc" + rm -rf "${vimr_app_path}/Contents/Frameworks/Sparkle.framework/Versions/B/XPCServices/org.sparkle-project.Downloader.xpc" +} + main () { pushd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null echo "### Signing VimR" @@ -11,10 +18,16 @@ main () { entitlements_path=$(realpath ./Carthage/Build/Mac/NvimServer/NvimServer.entitlements) readonly entitlements_path - codesign --verbose --force -s "${identity}" --deep --timestamp --options=runtime \ - "${vimr_app_path}/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app" + remove_sparkle_xpc + codesign --verbose --force -s "${identity}" --timestamp --options=runtime \ - "${vimr_app_path}/Contents/Frameworks/Sparkle.framework/Versions/A" + "${vimr_app_path}/Contents/Frameworks/Sparkle.framework/Versions/B/Autoupdate" + + codesign --verbose --force -s "${identity}" --deep --timestamp --options=runtime \ + "${vimr_app_path}/Contents/Frameworks/Sparkle.framework/Versions/B/Updater.app" + + codesign --verbose --force -s "${identity}" --options=runtime \ + "${vimr_app_path}/Contents/Frameworks/Sparkle.framework" codesign --verbose --force -s "${identity}" --timestamp --options=runtime \ --entitlements="${entitlements_path}" \ @@ -28,4 +41,4 @@ main () { popd >/dev/null } -main \ No newline at end of file +main