From 0e7deed1c676d9ea1f1e2e668474f4c77fd69d20 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Wed, 5 Oct 2022 21:06:02 +0200 Subject: [PATCH] move download settings to own PreferencePane --- .../Preferences/AdvancedPreferencePane.swift | 78 ++---------------- .../Preferences/DownloadPreferencePane.swift | 82 +++++++++++++++++++ .../Preferences/PreferencesView.swift | 5 ++ 3 files changed, 96 insertions(+), 69 deletions(-) create mode 100644 Xcodes/Frontend/Preferences/DownloadPreferencePane.swift diff --git a/Xcodes/Frontend/Preferences/AdvancedPreferencePane.swift b/Xcodes/Frontend/Preferences/AdvancedPreferencePane.swift index c908460..439f55a 100644 --- a/Xcodes/Frontend/Preferences/AdvancedPreferencePane.swift +++ b/Xcodes/Frontend/Preferences/AdvancedPreferencePane.swift @@ -4,19 +4,16 @@ import Path struct AdvancedPreferencePane: View { @EnvironmentObject var appState: AppState - - @AppStorage("dataSource") var dataSource: DataSource = .xcodeReleases - @AppStorage("downloader") var downloader: Downloader = .aria2 var body: some View { VStack(alignment: .leading, spacing: 20) { - + GroupBox(label: Text("InstallDirectory")) { VStack(alignment: .leading) { HStack(alignment: .top, spacing: 5) { Text(appState.installPath).font(.footnote) - .fixedSize(horizontal: false, vertical: true) - .lineLimit(2) + .fixedSize(horizontal: false, vertical: true) + .lineLimit(2) Button(action: { appState.reveal(path: appState.installPath) }) { Image(systemName: "arrow.right.circle.fill") } @@ -34,7 +31,7 @@ struct AdvancedPreferencePane: View { panel.directoryURL = URL(fileURLWithPath: appState.installPath) if panel.runModal() == .OK { - + guard let pathURL = panel.url, let path = Path(url: pathURL) else { return } self.appState.installPath = path.string } @@ -50,8 +47,8 @@ struct AdvancedPreferencePane: View { VStack(alignment: .leading) { HStack(alignment: .top, spacing: 5) { Text(appState.localPath).font(.footnote) - .fixedSize(horizontal: false, vertical: true) - .lineLimit(2) + .fixedSize(horizontal: false, vertical: true) + .lineLimit(2) Button(action: { appState.reveal(path: appState.localPath) }) { Image(systemName: "arrow.right.circle.fill") } @@ -69,7 +66,7 @@ struct AdvancedPreferencePane: View { panel.directoryURL = URL(fileURLWithPath: appState.localPath) if panel.runModal() == .OK { - + guard let pathURL = panel.url, let path = Path(url: pathURL) else { return } self.appState.localPath = path.string } @@ -102,44 +99,13 @@ struct AdvancedPreferencePane: View { Toggle("AutomaticallyCreateSymbolicLink", isOn: $appState.createSymLinkOnSelect) .disabled(appState.createSymLinkOnSelectDisabled) Text("AutomaticallyCreateSymbolicLinkDescription") - .font(.footnote) - .fixedSize(horizontal: false, vertical: true) + .font(.footnote) + .fixedSize(horizontal: false, vertical: true) } .fixedSize(horizontal: false, vertical: true) } .groupBoxStyle(PreferencesGroupBoxStyle()) - GroupBox(label: Text("DataSource")) { - VStack(alignment: .leading) { - Picker("DataSource", selection: $dataSource) { - ForEach(DataSource.allCases) { dataSource in - Text(dataSource.description) - .tag(dataSource) - } - } - .labelsHidden() - - AttributedText(dataSourceFootnote) - } - - } - .groupBoxStyle(PreferencesGroupBoxStyle()) - - GroupBox(label: Text("Downloader")) { - VStack(alignment: .leading) { - Picker("Downloader", selection: $downloader) { - ForEach(Downloader.allCases) { downloader in - Text(downloader.description) - .tag(downloader) - } - } - .labelsHidden() - - AttributedText(downloaderFootnote) - } - - } - .groupBoxStyle(PreferencesGroupBoxStyle()) GroupBox(label: Text("PrivilegedHelper")) { VStack(alignment: .leading, spacing: 8) { @@ -168,32 +134,6 @@ struct AdvancedPreferencePane: View { .groupBoxStyle(PreferencesGroupBoxStyle()) } } - - private var dataSourceFootnote: NSAttributedString { - let string = localizeString("DataSourceDescription") - let attributedString = NSMutableAttributedString( - string: string, - attributes: [ - .font: NSFont.preferredFont(forTextStyle: .footnote, options: [:]), - .foregroundColor: NSColor.labelColor - ] - ) - attributedString.addAttribute(.link, value: URL(string: "https://xcodereleases.com")!, range: NSRange(string.range(of: "Xcode Releases")!, in: string)) - return attributedString - } - - private var downloaderFootnote: NSAttributedString { - let string = localizeString("DownloaderDescription") - let attributedString = NSMutableAttributedString( - string: string, - attributes: [ - .font: NSFont.preferredFont(forTextStyle: .footnote, options: [:]), - .foregroundColor: NSColor.labelColor - ] - ) - attributedString.addAttribute(.link, value: URL(string: "https://github.com/aria2/aria2")!, range: NSRange(string.range(of: "aria2")!, in: string)) - return attributedString - } } struct AdvancedPreferencePane_Previews: PreviewProvider { diff --git a/Xcodes/Frontend/Preferences/DownloadPreferencePane.swift b/Xcodes/Frontend/Preferences/DownloadPreferencePane.swift new file mode 100644 index 0000000..e453dc2 --- /dev/null +++ b/Xcodes/Frontend/Preferences/DownloadPreferencePane.swift @@ -0,0 +1,82 @@ +import AppleAPI +import SwiftUI + +struct DownloadPreferencePane: View { + @EnvironmentObject var appState: AppState + + @AppStorage("dataSource") var dataSource: DataSource = .xcodeReleases + @AppStorage("downloader") var downloader: Downloader = .aria2 + + var body: some View { + VStack(alignment: .leading) { + GroupBox(label: Text("DataSource")) { + VStack(alignment: .leading) { + Picker("DataSource", selection: $dataSource) { + ForEach(DataSource.allCases) { dataSource in + Text(dataSource.description) + .tag(dataSource) + } + } + .labelsHidden() + + AttributedText(dataSourceFootnote) + } + + } + .groupBoxStyle(PreferencesGroupBoxStyle()) + + GroupBox(label: Text("Downloader")) { + VStack(alignment: .leading) { + Picker("Downloader", selection: $downloader) { + ForEach(Downloader.allCases) { downloader in + Text(downloader.description) + .tag(downloader) + } + } + .labelsHidden() + + AttributedText(downloaderFootnote) + } + + } + .groupBoxStyle(PreferencesGroupBoxStyle()) + + } + } + + private var dataSourceFootnote: NSAttributedString { + let string = localizeString("DataSourceDescription") + let attributedString = NSMutableAttributedString( + string: string, + attributes: [ + .font: NSFont.preferredFont(forTextStyle: .footnote, options: [:]), + .foregroundColor: NSColor.labelColor + ] + ) + attributedString.addAttribute(.link, value: URL(string: "https://xcodereleases.com")!, range: NSRange(string.range(of: "Xcode Releases")!, in: string)) + return attributedString + } + + private var downloaderFootnote: NSAttributedString { + let string = localizeString("DownloaderDescription") + let attributedString = NSMutableAttributedString( + string: string, + attributes: [ + .font: NSFont.preferredFont(forTextStyle: .footnote, options: [:]), + .foregroundColor: NSColor.labelColor + ] + ) + attributedString.addAttribute(.link, value: URL(string: "https://github.com/aria2/aria2")!, range: NSRange(string.range(of: "aria2")!, in: string)) + return attributedString + } +} + +struct DownloadPreferencePane_Previews: PreviewProvider { + static var previews: some View { + Group { + GeneralPreferencePane() + .environmentObject(AppState()) + .frame(maxWidth: 500) + } + } +} diff --git a/Xcodes/Frontend/Preferences/PreferencesView.swift b/Xcodes/Frontend/Preferences/PreferencesView.swift index 7442236..83ab775 100644 --- a/Xcodes/Frontend/Preferences/PreferencesView.swift +++ b/Xcodes/Frontend/Preferences/PreferencesView.swift @@ -21,6 +21,11 @@ struct PreferencesView: View { Label("Updates", systemImage: "arrow.triangle.2.circlepath.circle") } .tag(Tabs.updates) + DownloadPreferencePane() + .environmentObject(appState) + .tabItem { + Label("Downloads", systemImage: "icloud.and.arrow.down") + } AdvancedPreferencePane() .environmentObject(appState) .tabItem {