Hotspot port settings for iPad

This commit is contained in:
Balazs Perlaki-Horvath 2025-07-06 22:14:30 +02:00 committed by Kelson
parent 6028ea5341
commit 13e5c35e3a
2 changed files with 36 additions and 9 deletions

View File

@ -54,7 +54,6 @@ final class SidebarViewController: UICollectionViewController, NSFetchedResultsC
case primary
case library
case settings
case hotspot
case donation
static var allSections: [Section] {
@ -62,11 +61,11 @@ final class SidebarViewController: UICollectionViewController, NSFetchedResultsC
case (true, true):
allCases.filter { ![.donation].contains($0) }
case (false, true):
allCases.filter { ![.donation, .library, .hotspot].contains($0) }
allCases.filter { ![.donation, .library].contains($0) }
case (true, false):
allCases
case (false, false):
allCases.filter { ![.library, .hotspot].contains($0) }
allCases.filter { ![.library].contains($0) }
}
}
}
@ -139,10 +138,7 @@ final class SidebarViewController: UICollectionViewController, NSFetchedResultsC
snapshot.appendItems([.bookmarks], toSection: .primary)
}
if snapshot.sectionIdentifiers.contains(.library) {
snapshot.appendItems([.opened, .categories, .downloads, .new], toSection: .library)
}
if snapshot.sectionIdentifiers.contains(.hotspot) {
snapshot.appendItems([.hotspot], toSection: .hotspot)
snapshot.appendItems([.opened, .categories, .downloads, .new, .hotspot], toSection: .library)
}
if snapshot.sectionIdentifiers.contains(.settings) {
snapshot.appendItems([.settings], toSection: .settings)

View File

@ -114,7 +114,6 @@ struct LibrarySettings: View {
struct HotspotSettings: View {
@Default(.hotspotPortNumber) private var savedPortNumber
@State private var portNumber: Int
@State private var showAlert: Bool = false
@ -132,7 +131,7 @@ struct HotspotSettings: View {
if Hotspot.isValid(port: newValue) {
showAlert = false
// make sure we only save valid port numbers
savedPortNumber = newValue
Defaults[.hotspotPortNumber] = newValue
} else {
showAlert = true
}
@ -192,6 +191,13 @@ struct Settings: View {
@EnvironmentObject private var colorSchemeStore: UserColorSchemeStore
@EnvironmentObject private var library: LibraryViewModel
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@State private var showHotspotAlert: Bool = false
@State private var portNumber: Int
init() {
self.portNumber = Defaults[.hotspotPortNumber]
}
enum Route {
case languageSelector, about
@ -209,6 +215,7 @@ struct Settings: View {
downloadSettings
catalogSettings
miscellaneous
hotspot
backupSettings
}
.modifier(ToolbarRoleBrowser())
@ -331,6 +338,30 @@ struct Settings: View {
NavigationLink(LocalString.settings_miscellaneous_navigation_about) { About() }
}
}
var hotspot: some View {
Section {
if showHotspotAlert {
Text(Hotspot.invalidPortMessage).foregroundStyle(.red)
}
HStack {
Text(LocalString.hotspot_settings_port_number)
TextField("", value: $portNumber, format: .number)
.textFieldStyle(.roundedBorder)
.onChange(of: portNumber) { newValue in
if Hotspot.isValid(port: newValue) {
showHotspotAlert = false
// make sure we only save valid port numbers
Defaults[.hotspotPortNumber] = newValue
} else {
showHotspotAlert = true
}
}
}
} header: {
Text(LocalString.enum_navigation_item_hotspot)
}
}
}
private struct SelectedLanaguageLabel: View {