From d10c8159b1a93cf1d4092490941d9a190a967a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Pantale=C3=A3o=20Gon=C3=A7alves?= <5808343+bgoncal@users.noreply.github.com> Date: Fri, 7 Feb 2025 12:41:47 +0100 Subject: [PATCH] Revert "Adding back warning about internal URL usage (#3341)" This reverts commit 73ca0102fc88c9f70f5791512dd7603065aa16c3. --- .../ConnectionSettingsViewController.swift | 3 +- .../ConnectionURLViewController.swift | 61 ++++++++++--------- Sources/Shared/API/ConnectionInfo.swift | 25 +++++--- Tests/Shared/ConnectionInfo.test.swift | 4 ++ 4 files changed, 56 insertions(+), 37 deletions(-) diff --git a/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift b/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift index c02c9b786..3896cd064 100644 --- a/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift +++ b/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift @@ -156,7 +156,8 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType row.displayValueFor = { [server] _ in if server.info.connection.internalSSIDs?.isEmpty ?? true, server.info.connection.internalHardwareAddresses?.isEmpty ?? true, - !server.info.connection.alwaysFallbackToInternalURL { + !server.info.connection.alwaysFallbackToInternalURL, + !ConnectionInfo.shouldFallbackToInternalURL { return "‼️ \(L10n.Settings.ConnectionSection.InternalBaseUrl.RequiresSetup.title)" } else { return server.info.connection.address(for: .internal)?.absoluteString ?? "—" diff --git a/Sources/App/Settings/Connection/ConnectionURLViewController.swift b/Sources/App/Settings/Connection/ConnectionURLViewController.swift index 25bd1a75e..40b2641a2 100644 --- a/Sources/App/Settings/Connection/ConnectionURLViewController.swift +++ b/Sources/App/Settings/Connection/ConnectionURLViewController.swift @@ -232,7 +232,8 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle $0.tag = RowTag.internalURLWarning.rawValue if server.info.connection.internalSSIDs?.isEmpty ?? true, server.info.connection.internalHardwareAddresses?.isEmpty ?? true, - !server.info.connection.alwaysFallbackToInternalURL { + !server.info.connection.alwaysFallbackToInternalURL, + !ConnectionInfo.shouldFallbackToInternalURL { #if targetEnvironment(macCatalyst) $0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidBssidRequired.title #else @@ -296,39 +297,41 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle } } - form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer) - <<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) { - $0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title - $0.value = server.info.connection.alwaysFallbackToInternalURL + if !ConnectionInfo.shouldFallbackToInternalURL { + form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer) + <<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) { + $0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title + $0.value = server.info.connection.alwaysFallbackToInternalURL - $0.cellUpdate { cell, _ in - cell.switchControl.onTintColor = .red - } + $0.cellUpdate { cell, _ in + cell.switchControl.onTintColor = .red + } - $0.onChange { [weak self] row in - if row.value ?? false { - let alert = UIAlertController( - title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title, - message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message, - preferredStyle: .alert - ) - alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in - self?.server.info.connection.alwaysFallbackToInternalURL = false - row.value = false - row.cellUpdate { _, row in + $0.onChange { [weak self] row in + if row.value ?? false { + let alert = UIAlertController( + title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title, + message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message, + preferredStyle: .alert + ) + alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in + self?.server.info.connection.alwaysFallbackToInternalURL = false row.value = false - } - row.reload() - })) - alert.addAction(UIAlertAction( - title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation - .confirmButton, - style: .destructive - )) - self?.present(alert, animated: true) + row.cellUpdate { _, row in + row.value = false + } + row.reload() + })) + alert.addAction(UIAlertAction( + title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation + .confirmButton, + style: .destructive + )) + self?.present(alert, animated: true) + } } } - } + } } private func locationPermissionSection() -> Section { diff --git a/Sources/Shared/API/ConnectionInfo.swift b/Sources/Shared/API/ConnectionInfo.swift index 7882cabcc..a5917c3a8 100644 --- a/Sources/Shared/API/ConnectionInfo.swift +++ b/Sources/Shared/API/ConnectionInfo.swift @@ -6,6 +6,11 @@ import Communicator #endif public struct ConnectionInfo: Codable, Equatable { + // TODO: Remove when location permission enforcement is in place + /// Developer toggle used while enforcement of location permision is not ready + /// Used as feature toggle + public static var shouldFallbackToInternalURL = true + private var externalURL: URL? private var internalURL: URL? private var remoteUIURL: URL? @@ -200,13 +205,19 @@ public struct ConnectionInfo: Codable, Equatable { activeURLType = .internal url = internalURL } else { - activeURLType = .none - url = nil - /* - No URL that can be used in this context is available - This can happen when only internal URL is set and - user tries to access the App remotely - */ + // TODO: Remove when location permission enforcement is in place + if ConnectionInfo.shouldFallbackToInternalURL { + activeURLType = .internal + url = internalURL + } else { + activeURLType = .none + url = nil + /* + No URL that can be used in this context is available + This can happen when only internal URL is set and + user tries to access the App remotely + */ + } } return url?.sanitized() diff --git a/Tests/Shared/ConnectionInfo.test.swift b/Tests/Shared/ConnectionInfo.test.swift index c173271a4..da422832a 100644 --- a/Tests/Shared/ConnectionInfo.test.swift +++ b/Tests/Shared/ConnectionInfo.test.swift @@ -3,6 +3,10 @@ import Version import XCTest class ConnectionInfoTests: XCTestCase { + override func setUp() async throws { + ConnectionInfo.shouldFallbackToInternalURL = false + } + func testInternalOnlyURL() { let url = URL(string: "http://example.com:8123") var info = ConnectionInfo(