Improve layout of Updates/Preferences window

This commit is contained in:
Angelo Stavrow 2020-12-23 14:38:53 -05:00
parent b05938b497
commit 70dfda7ea0
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 53 additions and 36 deletions

View File

@ -103,7 +103,7 @@ struct WriteFreely_MultiPlatformApp: App {
} }
.tag(2) .tag(2)
} }
.frame(minWidth: 300, maxWidth: 300, minHeight: 200, maxHeight: 200) .frame(minWidth: 500, maxWidth: 500, minHeight: 200)
.padding() .padding()
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info. // .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
} }

View File

@ -5,9 +5,7 @@ struct MacAccountView: View {
var body: some View { var body: some View {
Form { Form {
Section(header: Text("Login Details")) {
AccountView() AccountView()
}
} }
} }
} }

View File

@ -1,14 +1,19 @@
import SwiftUI import SwiftUI
import Sparkle import Sparkle
private enum AppcastFeedUrl: String {
case release = "https://files.writefreely.org/apps/mac/appcast.xml"
case beta = "https://files.writefreely.org/apps/mac/appcast-beta.xml"
}
struct MacUpdatesView: View { struct MacUpdatesView: View {
@AppStorage("downloadUpdatesAutomatically") var downloadUpdatesAutomatically: Bool = false @AppStorage("automaticallyChecksForUpdates") var automaticallyChecksForUpdates: Bool = false
@AppStorage("subscribeToBetaUpdates") var subscribeToBetaUpdates: Bool = false @AppStorage("subscribeToBetaUpdates") var subscribeToBetaUpdates: Bool = false
@State private var lastUpdateCheck: Date? @State private var lastUpdateCheck: Date?
private let betaWarningString = """ private let betaWarningString = """
Choose release versions to update to the next stable version of WriteFreely. \ To get brand new features before each official release, choose "Test versions." Note that test versions may have bugs \
Test versions may have bugs that can cause crashes and data loss. that can cause crashes and data loss.
""" """
static let lastUpdateFormatter: DateFormatter = { static let lastUpdateFormatter: DateFormatter = {
@ -20,50 +25,64 @@ Test versions may have bugs that can cause crashes and data loss.
}() }()
var body: some View { var body: some View {
VStack(spacing: 32) { VStack(spacing: 24) {
VStack { Toggle(isOn: $automaticallyChecksForUpdates, label: {
Text(betaWarningString) Text("Check for updates automatically")
.frame(width: 400)
.foregroundColor(Color(NSColor.placeholderTextColor))
Picker(selection: $subscribeToBetaUpdates, label: Text("Download:"), content: {
Text("Release versions").tag(false)
Text("Test versions").tag(true)
})
.pickerStyle(RadioGroupPickerStyle())
}
Button(action: {
SUUpdater.shared()?.checkForUpdates(self)
DispatchQueue.main.async {
lastUpdateCheck = SUUpdater.shared()?.lastUpdateCheckDate
}
}, label: {
Text("Check For Updates")
}) })
VStack { VStack {
Toggle(isOn: $downloadUpdatesAutomatically, label: { Button(action: {
Text("Check for updates automatically") SUUpdater.shared()?.checkForUpdates(self)
DispatchQueue.main.async {
lastUpdateCheck = SUUpdater.shared()?.lastUpdateCheckDate
}
}, label: {
Text("Check For Updates")
}) })
HStack { HStack {
Text("Last check for updates:") Text("Last checked:")
.font(.caption)
if let lastUpdateCheck = lastUpdateCheck {
Text(lastUpdateCheck, formatter: Self.lastUpdateFormatter)
.font(.caption)
} else {
Text("Never")
.font(.caption) .font(.caption)
if let lastUpdateCheck = lastUpdateCheck {
Text(lastUpdateCheck, formatter: Self.lastUpdateFormatter)
.font(.caption)
} else {
Text("Never")
.font(.caption)
}
} }
} }
VStack(spacing: 16) {
HStack(alignment: .top) {
Text("Download:")
Picker(selection: $subscribeToBetaUpdates, label: Text("Download:"), content: {
Text("Release versions").tag(false)
Text("Test versions").tag(true)
})
.pickerStyle(RadioGroupPickerStyle())
.labelsHidden()
}
Text(betaWarningString)
.frame(width: 350)
.foregroundColor(.secondary)
} }
} }
.padding() .padding()
.onAppear { .onAppear {
lastUpdateCheck = SUUpdater.shared()?.lastUpdateCheckDate lastUpdateCheck = SUUpdater.shared()?.lastUpdateCheckDate
} }
.onChange(of: automaticallyChecksForUpdates) { value in
SUUpdater.shared()?.automaticallyChecksForUpdates = value
}
.onChange(of: subscribeToBetaUpdates) { value in
if value {
SUUpdater.shared()?.feedURL = URL(string: AppcastFeedUrl.beta.rawValue)
} else {
SUUpdater.shared()?.feedURL = URL(string: AppcastFeedUrl.release.rawValue)
}
}
} }
} }