Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit095bf83

Browse files
committed
feat: support disabling the built-in updater
1 parentde4b0e5 commit095bf83

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

‎Coder-Desktop/Coder-Desktop/UpdaterService.swift‎

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,64 @@ import Sparkle
22
import SwiftUI
33

44
finalclassUpdaterService:NSObject,ObservableObject{
5-
private lazyvarinner:SPUStandardUpdaterController=.init(
6-
startingUpdater:true,
7-
updaterDelegate:self,
8-
userDriverDelegate:self
9-
)
10-
privatevarupdater:SPUUpdater!
5+
6+
// The auto-updater can be entirely disabled by setting the
7+
// `disableUpdater` UserDefaults key to `true`. This is designed for use in
8+
// MDM configurations, where the value can be set to `true` permanently.
9+
@Publishedvardisabled:Bool=UserDefaults.standard.bool(forKey:Keys.disableUpdater){
10+
didSet{
11+
UserDefaults.standard.set(disabled, forKey:Keys.disableUpdater)
12+
}
13+
}
14+
1115
@PublishedvarcanCheckForUpdates=true
1216

1317
@PublishedvarautoCheckForUpdates:Bool!{
1418
didSet{
1519
iflet autoCheckForUpdates, autoCheckForUpdates!= oldValue{
16-
updater.automaticallyChecksForUpdates= autoCheckForUpdates
20+
inner?.updater.automaticallyChecksForUpdates= autoCheckForUpdates
1721
}
1822
}
1923
}
2024

2125
@PublishedvarupdateChannel:UpdateChannel{
2226
didSet{
23-
UserDefaults.standard.set(updateChannel.rawValue, forKey:Self.updateChannelKey)
27+
UserDefaults.standard.set(updateChannel.rawValue, forKey:Keys.updateChannel)
2428
}
2529
}
30+
privatevarinner:(controller:SPUStandardUpdaterController, updater:SPUUpdater)?
2631

27-
staticletupdateChannelKey="updateChannel"
2832

2933
overrideinit(){
30-
updateChannel=UserDefaults.standard.string(forKey:Self.updateChannelKey)
34+
updateChannel=UserDefaults.standard.string(forKey:Keys.updateChannel)
3135
.flatMap{UpdateChannel(rawValue: $0)}??.stable
3236
super.init()
33-
updater= inner.updater
37+
38+
guard !disabledelse{
39+
return
40+
}
41+
42+
letinner=SPUStandardUpdaterController(
43+
startingUpdater:true,
44+
updaterDelegate:self,
45+
userDriverDelegate:self
46+
)
47+
48+
letupdater= inner.updater
49+
self.inner=(inner, updater)
50+
3451
autoCheckForUpdates= updater.automaticallyChecksForUpdates
3552
updater.publisher(for: \.canCheckForUpdates).assign(to:&$canCheckForUpdates)
3653
}
3754

3855
func checkForUpdates(){
39-
guard canCheckForUpdateselse{return}
40-
updater.checkForUpdates()
56+
guardlet inner, canCheckForUpdateselse{return}
57+
inner.updater.checkForUpdates()
58+
}
59+
60+
enumKeys{
61+
staticletdisableUpdater="disableUpdater"
62+
staticletupdateChannel="updateChannel"
4163
}
4264
}
4365

‎Coder-Desktop/Coder-Desktop/Views/Settings/GeneralTab.swift‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ struct GeneralTab: View {
1919
Text("Start Coder Connect on launch")
2020
}
2121
}
22-
Section{
23-
Toggle(isOn: $updater.autoCheckForUpdates){
24-
Text("Automatically check for updates")
25-
}
26-
Picker("Update channel", selection: $updater.updateChannel){
27-
ForEach(UpdateChannel.allCases){ channelin
28-
Text(channel.name).tag(channel)
22+
if !updater.disabled{
23+
Section{
24+
Toggle(isOn: $updater.autoCheckForUpdates){
25+
Text("Automatically check for updates")
26+
}
27+
Picker("Update channel", selection: $updater.updateChannel){
28+
ForEach(UpdateChannel.allCases){ channelin
29+
Text(channel.name).tag(channel)
30+
}
31+
}
32+
HStack{
33+
Spacer()
34+
Button("Check for updates"){ updater.checkForUpdates()}.disabled(!updater.canCheckForUpdates)
2935
}
30-
}
31-
HStack{
32-
Spacer()
33-
Button("Check for updates"){ updater.checkForUpdates()}.disabled(!updater.canCheckForUpdates)
3436
}
3537
}
3638
}.formStyle(.grouped)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp