From 0d791c094e430240484ee1708a6fcbc5a6ce8161 Mon Sep 17 00:00:00 2001 From: Stephen Byatt <47413006+stephenb10@users.noreply.github.com> Date: Thu, 24 Jun 2021 17:02:39 +1000 Subject: [PATCH] Fix tvOS searching on every launch --- JellyfinPlayer tvOS/ConnectToServerView.swift | 82 ++++++++++--------- JellyfinPlayer.xcodeproj/project.pbxproj | 6 -- .../UDPBroadCastConnection.swift | 27 ++++++ .../UDPBroadcastConnectionError.swift | 34 -------- 4 files changed, 71 insertions(+), 78 deletions(-) delete mode 100644 Shared/ServerLocator/UDPBroadcastConnectionError.swift diff --git a/JellyfinPlayer tvOS/ConnectToServerView.swift b/JellyfinPlayer tvOS/ConnectToServerView.swift index 031968cb..6bda55ec 100644 --- a/JellyfinPlayer tvOS/ConnectToServerView.swift +++ b/JellyfinPlayer tvOS/ConnectToServerView.swift @@ -104,50 +104,56 @@ struct ConnectToServerView: View { } } } else { - Form { - Section(header: Text("Server Information")) { - TextField("Jellyfin Server URL", text: $uri) - .disableAutocorrection(true) - .autocapitalization(.none) - Button { - viewModel.connectToServer() - } label: { - HStack { - Text("Connect") - Spacer() + if !viewModel.isLoading { + + Form { + Section(header: Text("Server Information")) { + TextField("Jellyfin Server URL", text: $uri) + .disableAutocorrection(true) + .autocapitalization(.none) + Button { + viewModel.connectToServer() + } label: { + HStack { + Text("Connect") + Spacer() + } + if viewModel.isLoading { + ProgressView() + } } - if viewModel.isLoading { + .disabled(viewModel.isLoading || uri.isEmpty) + } + Section(header: Text("Local Servers")) { + if self.viewModel.searching { ProgressView() } - } - .disabled(viewModel.isLoading || uri.isEmpty) - } - Section(header: Text("Local Servers")) { - if self.viewModel.searching { - ProgressView() - } - ForEach(self.viewModel.servers, id: \.id) { server in - Button(action: { - print(server.url) - viewModel.connectToServer(at: server.url) - }, label: { - HStack { - VStack { - Text(server.name) - .font(.headline) - Text(server.host) - .font(.subheadline) - } - Spacer() - if viewModel.isLoading { - ProgressView() + ForEach(self.viewModel.servers, id: \.id) { server in + Button(action: { + print(server.url) + viewModel.connectToServer(at: server.url) + }, label: { + HStack { + VStack(alignment: .leading) { + Text(server.name) + .font(.headline) + Text(server.host) + .font(.subheadline) + } + Spacer() + Image(systemName: "chevron.forward") + .padding() } - } - - }) + + }) + .disabled(viewModel.isLoading) + } } + .onAppear(perform: self.viewModel.discoverServers) } - .onAppear(perform: self.viewModel.discoverServers) + } + else { + ProgressView() } } } diff --git a/JellyfinPlayer.xcodeproj/project.pbxproj b/JellyfinPlayer.xcodeproj/project.pbxproj index ea5c7d25..41e69b26 100644 --- a/JellyfinPlayer.xcodeproj/project.pbxproj +++ b/JellyfinPlayer.xcodeproj/project.pbxproj @@ -7,10 +7,8 @@ objects = { /* Begin PBXBuildFile section */ - 091B5A892683142E00D78B61 /* UDPBroadcastConnectionError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A862683142E00D78B61 /* UDPBroadcastConnectionError.swift */; }; 091B5A8A2683142E00D78B61 /* ServerDiscovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A872683142E00D78B61 /* ServerDiscovery.swift */; }; 091B5A8B2683142E00D78B61 /* UDPBroadCastConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A882683142E00D78B61 /* UDPBroadCastConnection.swift */; }; - 091B5A8C268315D400D78B61 /* UDPBroadcastConnectionError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A862683142E00D78B61 /* UDPBroadcastConnectionError.swift */; }; 091B5A8D268315D400D78B61 /* ServerDiscovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A872683142E00D78B61 /* ServerDiscovery.swift */; }; 091B5A8E268315D400D78B61 /* UDPBroadCastConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A882683142E00D78B61 /* UDPBroadCastConnection.swift */; }; 531690E5267ABD5C005D8AB9 /* MainTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 531690E4267ABD5C005D8AB9 /* MainTabView.swift */; }; @@ -187,7 +185,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 091B5A862683142E00D78B61 /* UDPBroadcastConnectionError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UDPBroadcastConnectionError.swift; sourceTree = ""; }; 091B5A872683142E00D78B61 /* ServerDiscovery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerDiscovery.swift; sourceTree = ""; }; 091B5A882683142E00D78B61 /* UDPBroadCastConnection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UDPBroadCastConnection.swift; sourceTree = ""; }; 3773C07648173CE7FEC083D5 /* Pods-JellyfinPlayer iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JellyfinPlayer iOS.debug.xcconfig"; path = "Target Support Files/Pods-JellyfinPlayer iOS/Pods-JellyfinPlayer iOS.debug.xcconfig"; sourceTree = ""; }; @@ -357,7 +354,6 @@ 091B5A852683142E00D78B61 /* ServerLocator */ = { isa = PBXGroup; children = ( - 091B5A862683142E00D78B61 /* UDPBroadcastConnectionError.swift */, 091B5A872683142E00D78B61 /* ServerDiscovery.swift */, 091B5A882683142E00D78B61 /* UDPBroadCastConnection.swift */, ); @@ -884,7 +880,6 @@ 531690E7267ABD79005D8AB9 /* HomeView.swift in Sources */, 53ABFDDE267974E300886593 /* SplashView.swift in Sources */, 53ABFDE8267974EF00886593 /* SplashViewModel.swift in Sources */, - 091B5A8C268315D400D78B61 /* UDPBroadcastConnectionError.swift in Sources */, 62E632DE267D2E170063E547 /* LatestMediaViewModel.swift in Sources */, 536D3D88267C17350004248C /* PublicUserButton.swift in Sources */, 62E632EA267D3FF50063E547 /* SeasonItemViewModel.swift in Sources */, @@ -948,7 +943,6 @@ 53F8377D265FF67C00F456B3 /* VideoPlayerSettingsView.swift in Sources */, 53192D5D265AA78A008A4215 /* DeviceProfileBuilder.swift in Sources */, 62133890265F83A900A81A2A /* LibraryListView.swift in Sources */, - 091B5A892683142E00D78B61 /* UDPBroadcastConnectionError.swift in Sources */, 62E632DA267D2BC40063E547 /* LatestMediaViewModel.swift in Sources */, 625CB56F2678C23300530A6E /* HomeView.swift in Sources */, 53892770263C25230035E14B /* NextUpView.swift in Sources */, diff --git a/Shared/ServerLocator/UDPBroadCastConnection.swift b/Shared/ServerLocator/UDPBroadCastConnection.swift index f30973dc..6df50bd0 100644 --- a/Shared/ServerLocator/UDPBroadCastConnection.swift +++ b/Shared/ServerLocator/UDPBroadCastConnection.swift @@ -298,3 +298,30 @@ open class UDPBroadcastConnection { +// Created by Gunter Hager on 25.03.19. +// Copyright © 2019 Gunter Hager. All rights reserved. +// +public extension UDPBroadcastConnection { + + enum ConnectionError: Error { + // Creating socket + case createSocketFailed + case enableBroadcastFailed + case bindSocketFailed + + // Sending message + case messageEncodingFailed + case sendingMessageFailed(code: Int32) + + // Receiving data + case receivedEndOfFile + case receiveFailed(code: Int32) + + // Closing socket + case reopeningSocketFailed(error: Error) + + // Underlying + case underlying(error: Error) + } + +} diff --git a/Shared/ServerLocator/UDPBroadcastConnectionError.swift b/Shared/ServerLocator/UDPBroadcastConnectionError.swift deleted file mode 100644 index 29c9dd3b..00000000 --- a/Shared/ServerLocator/UDPBroadcastConnectionError.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// UDPBroadcastConnectionError.swift -// UDPBroadcast -// -// Created by Gunter Hager on 25.03.19. -// Copyright © 2019 Gunter Hager. All rights reserved. -// - -import Foundation - -public extension UDPBroadcastConnection { - - enum ConnectionError: Error { - // Creating socket - case createSocketFailed - case enableBroadcastFailed - case bindSocketFailed - - // Sending message - case messageEncodingFailed - case sendingMessageFailed(code: Int32) - - // Receiving data - case receivedEndOfFile - case receiveFailed(code: Int32) - - // Closing socket - case reopeningSocketFailed(error: Error) - - // Underlying - case underlying(error: Error) - } - -}