- Notifications
You must be signed in to change notification settings - Fork3
feat: add auto-updates#176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
6a86c64
feat: add auto-updates
ethanndickson1c7f4de
remove preview cask updating
ethanndickson543390b
once again I have been owned by the fact that I cannot sync the swift…
ethanndickson134c7bc
typos in update-cask
ethanndicksonc904646
fixup
ethanndicksonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletions.github/workflows/release.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletionsCoder-Desktop/Coder-Desktop/Coder_DesktopApp.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionsCoder-Desktop/Coder-Desktop/Info.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletionsCoder-Desktop/Coder-Desktop/UpdaterService.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import Sparkle | ||
import SwiftUI | ||
final class UpdaterService: NSObject, ObservableObject { | ||
private lazy var inner: SPUStandardUpdaterController = .init( | ||
startingUpdater: true, | ||
updaterDelegate: self, | ||
userDriverDelegate: self | ||
) | ||
private var updater: SPUUpdater! | ||
@Published var canCheckForUpdates = true | ||
@Published var autoCheckForUpdates: Bool! { | ||
didSet { | ||
if let autoCheckForUpdates, autoCheckForUpdates != oldValue { | ||
updater.automaticallyChecksForUpdates = autoCheckForUpdates | ||
} | ||
} | ||
} | ||
@Published var updateChannel: UpdateChannel { | ||
didSet { | ||
UserDefaults.standard.set(updateChannel.rawValue, forKey: Self.updateChannelKey) | ||
} | ||
} | ||
static let updateChannelKey = "updateChannel" | ||
override init() { | ||
updateChannel = UserDefaults.standard.string(forKey: Self.updateChannelKey) | ||
.flatMap { UpdateChannel(rawValue: $0) } ?? .stable | ||
super.init() | ||
updater = inner.updater | ||
autoCheckForUpdates = updater.automaticallyChecksForUpdates | ||
updater.publisher(for: \.canCheckForUpdates).assign(to: &$canCheckForUpdates) | ||
} | ||
func checkForUpdates() { | ||
guard canCheckForUpdates else { return } | ||
updater.checkForUpdates() | ||
} | ||
} | ||
enum UpdateChannel: String, CaseIterable, Identifiable { | ||
case stable | ||
case preview | ||
var name: String { | ||
switch self { | ||
case .stable: | ||
"Stable" | ||
case .preview: | ||
"Preview" | ||
} | ||
} | ||
var id: String { rawValue } | ||
} | ||
extension UpdaterService: SPUUpdaterDelegate { | ||
func allowedChannels(for _: SPUUpdater) -> Set<String> { | ||
// There's currently no point in subscribing to both channels, as | ||
// preview >= stable | ||
[updateChannel.rawValue] | ||
} | ||
} | ||
extension UpdaterService: SUVersionDisplay { | ||
func formatUpdateVersion( | ||
fromUpdate update: SUAppcastItem, | ||
andBundleDisplayVersion inOutBundleDisplayVersion: AutoreleasingUnsafeMutablePointer<NSString>, | ||
withBundleVersion bundleVersion: String | ||
) -> String { | ||
// Replace CFBundleShortVersionString with CFBundleVersion, as the | ||
// latter shows build numbers. | ||
inOutBundleDisplayVersion.pointee = bundleVersion as NSString | ||
// This is already CFBundleVersion, as that's the only version in the | ||
// appcast. | ||
return update.displayVersionString | ||
} | ||
} | ||
extension UpdaterService: SPUStandardUserDriverDelegate { | ||
func standardUserDriverRequestsVersionDisplayer() -> (any SUVersionDisplay)? { | ||
self | ||
} | ||
} |
2 changes: 1 addition & 1 deletionCoder-Desktop/Coder-Desktop/VPN/VPNSystemExtension.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
19 changes: 15 additions & 4 deletionsCoder-Desktop/Coder-Desktop/Views/Settings/GeneralTab.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsCoder-Desktop/project.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
46 changes: 15 additions & 31 deletionsscripts/update-cask.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.