Updates PreferencesView To use built in Settings Scene

This commit is contained in:
Matt Kiazyk 2021-01-26 22:45:43 -06:00
parent a4a83deae5
commit 202212f417
No known key found for this signature in database
GPG key ID: 967DBC53389132D7
6 changed files with 43 additions and 51 deletions

View file

@ -100,6 +100,7 @@
CAFE4AB425B7D3AF0064FE51 /* AdvancedPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFE4AB325B7D3AF0064FE51 /* AdvancedPreferencePane.swift */; };
CAFE4ABC25B7D54B0064FE51 /* UpdatesPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFE4ABB25B7D54B0064FE51 /* UpdatesPreferencePane.swift */; };
CAFFFED8259CDA5000903F81 /* XcodeListViewRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFFFED7259CDA5000903F81 /* XcodeListViewRow.swift */; };
E8977EA325C11E1500835F80 /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8977EA225C11E1500835F80 /* PreferencesView.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -260,6 +261,7 @@
CAFE4ABB25B7D54B0064FE51 /* UpdatesPreferencePane.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatesPreferencePane.swift; sourceTree = "<group>"; };
CAFFFED7259CDA5000903F81 /* XcodeListViewRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeListViewRow.swift; sourceTree = "<group>"; };
CAFFFEEE259CEAC400903F81 /* RingProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RingProgressViewStyle.swift; sourceTree = "<group>"; };
E8977EA225C11E1500835F80 /* PreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -542,6 +544,7 @@
CAFE4AB325B7D3AF0064FE51 /* AdvancedPreferencePane.swift */,
CAFE4AAB25B7D2C70064FE51 /* GeneralPreferencePane.swift */,
CAFE4ABB25B7D54B0064FE51 /* UpdatesPreferencePane.swift */,
E8977EA225C11E1500835F80 /* PreferencesView.swift */,
);
path = Preferences;
sourceTree = "<group>";
@ -794,6 +797,7 @@
CAE424B4259A764700B8B246 /* AppState+Install.swift in Sources */,
CAE42487259A68A300B8B246 /* XcodeListCategory.swift in Sources */,
CAA858C425A2BE4E00ACF8C0 /* Downloader.swift in Sources */,
E8977EA325C11E1500835F80 /* PreferencesView.swift in Sources */,
CA9FF87B2595293E00E47BAF /* DataSource.swift in Sources */,
CABFA9C92592EEEA00380FEE /* URLRequest+Apple.swift in Sources */,
CABFAA432593104F00380FEE /* AboutView.swift in Sources */,

View file

@ -2,10 +2,6 @@ import AppleAPI
import Preferences
import SwiftUI
extension Preferences.PaneIdentifier {
static let advanced = Self("advanced")
}
struct AdvancedPreferencePane: View {
@EnvironmentObject var appState: AppState
@AppStorage("dataSource") var dataSource: DataSource = .xcodeReleases

View file

@ -2,13 +2,9 @@ import AppleAPI
import Preferences
import SwiftUI
extension Preferences.PaneIdentifier {
static let general = Self("general")
}
struct GeneralPreferencePane: View {
@EnvironmentObject var appState: AppState
var body: some View {
Preferences.Container(contentWidth: 400.0) {
Preferences.Section(title: "Apple ID") {

View file

@ -0,0 +1,31 @@
import SwiftUI
struct PreferencesView: View {
private enum Tabs: Hashable {
case general, updates, advanced
}
@EnvironmentObject var appState: AppState
var body: some View {
TabView {
GeneralPreferencePane()
.environmentObject(appState)
.tabItem {
Label("General", systemImage: "gearshape")
}
.tag(Tabs.general)
UpdatesPreferencePane()
.tabItem {
Label("Updates", systemImage: "arrow.triangle.2.circlepath.circle")
}
.tag(Tabs.updates)
AdvancedPreferencePane()
.environmentObject(appState)
.tabItem {
Label("Advanced", systemImage: "gearshape.2")
}
.tag(Tabs.advanced)
}
.padding(20)
}
}

View file

@ -3,10 +3,6 @@ import Preferences
import Sparkle
import SwiftUI
extension Preferences.PaneIdentifier {
static let updates = Self("updates")
}
struct UpdatesPreferencePane: View {
@StateObject var updater = ObservableUpdater()

View file

@ -36,13 +36,7 @@ struct XcodesApp: App {
appDelegate.checkForUpdates()
}
}
CommandGroup(replacing: .appSettings) {
Button("Preferences...") {
showPreferencesWindow()
}
.keyboardShortcut(KeyEquivalent(","), modifiers: .command)
}
CommandGroup(after: CommandGroupPlacement.newItem) {
Button("Refresh") {
appState.update()
@ -72,37 +66,12 @@ struct XcodesApp: App {
}
}
}
}
private func showPreferencesWindow() {
PreferencesWindowController(
panes: [
Preferences.Pane(
identifier: .general,
title: "General",
toolbarIcon: NSImage(systemSymbolName: "gearshape", accessibilityDescription: "General")!
) {
GeneralPreferencePane()
.environmentObject(appState)
},
Preferences.Pane(
identifier: .updates,
title: "Updates",
toolbarIcon: NSImage(systemSymbolName: "arrow.triangle.2.circlepath.circle", accessibilityDescription: "Updates")!
) {
UpdatesPreferencePane()
},
Preferences.Pane(
identifier: .advanced,
title: "Advanced",
toolbarIcon: NSImage(systemSymbolName: "gearshape.2", accessibilityDescription: "Advanced")!
) {
AdvancedPreferencePane()
.environmentObject(appState)
},
]
)
.show()
#if os(macOS)
Settings {
PreferencesView()
.environmentObject(appState)
}
#endif
}
}