Skip to content

Commit

Permalink
Temporarily allow fallback to internal URL
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal committed Dec 12, 2024
1 parent 9eb6f4f commit 274f0e2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
88 changes: 44 additions & 44 deletions Sources/App/Settings/Connection/ConnectionURLViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions Sources/Shared/API/ConnectionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 274f0e2

Please sign in to comment.