From 274f0e2b02659655b07583eba31d026da079eccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Pantale=C3=A3o?= <5808343+bgoncal@users.noreply.github.com> Date: Thu, 12 Dec 2024 01:12:21 +0100 Subject: [PATCH] Temporarily allow fallback to internal URL --- .../ConnectionSettingsViewController.swift | 14 +-- .../ConnectionURLViewController.swift | 88 +++++++++---------- Sources/Shared/API/ConnectionInfo.swift | 10 ++- 3 files changed, 59 insertions(+), 53 deletions(-) diff --git a/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift b/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift index c02c9b786..257e31731 100644 --- a/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift +++ b/Sources/App/Settings/Connection/ConnectionSettingsViewController.swift @@ -154,13 +154,13 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType row.cellStyle = .value1 row.title = L10n.Settings.ConnectionSection.InternalBaseUrl.title row.displayValueFor = { [server] _ in - if server.info.connection.internalSSIDs?.isEmpty ?? true, - server.info.connection.internalHardwareAddresses?.isEmpty ?? true, - !server.info.connection.alwaysFallbackToInternalURL { - return "‼️ \(L10n.Settings.ConnectionSection.InternalBaseUrl.RequiresSetup.title)" - } else { - return server.info.connection.address(for: .internal)?.absoluteString ?? "—" - } +// if server.info.connection.internalSSIDs?.isEmpty ?? true, +// server.info.connection.internalHardwareAddresses?.isEmpty ?? true, +// !server.info.connection.alwaysFallbackToInternalURL { +// return "‼️ \(L10n.Settings.ConnectionSection.InternalBaseUrl.RequiresSetup.title)" +// } else { + server.info.connection.address(for: .internal)?.absoluteString ?? "—" +// } } row.presentationMode = .show(controllerProvider: .callback(builder: { [server] in ConnectionURLViewController(server: server, urlType: .internal, row: row) diff --git a/Sources/App/Settings/Connection/ConnectionURLViewController.swift b/Sources/App/Settings/Connection/ConnectionURLViewController.swift index 048aa24be..fb696e67e 100644 --- a/Sources/App/Settings/Connection/ConnectionURLViewController.swift +++ b/Sources/App/Settings/Connection/ConnectionURLViewController.swift @@ -230,18 +230,18 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle } <<< InfoLabelRow { $0.tag = RowTag.internalURLWarning.rawValue - if server.info.connection.internalSSIDs?.isEmpty ?? true, - server.info.connection.internalHardwareAddresses?.isEmpty ?? true, - !server.info.connection.alwaysFallbackToInternalURL { - #if targetEnvironment(macCatalyst) - $0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidBssidRequired.title - #else - $0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidRequired.title - - #endif - } else { - $0.title = L10n.Settings.ConnectionSection.InternalBaseUrl.SsidRequired.title - } +// if server.info.connection.internalSSIDs?.isEmpty ?? true, +// server.info.connection.internalHardwareAddresses?.isEmpty ?? true, +// !server.info.connection.alwaysFallbackToInternalURL { +// #if targetEnvironment(macCatalyst) +// $0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidBssidRequired.title +// #else +// $0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidRequired.title +// +// #endif +// } else { + $0.title = L10n.Settings.ConnectionSection.InternalBaseUrl.SsidRequired.title +// } } if urlType.isAffectedBySSID { @@ -296,38 +296,38 @@ 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 - - $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: .actionSheet - ) - alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in - self?.server.info.connection.alwaysFallbackToInternalURL = false - row.value = false - 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) - } - } - } + // 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.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: .actionSheet + // ) + // alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in + // self?.server.info.connection.alwaysFallbackToInternalURL = false + // row.value = false + // 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..6f29e1826 100644 --- a/Sources/Shared/API/ConnectionInfo.swift +++ b/Sources/Shared/API/ConnectionInfo.swift @@ -200,8 +200,14 @@ public struct ConnectionInfo: Codable, Equatable { activeURLType = .internal url = internalURL } else { - activeURLType = .none - url = nil +// activeURLType = .none +// url = nil + + // Temporarily allow fallback to internal URL if no URL is available + // TODO: Remove this fallback as soonas a better communication is available for this security change. + activeURLType = .internal + url = internalURL + /* No URL that can be used in this context is available This can happen when only internal URL is set and