- Notifications
You must be signed in to change notification settings - Fork5
feat: support disabling the built-in updater#219
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,42 +2,59 @@ import Sparkle | ||
import SwiftUI | ||
final class UpdaterService: NSObject, ObservableObject { | ||
// The auto-updater can be entirely disabled by setting the | ||
// `disableUpdater` UserDefaults key to `true`. This is designed for use in | ||
// MDM configurations, where the value can be set to `true` permanently. | ||
let disabled: Bool = UserDefaults.standard.bool(forKey: Keys.disableUpdater) | ||
CopilotAI | ||
@Published var canCheckForUpdates = true | ||
@Published var autoCheckForUpdates: Bool! { | ||
didSet { | ||
if let autoCheckForUpdates, autoCheckForUpdates != oldValue { | ||
inner?.updater.automaticallyChecksForUpdates = autoCheckForUpdates | ||
} | ||
} | ||
} | ||
@Published var updateChannel: UpdateChannel { | ||
didSet { | ||
UserDefaults.standard.set(updateChannel.rawValue, forKey:Keys.updateChannel) | ||
} | ||
} | ||
private var inner: (controller: SPUStandardUpdaterController, updater: SPUUpdater)? | ||
override init() { | ||
updateChannel = UserDefaults.standard.string(forKey:Keys.updateChannel) | ||
.flatMap { UpdateChannel(rawValue: $0) } ?? .stable | ||
super.init() | ||
guard !disabled else { | ||
return | ||
} | ||
let inner = SPUStandardUpdaterController( | ||
startingUpdater: true, | ||
updaterDelegate: self, | ||
userDriverDelegate: self | ||
) | ||
let updater = inner.updater | ||
self.inner = (inner, updater) | ||
autoCheckForUpdates = updater.automaticallyChecksForUpdates | ||
updater.publisher(for: \.canCheckForUpdates).assign(to: &$canCheckForUpdates) | ||
} | ||
func checkForUpdates() { | ||
guard let inner, canCheckForUpdates else { return } | ||
inner.updater.checkForUpdates() | ||
} | ||
enum Keys { | ||
static let disableUpdater = "disableUpdater" | ||
static let updateChannel = "updateChannel" | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -19,18 +19,25 @@ struct GeneralTab: View { | ||||||
Text("Start Coder Connect on launch") | ||||||
} | ||||||
} | ||||||
if !updater.disabled { | ||||||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||
Section { | ||||||
Toggle(isOn: $updater.autoCheckForUpdates) { | ||||||
Text("Automatically check for updates") | ||||||
} | ||||||
Picker("Update channel", selection: $updater.updateChannel) { | ||||||
ForEach(UpdateChannel.allCases) { channel in | ||||||
Text(channel.name).tag(channel) | ||||||
} | ||||||
} | ||||||
HStack { | ||||||
Spacer() | ||||||
Button("Check for updates") { updater.checkForUpdates() }.disabled(!updater.canCheckForUpdates) | ||||||
} | ||||||
} | ||||||
} else { | ||||||
Section { | ||||||
Text("The app updater has been disabled by a device management policy.") | ||||||
CopilotAI |
Text("The app updater has been disabled by a device management policy.") | |
Text("The app updater has been disabled.") |
Copilot uses AI. Check for mistakes.
Uh oh!
There was an error while loading.Please reload this page.