From 095a7cd7664f9f774e3e211094eb0ab8da5ee306 Mon Sep 17 00:00:00 2001 From: Ethan Pippin Date: Sat, 23 Oct 2021 22:25:29 -0600 Subject: [PATCH 1/2] add default scheme and autopopulate scheme --- JellyfinPlayer/Views/BasicAppSettingsView.swift | 11 +++++++++++ JellyfinPlayer/Views/ConnectToServerView.swift | 10 +++++++++- Shared/Objects/HTTPScheme.swift | 16 ++++++++++++++++ Shared/Singleton/SessionManager.swift | 10 +++++++--- Shared/SwiftfinStore/SwiftfinStoreDefaults.swift | 1 + 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 Shared/Objects/HTTPScheme.swift diff --git a/JellyfinPlayer/Views/BasicAppSettingsView.swift b/JellyfinPlayer/Views/BasicAppSettingsView.swift index 286f2163..ed73b75f 100644 --- a/JellyfinPlayer/Views/BasicAppSettingsView.swift +++ b/JellyfinPlayer/Views/BasicAppSettingsView.swift @@ -18,6 +18,7 @@ struct BasicAppSettingsView: View { @State var resetTapped: Bool = false @Default(.appAppearance) var appAppearance + @Default(.defaultHTTPScheme) var defaultHTTPScheme var body: some View { Form { @@ -33,6 +34,16 @@ struct BasicAppSettingsView: View { Text("Accessibility") } + Section { + Picker("Default Scheme", selection: $defaultHTTPScheme) { + ForEach(HTTPScheme.allCases, id: \.self) { scheme in + Text("\(scheme.rawValue)") + } + } + } header: { + Text("Networking") + } + Button { resetTapped = true } label: { diff --git a/JellyfinPlayer/Views/ConnectToServerView.swift b/JellyfinPlayer/Views/ConnectToServerView.swift index eb546920..f44975d6 100644 --- a/JellyfinPlayer/Views/ConnectToServerView.swift +++ b/JellyfinPlayer/Views/ConnectToServerView.swift @@ -6,14 +6,17 @@ * Copyright 2021 Aiden Vigue & Jellyfin Contributors */ -import SwiftUI +import Defaults import Stinsen +import SwiftUI struct ConnectToServerView: View { @StateObject var viewModel: ConnectToServerViewModel @State var uri = "" + @Default(.defaultHTTPScheme) var defaultHTTPScheme + var body: some View { List { Section { @@ -21,6 +24,11 @@ struct ConnectToServerView: View { .disableAutocorrection(true) .autocapitalization(.none) .keyboardType(.URL) + .onAppear { + if uri == "" { + uri = "\(defaultHTTPScheme.rawValue)://" + } + } if viewModel.isLoading { Button(role: .destructive) { diff --git a/Shared/Objects/HTTPScheme.swift b/Shared/Objects/HTTPScheme.swift new file mode 100644 index 00000000..28152234 --- /dev/null +++ b/Shared/Objects/HTTPScheme.swift @@ -0,0 +1,16 @@ +// + /* + * SwiftFin is subject to the terms of the Mozilla Public + * License, v2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * Copyright 2021 Aiden Vigue & Jellyfin Contributors + */ + +import Defaults +import Foundation + +enum HTTPScheme: String, Defaults.Serializable, CaseIterable { + case http + case https +} diff --git a/Shared/Singleton/SessionManager.swift b/Shared/Singleton/SessionManager.swift index d803e8ac..d5fdd1c0 100644 --- a/Shared/Singleton/SessionManager.swift +++ b/Shared/Singleton/SessionManager.swift @@ -58,10 +58,14 @@ final class SessionManager { // Connects to a server at the given uri, storing if successful func connectToServer(with uri: String) -> AnyPublisher { - var uri = uri - if !uri.contains("http") { - uri = "https://" + uri + var uriComponents = URLComponents(string: uri) ?? URLComponents() + + if uriComponents.scheme == nil { + uriComponents.scheme = SwiftfinStore.Defaults.suite[.defaultHTTPScheme].rawValue } + + var uri = uriComponents.string ?? "" + if uri.last == "/" { uri = String(uri.dropLast()) } diff --git a/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift b/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift index 53ce5f84..ab6a28d0 100644 --- a/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift +++ b/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift @@ -23,6 +23,7 @@ extension SwiftfinStore { extension Defaults.Keys { static let lastServerUserID = Defaults.Key("lastServerUserID", suite: SwiftfinStore.Defaults.suite) + static let defaultHTTPScheme = Key("defaultHTTPScheme", default: .http, suite: SwiftfinStore.Defaults.suite) static let inNetworkBandwidth = Key("InNetworkBandwidth", default: 40_000_000, suite: SwiftfinStore.Defaults.suite) static let outOfNetworkBandwidth = Key("OutOfNetworkBandwidth", default: 40_000_000, suite: SwiftfinStore.Defaults.suite) static let isAutoSelectSubtitles = Key("isAutoSelectSubtitles", default: false, suite: SwiftfinStore.Defaults.suite) From 113aa128c7022835a975373bef212ceff2d8c6c8 Mon Sep 17 00:00:00 2001 From: Ethan Pippin Date: Sat, 23 Oct 2021 22:25:58 -0600 Subject: [PATCH 2/2] update pbxproj --- JellyfinPlayer.xcodeproj/project.pbxproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/JellyfinPlayer.xcodeproj/project.pbxproj b/JellyfinPlayer.xcodeproj/project.pbxproj index 191aec31..b29b0224 100644 --- a/JellyfinPlayer.xcodeproj/project.pbxproj +++ b/JellyfinPlayer.xcodeproj/project.pbxproj @@ -290,6 +290,9 @@ E18845F826DEA9C900B0C5B7 /* ItemViewBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18845F726DEA9C900B0C5B7 /* ItemViewBody.swift */; }; E188460026DECB9E00B0C5B7 /* ItemLandscapeTopBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18845FF26DECB9E00B0C5B7 /* ItemLandscapeTopBarView.swift */; }; E188460426DEF04800B0C5B7 /* EpisodeCardVStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E188460326DEF04800B0C5B7 /* EpisodeCardVStackView.swift */; }; + E19169CE272514760085832A /* HTTPScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = E19169CD272514760085832A /* HTTPScheme.swift */; }; + E19169CF272514760085832A /* HTTPScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = E19169CD272514760085832A /* HTTPScheme.swift */; }; + E19169D0272514760085832A /* HTTPScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = E19169CD272514760085832A /* HTTPScheme.swift */; }; E193D4D827193CAC00900D82 /* PortraitImageStackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E193D4D727193CAC00900D82 /* PortraitImageStackable.swift */; }; E193D4D927193CAC00900D82 /* PortraitImageStackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E193D4D727193CAC00900D82 /* PortraitImageStackable.swift */; }; E193D4DB27193CCA00900D82 /* PillStackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E193D4DA27193CCA00900D82 /* PillStackable.swift */; }; @@ -575,6 +578,7 @@ E18845F726DEA9C900B0C5B7 /* ItemViewBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemViewBody.swift; sourceTree = ""; }; E18845FF26DECB9E00B0C5B7 /* ItemLandscapeTopBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemLandscapeTopBarView.swift; sourceTree = ""; }; E188460326DEF04800B0C5B7 /* EpisodeCardVStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EpisodeCardVStackView.swift; sourceTree = ""; }; + E19169CD272514760085832A /* HTTPScheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPScheme.swift; sourceTree = ""; }; E193D4D727193CAC00900D82 /* PortraitImageStackable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortraitImageStackable.swift; sourceTree = ""; }; E193D4DA27193CCA00900D82 /* PillStackable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PillStackable.swift; sourceTree = ""; }; E193D5422719407E00900D82 /* tvOSMainCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = tvOSMainCoordinator.swift; sourceTree = ""; }; @@ -807,6 +811,7 @@ E1AD104926D94822003E4A08 /* DetailItem.swift */, 53192D5C265AA78A008A4215 /* DeviceProfileBuilder.swift */, 62EC353326766B03000E9F2D /* DeviceRotationViewModifier.swift */, + E19169CD272514760085832A /* HTTPScheme.swift */, E193D4DA27193CCA00900D82 /* PillStackable.swift */, E193D4D727193CAC00900D82 /* PortraitImageStackable.swift */, E1D4BF832719D25A00A11E64 /* TrackLanguage.swift */, @@ -1734,6 +1739,7 @@ E193D549271941CC00900D82 /* UserSignInView.swift in Sources */, 535870AA2669D8AE00D05A09 /* BlurHashDecode.swift in Sources */, 53ABFDE5267974EF00886593 /* ViewModel.swift in Sources */, + E19169CF272514760085832A /* HTTPScheme.swift in Sources */, C45B29BB26FAC5B600CEF5E0 /* ColorExtension.swift in Sources */, 531069582684E7EE00CFFDBA /* MediaInfoView.swift in Sources */, E1D4BF822719D22800A11E64 /* AppAppearance.swift in Sources */, @@ -1808,6 +1814,7 @@ E173DA5426D050F500CC4EB7 /* ServerDetailViewModel.swift in Sources */, E188460426DEF04800B0C5B7 /* EpisodeCardVStackView.swift in Sources */, 53F8377D265FF67C00F456B3 /* VideoPlayerSettingsView.swift in Sources */, + E19169CE272514760085832A /* HTTPScheme.swift in Sources */, 53192D5D265AA78A008A4215 /* DeviceProfileBuilder.swift in Sources */, 62133890265F83A900A81A2A /* LibraryListView.swift in Sources */, 62C29EA326D1030F00C1D2E7 /* ConnectToServerCoodinator.swift in Sources */, @@ -1904,6 +1911,7 @@ files = ( 53649AB3269D3F5B00A2D8B7 /* LogManager.swift in Sources */, E13DD3CB27164BA8009D4DAF /* UIDeviceExtensions.swift in Sources */, + E19169D0272514760085832A /* HTTPScheme.swift in Sources */, 6267B3D726710B9700A7371D /* CollectionExtensions.swift in Sources */, 628B953C2670D2430091AF3B /* StringExtensions.swift in Sources */, 6267B3DB2671139400A7371D /* ImageExtensions.swift in Sources */,