From 13e5c35e3aa38c161d637ee884189c5c6496f50c Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sun, 6 Jul 2025 22:14:30 +0200 Subject: [PATCH] Hotspot port settings for iPad --- App/SidebarViewController.swift | 10 +++------- Views/Settings/Settings.swift | 35 +++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/App/SidebarViewController.swift b/App/SidebarViewController.swift index 8c8d856c..808108a7 100644 --- a/App/SidebarViewController.swift +++ b/App/SidebarViewController.swift @@ -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) diff --git a/Views/Settings/Settings.swift b/Views/Settings/Settings.swift index c10b7e45..db8f598a 100644 --- a/Views/Settings/Settings.swift +++ b/Views/Settings/Settings.swift @@ -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 {