mirror of
https://github.com/jellyfin/Swiftfin.git
synced 2025-02-25 01:31:32 +00:00
add default scheme and autopopulate scheme
This commit is contained in:
parent
a06ceb7453
commit
095a7cd766
@ -18,6 +18,7 @@ struct BasicAppSettingsView: View {
|
|||||||
@State var resetTapped: Bool = false
|
@State var resetTapped: Bool = false
|
||||||
|
|
||||||
@Default(.appAppearance) var appAppearance
|
@Default(.appAppearance) var appAppearance
|
||||||
|
@Default(.defaultHTTPScheme) var defaultHTTPScheme
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
@ -33,6 +34,16 @@ struct BasicAppSettingsView: View {
|
|||||||
Text("Accessibility")
|
Text("Accessibility")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Section {
|
||||||
|
Picker("Default Scheme", selection: $defaultHTTPScheme) {
|
||||||
|
ForEach(HTTPScheme.allCases, id: \.self) { scheme in
|
||||||
|
Text("\(scheme.rawValue)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
Text("Networking")
|
||||||
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
resetTapped = true
|
resetTapped = true
|
||||||
} label: {
|
} label: {
|
||||||
|
@ -6,14 +6,17 @@
|
|||||||
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
|
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import SwiftUI
|
import Defaults
|
||||||
import Stinsen
|
import Stinsen
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
struct ConnectToServerView: View {
|
struct ConnectToServerView: View {
|
||||||
|
|
||||||
@StateObject var viewModel: ConnectToServerViewModel
|
@StateObject var viewModel: ConnectToServerViewModel
|
||||||
@State var uri = ""
|
@State var uri = ""
|
||||||
|
|
||||||
|
@Default(.defaultHTTPScheme) var defaultHTTPScheme
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
Section {
|
Section {
|
||||||
@ -21,6 +24,11 @@ struct ConnectToServerView: View {
|
|||||||
.disableAutocorrection(true)
|
.disableAutocorrection(true)
|
||||||
.autocapitalization(.none)
|
.autocapitalization(.none)
|
||||||
.keyboardType(.URL)
|
.keyboardType(.URL)
|
||||||
|
.onAppear {
|
||||||
|
if uri == "" {
|
||||||
|
uri = "\(defaultHTTPScheme.rawValue)://"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if viewModel.isLoading {
|
if viewModel.isLoading {
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
|
16
Shared/Objects/HTTPScheme.swift
Normal file
16
Shared/Objects/HTTPScheme.swift
Normal file
@ -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
|
||||||
|
}
|
@ -58,10 +58,14 @@ final class SessionManager {
|
|||||||
|
|
||||||
// Connects to a server at the given uri, storing if successful
|
// Connects to a server at the given uri, storing if successful
|
||||||
func connectToServer(with uri: String) -> AnyPublisher<SwiftfinStore.State.Server, Error> {
|
func connectToServer(with uri: String) -> AnyPublisher<SwiftfinStore.State.Server, Error> {
|
||||||
var uri = uri
|
var uriComponents = URLComponents(string: uri) ?? URLComponents()
|
||||||
if !uri.contains("http") {
|
|
||||||
uri = "https://" + uri
|
if uriComponents.scheme == nil {
|
||||||
|
uriComponents.scheme = SwiftfinStore.Defaults.suite[.defaultHTTPScheme].rawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var uri = uriComponents.string ?? ""
|
||||||
|
|
||||||
if uri.last == "/" {
|
if uri.last == "/" {
|
||||||
uri = String(uri.dropLast())
|
uri = String(uri.dropLast())
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ extension SwiftfinStore {
|
|||||||
extension Defaults.Keys {
|
extension Defaults.Keys {
|
||||||
static let lastServerUserID = Defaults.Key<String?>("lastServerUserID", suite: SwiftfinStore.Defaults.suite)
|
static let lastServerUserID = Defaults.Key<String?>("lastServerUserID", suite: SwiftfinStore.Defaults.suite)
|
||||||
|
|
||||||
|
static let defaultHTTPScheme = Key<HTTPScheme>("defaultHTTPScheme", default: .http, suite: SwiftfinStore.Defaults.suite)
|
||||||
static let inNetworkBandwidth = Key<Int>("InNetworkBandwidth", default: 40_000_000, suite: SwiftfinStore.Defaults.suite)
|
static let inNetworkBandwidth = Key<Int>("InNetworkBandwidth", default: 40_000_000, suite: SwiftfinStore.Defaults.suite)
|
||||||
static let outOfNetworkBandwidth = Key<Int>("OutOfNetworkBandwidth", default: 40_000_000, suite: SwiftfinStore.Defaults.suite)
|
static let outOfNetworkBandwidth = Key<Int>("OutOfNetworkBandwidth", default: 40_000_000, suite: SwiftfinStore.Defaults.suite)
|
||||||
static let isAutoSelectSubtitles = Key<Bool>("isAutoSelectSubtitles", default: false, suite: SwiftfinStore.Defaults.suite)
|
static let isAutoSelectSubtitles = Key<Bool>("isAutoSelectSubtitles", default: false, suite: SwiftfinStore.Defaults.suite)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user