diff --git a/Shared/WriteFreely_MultiPlatformApp.swift b/Shared/WriteFreely_MultiPlatformApp.swift index 7e1e0a9..f544e74 100644 --- a/Shared/WriteFreely_MultiPlatformApp.swift +++ b/Shared/WriteFreely_MultiPlatformApp.swift @@ -47,7 +47,6 @@ struct WriteFreely_MultiPlatformApp: App { #if os(macOS) CommandGroup(after: .appInfo, addition: { Button("Check For Updates") { - print("Checking for updates!") SUUpdater.shared()?.checkForUpdates(self) } }) @@ -97,6 +96,12 @@ struct WriteFreely_MultiPlatformApp: App { Text("Preferences") } .tag(1) + MacUpdatesView() + .tabItem { + Image(systemName: "arrow.down.circle") + Text("Updates") + } + .tag(2) } .frame(minWidth: 300, maxWidth: 300, minHeight: 200, maxHeight: 200) .padding() diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index 64bd458..cc0f2c2 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 17120DB224E1E19C002B9F6C /* SettingsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17120DB124E1E19C002B9F6C /* SettingsHeaderView.swift */; }; 171BFDFA24D4AF8300888236 /* CollectionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BFDF924D4AF8300888236 /* CollectionListView.swift */; }; 171BFDFB24D4AF8300888236 /* CollectionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BFDF924D4AF8300888236 /* CollectionListView.swift */; }; + 172C492E2593981900E20ADF /* MacUpdatesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172C492D2593981900E20ADF /* MacUpdatesView.swift */; }; 173E19D1254318F600440F0F /* RemoteChangePromptView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173E19D0254318F600440F0F /* RemoteChangePromptView.swift */; }; 173E19E3254329CC00440F0F /* PostTextEditingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173E19E2254329CC00440F0F /* PostTextEditingView.swift */; }; 17466626256C0D0600629997 /* MacEditorTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17466625256C0D0600629997 /* MacEditorTextView.swift */; }; @@ -127,6 +128,7 @@ 17120DAB24E1B99F002B9F6C /* AccountLoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountLoginView.swift; sourceTree = ""; }; 17120DB124E1E19C002B9F6C /* SettingsHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsHeaderView.swift; sourceTree = ""; }; 171BFDF924D4AF8300888236 /* CollectionListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionListView.swift; sourceTree = ""; }; + 172C492D2593981900E20ADF /* MacUpdatesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacUpdatesView.swift; sourceTree = ""; }; 173E19D0254318F600440F0F /* RemoteChangePromptView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteChangePromptView.swift; sourceTree = ""; }; 173E19E2254329CC00440F0F /* PostTextEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostTextEditingView.swift; sourceTree = ""; }; 17466625256C0D0600629997 /* MacEditorTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacEditorTextView.swift; sourceTree = ""; }; @@ -302,6 +304,7 @@ children = ( 17A5388724DDA31F00DEFF9A /* MacAccountView.swift */, 1753F6AB24E431CC00309365 /* MacPreferencesView.swift */, + 172C492D2593981900E20ADF /* MacUpdatesView.swift */, ); path = Settings; sourceTree = ""; @@ -771,6 +774,7 @@ 17D435E924E3128F0036B539 /* PreferencesModel.swift in Sources */, 17120DAA24E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */, 17DF32D624C8CA3400BCE2E3 /* PostStatusBadgeView.swift in Sources */, + 172C492E2593981900E20ADF /* MacUpdatesView.swift in Sources */, 17479F152583D8E40072B7FB /* PostEditorSharingPicker.swift in Sources */, 17480CA6251272EE00EB7765 /* Bundle+AppVersion.swift in Sources */, 17C42E662509237800072984 /* PostListFilteredView.swift in Sources */, diff --git a/macOS/Settings/MacUpdatesView.swift b/macOS/Settings/MacUpdatesView.swift new file mode 100644 index 0000000..b94122d --- /dev/null +++ b/macOS/Settings/MacUpdatesView.swift @@ -0,0 +1,74 @@ +import SwiftUI +import Sparkle + +struct MacUpdatesView: View { + @AppStorage("downloadUpdatesAutomatically") var downloadUpdatesAutomatically: Bool = false + @AppStorage("subscribeToBetaUpdates") var subscribeToBetaUpdates: Bool = false + @State private var lastUpdateCheck: Date? + + private let betaWarningString = """ +Choose release versions to update to the next stable version of WriteFreely. \ +Test versions may have bugs that can cause crashes and data loss. +""" + + static let lastUpdateFormatter: DateFormatter = { + let formatter = DateFormatter() + formatter.dateStyle = .short + formatter.timeStyle = .short + formatter.doesRelativeDateFormatting = true + return formatter + }() + + var body: some View { + VStack(spacing: 32) { + VStack { + Text(betaWarningString) + .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 { + Toggle(isOn: $downloadUpdatesAutomatically, label: { + Text("Check for updates automatically") + }) + + HStack { + Text("Last check for updates:") + .font(.caption) + if let lastUpdateCheck = lastUpdateCheck { + Text(lastUpdateCheck, formatter: Self.lastUpdateFormatter) + .font(.caption) + } else { + Text("Never") + .font(.caption) + } + } + } + } + .padding() + .onAppear { + lastUpdateCheck = SUUpdater.shared()?.lastUpdateCheckDate + } + } +} + +struct MacUpdatesView_Previews: PreviewProvider { + static var previews: some View { + MacUpdatesView() + } +}