diff --git a/AppCast/_includes/appcast.inc b/AppCast/_includes/appcast.inc index 0e1a628..335a64f 100644 --- a/AppCast/_includes/appcast.inc +++ b/AppCast/_includes/appcast.inc @@ -12,6 +12,8 @@ {{ release.published_at | date_to_rfc822 }} {% for asset in release.assets limit:1 %} + {% assign signature = release.body | sparkle_signature %} + {% assign build_nums = release.tag_name | replace_first:'v','' | replace_first:'b',',' | split:',' %} {% if build_nums.size == 2 %} {% assign version_number = build_nums[0] %} @@ -21,6 +23,7 @@ url="{{ asset.browser_download_url }}" sparkle:version="{{ build_number }}" sparkle:shortVersionString="{{ version_number }}" + sparkle:edSignature="{{ signature }}" length="{{ asset.size }}" type="application/octet-stream" /> {% else %} @@ -29,6 +32,7 @@ {% endif %} diff --git a/AppCast/_plugins/signature_filter.rb b/AppCast/_plugins/signature_filter.rb new file mode 100644 index 0000000..0a9509c --- /dev/null +++ b/AppCast/_plugins/signature_filter.rb @@ -0,0 +1,12 @@ +module Jekyll + module SignatureFilter + def sparkle_signature(release_body) + regex = //m + signature = release_body.match(regex).named_captures["signature"] + raise "Didn't find a signature in the release body." if signature.empty? + signature + end + end +end + +Liquid::Template.register_filter(Jekyll::SignatureFilter) \ No newline at end of file diff --git a/DECISIONS.md b/DECISIONS.md index bc9bd91..9e9ca9a 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -64,3 +64,13 @@ Here are the descriptions of these terms from [Apple's Style Guide](https://book Xcodes.app has this same functionality as xcodes, which still uses `xcode-select` under the hood, but because the main UI is a list of selectable rows, there _may_ be some ambiguity about the meaning of "selected". "Default" has a less clear connection to `xcode-select`'s name, but does accurately describe the behaviour that results. In Xcode 11 Launch Services also uses the selected Xcode version when opening a (GUI) developer tool bundled with Xcode, like Instruments. We could also try to follow Apple's lead by using the term "active" from the `xcode-select` man pages and notarization documentation. According to the style guide "active" already has a clear meaning in a GUI context. Ultimately, we've decided to align with Apple's usage of "active" and "make active" in this specific context, despite possible confusion with the definition in the style guide. + +## Software Updates + +We're familiar with using GitHub releases to distribute pre-built, code signed and notarized versions of `xcodes` via direct download and Homebrew. Ideally we could use GitHub releases here too with an update mechanism more suitable for an app bundle. For distribution outside the Mac App Store, the most popular choice for updates is [Sparkle](https://sparkle-project.org). The v2 branch has been in beta for a long time, but since Xcodes.app isn't (currently) sandboxed, we can use the production-ready v1 releases. + +Based on [this blog post](https://yiqiu.me/2015/11/19/sparkle-update-on-github/), we can use GitHub Pages to generate the appcast for Sparkle to point at releases in our repo. We've made a few changes, like putting the source for the Jekyll site on the main branch, and including the EdDSA signature in the appcast. Generating the appcast file manually would be more straightforward, but we can always edit the files on the gh_pages branch manually if we need to, and it's one less step for a release manager to perform when they're already creating the release in the repo. + +We're deliberately not capturing system profile data with Sparkle right now, because we don't want it and because it would require additional infrastructure. + +We also considered https://github.com/mxcl/AppUpdater, but decided aganist it because it seemed less battle-tested than Sparkle and currently lacks an open source license. diff --git a/README.md b/README.md index 451d84f..44b50fb 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,21 @@ git push --follow-tags scripts/package_release.sh # Notarize the app -scripts/notarize.sh "test@example.com" "@keychain:altool" MyOrg Product/Xcodes.zip +# Do this from the Product directory so the app is zipped without being nested inside Product +pushd Product +../scripts/notarize.sh "test@example.com" "@keychain:altool" MyOrg Xcodes.zip + +# Sign the .zip for Sparkle, note the signature in the output for later +../scripts/sign_update Xcodes.zip +popd # Go to https://github.com/RobotsAndPencils/XcodesApp/releases # Edit the latest draft release # Set its tag to the tag you just pushed # Set its title to a string with the format "$VERSION ($BUILD)" # Polish the draft release notes, if necessary +# Add the signature to the bottom of the release notes in a comment, like: + # Attach the zip that was created in the Product directory to the release # Publish the release ``` diff --git a/Scripts/notarize.sh b/Scripts/notarize.sh index 89de6d4..b9dd426 100755 --- a/Scripts/notarize.sh +++ b/Scripts/notarize.sh @@ -66,4 +66,4 @@ app_path="$(basename -s ".zip" "$file").app" xcrun stapler staple "$app_path" # Zip the stapled app for distribution -zip -r "$file" "$app_path" +ditto -c -k --sequesterRsrc --keepParent "$file" "$app_path" diff --git a/Scripts/sign_update b/Scripts/sign_update new file mode 100755 index 0000000..8193e1f Binary files /dev/null and b/Scripts/sign_update differ diff --git a/Xcodes.xcodeproj/project.pbxproj b/Xcodes.xcodeproj/project.pbxproj index 667c317..4982c06 100644 --- a/Xcodes.xcodeproj/project.pbxproj +++ b/Xcodes.xcodeproj/project.pbxproj @@ -70,7 +70,6 @@ CABFA9EE2592F0CC00380FEE /* SwiftSoup in Frameworks */ = {isa = PBXBuildFile; productRef = CABFA9ED2592F0CC00380FEE /* SwiftSoup */; }; CABFA9F82592F0F900380FEE /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = CABFA9F72592F0F900380FEE /* KeychainAccess */; }; CABFA9FD2592F13300380FEE /* LegibleError in Frameworks */ = {isa = PBXBuildFile; productRef = CABFA9FC2592F13300380FEE /* LegibleError */; }; - CABFAA2C2592FBFC00380FEE /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABFAA2A2592FBFC00380FEE /* SettingsView.swift */; }; CABFAA2D2592FBFC00380FEE /* Configure.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABFAA2B2592FBFC00380FEE /* Configure.swift */; }; CABFAA432593104F00380FEE /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABFAA422593104F00380FEE /* AboutView.swift */; }; CABFAA492593162500380FEE /* Bundle+InfoPlistValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABFAA482593162500380FEE /* Bundle+InfoPlistValues.swift */; }; @@ -93,6 +92,11 @@ CAFBDC4E2599B33D003DCC5A /* MainToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFBDC4D2599B33D003DCC5A /* MainToolbar.swift */; }; CAFBDC68259A308B003DCC5A /* InfoPane.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFBDC67259A308B003DCC5A /* InfoPane.swift */; }; CAFBDC6C259A3098003DCC5A /* View+Conditional.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFBDC6B259A3098003DCC5A /* View+Conditional.swift */; }; + CAFE4A9A25B7C7A30064FE51 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = CAFE4A9925B7C7A30064FE51 /* Sparkle */; }; + CAFE4AA325B7CF960064FE51 /* Preferences in Frameworks */ = {isa = PBXBuildFile; productRef = CAFE4AA225B7CF960064FE51 /* Preferences */; }; + CAFE4AAC25B7D2C70064FE51 /* GeneralPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFE4AAB25B7D2C70064FE51 /* GeneralPreferencePane.swift */; }; + CAFE4AB425B7D3AF0064FE51 /* AdvancedPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFE4AB325B7D3AF0064FE51 /* AdvancedPreferencePane.swift */; }; + CAFE4ABC25B7D54B0064FE51 /* UpdatesPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFE4ABB25B7D54B0064FE51 /* UpdatesPreferencePane.swift */; }; CAFFFED8259CDA5000903F81 /* XcodeListViewRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFFFED7259CDA5000903F81 /* XcodeListViewRow.swift */; }; /* End PBXBuildFile section */ @@ -218,7 +222,6 @@ CABFA9B92592EEEA00380FEE /* Downloads.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Downloads.swift; sourceTree = ""; }; CABFA9BA2592EEEA00380FEE /* DateFormatter+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+.swift"; sourceTree = ""; }; CABFA9D42592EF6300380FEE /* DECISIONS.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = DECISIONS.md; sourceTree = ""; }; - CABFAA2A2592FBFC00380FEE /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsView.swift; path = Xcodes/SettingsView.swift; sourceTree = SOURCE_ROOT; }; CABFAA2B2592FBFC00380FEE /* Configure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Configure.swift; path = Xcodes/Backend/Configure.swift; sourceTree = SOURCE_ROOT; }; CABFAA422593104F00380FEE /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = ""; }; CABFAA482593162500380FEE /* Bundle+InfoPlistValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+InfoPlistValues.swift"; sourceTree = ""; }; @@ -249,6 +252,9 @@ CAFBDC4D2599B33D003DCC5A /* MainToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainToolbar.swift; sourceTree = ""; }; CAFBDC67259A308B003DCC5A /* InfoPane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoPane.swift; sourceTree = ""; }; CAFBDC6B259A3098003DCC5A /* View+Conditional.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Conditional.swift"; sourceTree = ""; }; + CAFE4AAB25B7D2C70064FE51 /* GeneralPreferencePane.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralPreferencePane.swift; sourceTree = ""; }; + CAFE4AB325B7D3AF0064FE51 /* AdvancedPreferencePane.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvancedPreferencePane.swift; sourceTree = ""; }; + CAFE4ABB25B7D54B0064FE51 /* UpdatesPreferencePane.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatesPreferencePane.swift; sourceTree = ""; }; CAFFFED7259CDA5000903F81 /* XcodeListViewRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeListViewRow.swift; sourceTree = ""; }; CAFFFEEE259CEAC400903F81 /* RingProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RingProgressViewStyle.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -265,6 +271,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CAFE4A9A25B7C7A30064FE51 /* Sparkle in Frameworks */, + CAFE4AA325B7CF960064FE51 /* Preferences in Frameworks */, CABFA9E42592F08E00380FEE /* Version in Frameworks */, CABFA9FD2592F13300380FEE /* LegibleError in Frameworks */, CA9FF86D25951C6E00E47BAF /* XCModel in Frameworks */, @@ -434,10 +442,10 @@ children = ( 63EAA4E9259944340046AB8F /* Common */, CA9FF8552595082000E47BAF /* About */, + CAFE4AAA25B7D29B0064FE51 /* Preferences */, CAA1CB50255A5D16003FD669 /* SignIn */, CABFAA142592F73000380FEE /* XcodeList */, CAE4247E259A666100B8B246 /* MainWindow.swift */, - CABFAA2A2592FBFC00380FEE /* SettingsView.swift */, CAFBDC6B259A3098003DCC5A /* View+Conditional.swift */, CA9FF8652595130600E47BAF /* View+IsHidden.swift */, ); @@ -524,6 +532,16 @@ path = XcodesTests; sourceTree = ""; }; + CAFE4AAA25B7D29B0064FE51 /* Preferences */ = { + isa = PBXGroup; + children = ( + CAFE4AB325B7D3AF0064FE51 /* AdvancedPreferencePane.swift */, + CAFE4AAB25B7D2C70064FE51 /* GeneralPreferencePane.swift */, + CAFE4ABB25B7D54B0064FE51 /* UpdatesPreferencePane.swift */, + ); + path = Preferences; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -570,6 +588,8 @@ CABFA9FC2592F13300380FEE /* LegibleError */, CA9FF86C25951C6E00E47BAF /* XCModel */, CAA858CC25A3D8BC00ACF8C0 /* ErrorHandling */, + CAFE4A9925B7C7A30064FE51 /* Sparkle */, + CAFE4AA225B7CF960064FE51 /* Preferences */, ); productName = XcodesMac; productReference = CAD2E79E2449574E00113D76 /* Xcodes.app */; @@ -636,6 +656,8 @@ CA9FF86B25951C6E00E47BAF /* XCRemoteSwiftPackageReference "data" */, CAA858CB25A3D8BC00ACF8C0 /* XCRemoteSwiftPackageReference "ErrorHandling" */, CAC28186259EE27200B8AB0B /* XCRemoteSwiftPackageReference "CombineExpectations" */, + CAFE4A9825B7C7A30064FE51 /* XCRemoteSwiftPackageReference "Sparkle" */, + CAFE4AA125B7CF960064FE51 /* XCRemoteSwiftPackageReference "Preferences" */, ); productRefGroup = CAD2E79F2449574E00113D76 /* Products */; projectDirPath = ""; @@ -726,7 +748,9 @@ CABFA9CA2592EEEA00380FEE /* AppState+Update.swift in Sources */, CA44901F2463AD34003D8213 /* Tag.swift in Sources */, CABFA9BF2592EEEA00380FEE /* URLSession+DownloadTaskPublisher.swift in Sources */, + CAFE4AAC25B7D2C70064FE51 /* GeneralPreferencePane.swift in Sources */, CABFA9BB2592EEEA00380FEE /* DateFormatter+.swift in Sources */, + CAFE4ABC25B7D54B0064FE51 /* UpdatesPreferencePane.swift in Sources */, CABFA9BD2592EEEA00380FEE /* Environment.swift in Sources */, CABFA9C32592EEEA00380FEE /* Downloads.swift in Sources */, CAC281DA259F985100B8AB0B /* InstallationStep.swift in Sources */, @@ -740,6 +764,7 @@ CA61A6E0259835580008926E /* Xcode.swift in Sources */, CAE4247F259A666100B8B246 /* MainWindow.swift in Sources */, CA452BB0259FD9770072DFA4 /* ProgressIndicator.swift in Sources */, + CAFE4AB425B7D3AF0064FE51 /* AdvancedPreferencePane.swift in Sources */, CAC281C8259F97E100B8AB0B /* InstallationStepView.swift in Sources */, CA9FF84E2595079F00E47BAF /* ScrollingTextView.swift in Sources */, CABFA9C12592EEEA00380FEE /* Version+.swift in Sources */, @@ -763,7 +788,6 @@ CABFA9C72592EEEA00380FEE /* Entry+.swift in Sources */, CAE424B4259A764700B8B246 /* AppState+Install.swift in Sources */, CAE42487259A68A300B8B246 /* XcodeListCategory.swift in Sources */, - CABFAA2C2592FBFC00380FEE /* SettingsView.swift in Sources */, CAA858C425A2BE4E00ACF8C0 /* Downloader.swift in Sources */, CA9FF87B2595293E00E47BAF /* DataSource.swift in Sources */, CABFA9C92592EEEA00380FEE /* URLRequest+Apple.swift in Sources */, @@ -1299,6 +1323,22 @@ minimumVersion = 0.6.0; }; }; + CAFE4A9825B7C7A30064FE51 /* XCRemoteSwiftPackageReference "Sparkle" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sparkle-project/Sparkle/"; + requirement = { + kind = exactVersion; + version = "1.24.0-spm"; + }; + }; + CAFE4AA125B7CF960064FE51 /* XCRemoteSwiftPackageReference "Preferences" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sindresorhus/Preferences"; + requirement = { + kind = upToNextMinorVersion; + minimumVersion = 2.2.0; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -1346,6 +1386,16 @@ package = CAC28186259EE27200B8AB0B /* XCRemoteSwiftPackageReference "CombineExpectations" */; productName = CombineExpectations; }; + CAFE4A9925B7C7A30064FE51 /* Sparkle */ = { + isa = XCSwiftPackageProductDependency; + package = CAFE4A9825B7C7A30064FE51 /* XCRemoteSwiftPackageReference "Sparkle" */; + productName = Sparkle; + }; + CAFE4AA225B7CF960064FE51 /* Preferences */ = { + isa = XCSwiftPackageProductDependency; + package = CAFE4AA125B7CF960064FE51 /* XCRemoteSwiftPackageReference "Preferences" */; + productName = Preferences; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = CAD2E7962449574E00113D76 /* Project object */; diff --git a/Xcodes.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Xcodes.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 598952c..525b323 100644 --- a/Xcodes.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Xcodes.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -55,6 +55,24 @@ "version": "0.16.3" } }, + { + "package": "Preferences", + "repositoryURL": "https://github.com/sindresorhus/Preferences", + "state": { + "branch": null, + "revision": "4802a493acef50c814e4eb63e9a44e0941ec8883", + "version": "2.2.0" + } + }, + { + "package": "Sparkle", + "repositoryURL": "https://github.com/sparkle-project/Sparkle/", + "state": { + "branch": null, + "revision": "891afd44c7075e699924ed9b81d8dc94a5111dfd", + "version": "1.24.0-spm" + } + }, { "package": "SwiftSoup", "repositoryURL": "https://github.com/scinfu/SwiftSoup", diff --git a/Xcodes/SettingsView.swift b/Xcodes/Frontend/Preferences/AdvancedPreferencePane.swift similarity index 77% rename from Xcodes/SettingsView.swift rename to Xcodes/Frontend/Preferences/AdvancedPreferencePane.swift index e754ab7..4dc028d 100644 --- a/Xcodes/SettingsView.swift +++ b/Xcodes/Frontend/Preferences/AdvancedPreferencePane.swift @@ -1,30 +1,19 @@ import AppleAPI +import Preferences import SwiftUI -struct SettingsView: View { +extension Preferences.PaneIdentifier { + static let advanced = Self("advanced") +} + +struct AdvancedPreferencePane: View { @EnvironmentObject var appState: AppState @AppStorage("dataSource") var dataSource: DataSource = .xcodeReleases @AppStorage("downloader") var downloader: Downloader = .aria2 var body: some View { - VStack(alignment: .leading) { - GroupBox(label: Text("Apple ID")) { - VStack(alignment: .leading) { - if appState.authenticationState == .authenticated { - Text(Current.defaults.string(forKey: "username") ?? "-") - Button("Sign Out", action: appState.signOut) - } else { - Button("Sign In", action: { self.appState.presentingSignInAlert = true }) - } - } - .frame(maxWidth: .infinity, alignment: .leading) - .sheet(isPresented: $appState.presentingSignInAlert) { - SignInCredentialsView(isPresented: $appState.presentingSignInAlert) - .environmentObject(appState) - } - } - - GroupBox(label: Text("Data Source")) { + Preferences.Container(contentWidth: 400.0) { + Preferences.Section(title: "Data Source") { VStack(alignment: .leading) { Picker("Data Source", selection: $dataSource) { ForEach(DataSource.allCases) { dataSource in @@ -39,7 +28,7 @@ struct SettingsView: View { .frame(maxWidth: .infinity, alignment: .leading) } - GroupBox(label: Text("Downloader")) { + Preferences.Section(title: "Downloader") { VStack(alignment: .leading) { Picker("Downloader", selection: $downloader) { ForEach(Downloader.allCases) { downloader in @@ -54,7 +43,7 @@ struct SettingsView: View { .frame(maxWidth: .infinity, alignment: .leading) } - GroupBox(label: Text("Privileged Helper")) { + Preferences.Section(title: "Privileged Helper") { VStack(alignment: .leading, spacing: 8) { switch appState.helperInstallState { case .unknown: @@ -73,14 +62,13 @@ struct SettingsView: View { Text("Xcodes uses a separate privileged helper to perform tasks as root. These are things that would require sudo on the command line, including post-install steps and switching Xcode versions with xcode-select.") .font(.footnote) + .fixedSize(horizontal: false, vertical: true) + + Spacer() } } - Spacer() } - .padding() - .navigationTitle("Settings") - .frame(width: 400) - .frame(minHeight: 500) + .padding(.trailing) } private var dataSourceFootnote: NSAttributedString { @@ -118,10 +106,10 @@ struct SettingsView: View { } } -struct SettingsView_Previews: PreviewProvider { +struct AdvancedPreferencePane_Previews: PreviewProvider { static var previews: some View { Group { - SettingsView() + AdvancedPreferencePane() .environmentObject(AppState()) } } diff --git a/Xcodes/Frontend/Preferences/GeneralPreferencePane.swift b/Xcodes/Frontend/Preferences/GeneralPreferencePane.swift new file mode 100644 index 0000000..cef62a2 --- /dev/null +++ b/Xcodes/Frontend/Preferences/GeneralPreferencePane.swift @@ -0,0 +1,43 @@ +import AppleAPI +import Preferences +import SwiftUI + +extension Preferences.PaneIdentifier { + static let general = Self("general") +} + +struct GeneralPreferencePane: View { + @EnvironmentObject var appState: AppState + + var body: some View { + Preferences.Container(contentWidth: 400.0) { + Preferences.Section(title: "Apple ID") { + VStack(alignment: .leading) { + if appState.authenticationState == .authenticated { + Text(Current.defaults.string(forKey: "username") ?? "-") + Button("Sign Out", action: appState.signOut) + } else { + Button("Sign In", action: { self.appState.presentingSignInAlert = true }) + } + + Spacer() + } + .frame(maxWidth: .infinity, alignment: .leading) + .sheet(isPresented: $appState.presentingSignInAlert) { + SignInCredentialsView(isPresented: $appState.presentingSignInAlert) + .environmentObject(appState) + } + } + } + .padding(.trailing) + } +} + +struct GeneralPreferencePane_Previews: PreviewProvider { + static var previews: some View { + Group { + GeneralPreferencePane() + .environmentObject(AppState()) + } + } +} diff --git a/Xcodes/Frontend/Preferences/UpdatesPreferencePane.swift b/Xcodes/Frontend/Preferences/UpdatesPreferencePane.swift new file mode 100644 index 0000000..512c875 --- /dev/null +++ b/Xcodes/Frontend/Preferences/UpdatesPreferencePane.swift @@ -0,0 +1,107 @@ +import AppleAPI +import Preferences +import Sparkle +import SwiftUI + +extension Preferences.PaneIdentifier { + static let updates = Self("updates") +} + +struct UpdatesPreferencePane: View { + @StateObject var updater = ObservableUpdater() + + var body: some View { + Preferences.Container(contentWidth: 400.0) { + Preferences.Section(title: "Updates") { + VStack(alignment: .leading) { + Toggle( + "Automatically check for updates", + isOn: $updater.automaticallyChecksForUpdates + ) + + Toggle( + "Include prerelease versions", + isOn: $updater.includePrereleaseVersions + ) + + Button("Check Now") { + SUUpdater.shared()?.checkForUpdates(nil) + } + + Text("Last checked: \(lastUpdatedString)") + .font(.footnote) + } + .frame(maxWidth: .infinity, alignment: .leading) + } + } + .padding(.trailing) + } + + private var lastUpdatedString: String { + if let lastUpdatedDate = updater.lastUpdateCheckDate { + return Self.formatter.string(from: lastUpdatedDate) + } else { + return "Never" + } + } + + private static let formatter = configure(DateFormatter()) { + $0.dateStyle = .medium + $0.timeStyle = .medium + } +} + +class ObservableUpdater: ObservableObject { + @Published var automaticallyChecksForUpdates = false { + didSet { + SUUpdater.shared()?.automaticallyChecksForUpdates = automaticallyChecksForUpdates + } + } + private var automaticallyChecksForUpdatesObservation: NSKeyValueObservation? + @Published var lastUpdateCheckDate: Date? + private var lastUpdateCheckDateObservation: NSKeyValueObservation? + @Published var includePrereleaseVersions = false { + didSet { + UserDefaults.standard.setValue(includePrereleaseVersions, forKey: "includePrereleaseVersions") + + if includePrereleaseVersions { + SUUpdater.shared()?.feedURL = .prereleaseAppcast + } else { + SUUpdater.shared()?.feedURL = .appcast + } + } + } + + init() { + automaticallyChecksForUpdatesObservation = SUUpdater.shared()?.observe( + \.automaticallyChecksForUpdates, + options: [.initial, .new, .old], + changeHandler: { [unowned self] updater, change in + guard change.newValue != change.oldValue else { return } + self.automaticallyChecksForUpdates = updater.automaticallyChecksForUpdates + } + ) + lastUpdateCheckDateObservation = SUUpdater.shared()?.observe( + \.lastUpdateCheckDate, + options: [.initial, .new, .old], + changeHandler: { [unowned self] updater, change in + self.lastUpdateCheckDate = updater.lastUpdateCheckDate + } + ) + includePrereleaseVersions = UserDefaults.standard.bool(forKey: "includePrereleaseVersions") + } +} + +extension URL { + static let appcast = URL(string: "https://robotsandpencils.github.io/XcodesApp/appcast.xml")! + static let prereleaseAppcast = URL(string: "https://robotsandpencils.github.io/XcodesApp/appcast_pre.xml")! +} + +struct UpdatesPreferencePane_Previews: PreviewProvider { + static var previews: some View { + Group { + UpdatesPreferencePane() + .environmentObject(AppState()) + } + } +} diff --git a/Xcodes/Resources/Info.plist b/Xcodes/Resources/Info.plist index c4c07d5..258123b 100644 --- a/Xcodes/Resources/Info.plist +++ b/Xcodes/Resources/Info.plist @@ -37,5 +37,9 @@ com.robotsandpencils.XcodesApp.Helper identifier "com.robotsandpencils.XcodesApp.Helper" and info [CFBundleShortVersionString] >= "1.0.0" and anchor apple generic and certificate leaf[subject.OU] = "$(CODE_SIGNING_SUBJECT_ORGANIZATIONAL_UNIT)" + SUFeedURL + https://robotsandpencils.github.io/XcodesApp/appcast.xml + SUPublicEDKey + SEcz0vgUSeBTOoAXYe+64zea95G6lIf5NgzFs3InYJQ= diff --git a/Xcodes/Resources/Licenses.rtf b/Xcodes/Resources/Licenses.rtf index cc81dc2..9636214 100644 --- a/Xcodes/Resources/Licenses.rtf +++ b/Xcodes/Resources/Licenses.rtf @@ -4,7 +4,22 @@ {\*\expandedcolortbl;;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0 -\f0\fs34 \cf0 SwiftSoup\ +\f0\fs34 \cf0 Preferences\ +\ + +\fs26 MIT License\ +\ +Copyright (c) Sindre Sorhus (sindresorhus.com)\ +\ +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\ +\ +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\ +\ +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\ +\ +\ + +\fs34 SwiftSoup\ \ \fs26 MIT License\ diff --git a/Xcodes/XcodesApp.swift b/Xcodes/XcodesApp.swift index 4fb73bc..85b0569 100644 --- a/Xcodes/XcodesApp.swift +++ b/Xcodes/XcodesApp.swift @@ -1,5 +1,7 @@ -import SwiftUI import AppKit +import Preferences +import Sparkle +import SwiftUI @main struct XcodesApp: App { @@ -28,6 +30,18 @@ struct XcodesApp: App { appDelegate.showAboutWindow() } } + CommandGroup(after: .appInfo) { + Button("Check for Updates...") { + appDelegate.checkForUpdates() + } + } + CommandGroup(replacing: .appSettings) { + Button("Preferences...") { + showPreferencesWindow() + } + .keyboardShortcut(KeyEquivalent(","), modifiers: .command) + } + CommandGroup(after: CommandGroupPlacement.newItem) { Button("Refresh") { appState.update() @@ -38,11 +52,37 @@ struct XcodesApp: App { XcodeCommands(appState: appState) } - - Settings { - SettingsView() - .environmentObject(appState) - } + } + + private func showPreferencesWindow() { + PreferencesWindowController( + panes: [ + Preferences.Pane( + identifier: .general, + title: "General", + toolbarIcon: NSImage(systemSymbolName: "gearshape", accessibilityDescription: "General")! + ) { + GeneralPreferencePane() + .environmentObject(appState) + }, + Preferences.Pane( + identifier: .updates, + title: "Updates", + toolbarIcon: NSImage(systemSymbolName: "arrow.triangle.2.circlepath.circle", accessibilityDescription: "Updates")! + ) { + UpdatesPreferencePane() + }, + Preferences.Pane( + identifier: .advanced, + title: "Advanced", + toolbarIcon: NSImage(systemSymbolName: "gearshape.2", accessibilityDescription: "Advanced")! + ) { + AdvancedPreferencePane() + .environmentObject(appState) + }, + ] + ) + .show() } } @@ -83,4 +123,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { acknowledgementsWindow.center() acknowledgementsWindow.makeKeyAndOrderFront(nil) } + + func checkForUpdates() { + SUUpdater.shared()?.checkForUpdates(self) + } + + func applicationDidFinishLaunching(_ notification: Notification) { + // Initialize manually + SUUpdater.shared() + } }