Prevent potential redirect loops
This commit is contained in:
parent
71b6352395
commit
182bb4b79b
|
@ -19,6 +19,14 @@ public class NavigationManager: NSObject, ObservableObject {
|
||||||
@Published public var backStack = [URL]()
|
@Published public var backStack = [URL]()
|
||||||
@Published public var forwardStack = [URL]()
|
@Published public var forwardStack = [URL]()
|
||||||
|
|
||||||
|
public var displayURL: String {
|
||||||
|
var components = URLComponents(url: currentURL, resolvingAgainstBaseURL: false)!
|
||||||
|
if components.port == 1965 {
|
||||||
|
components.port = nil
|
||||||
|
}
|
||||||
|
return components.string!
|
||||||
|
}
|
||||||
|
|
||||||
public init(url: URL) {
|
public init(url: URL) {
|
||||||
self.currentURL = url
|
self.currentURL = url
|
||||||
}
|
}
|
||||||
|
@ -30,9 +38,6 @@ public class NavigationManager: NSObject, ObservableObject {
|
||||||
delegate?.loadNonGeminiURL(url)
|
delegate?.loadNonGeminiURL(url)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if components.port == 1965 {
|
|
||||||
components.port = nil
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
components.scheme = "gemini"
|
components.scheme = "gemini"
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct NavigationBar: View {
|
||||||
|
|
||||||
init(navigator: NavigationManager) {
|
init(navigator: NavigationManager) {
|
||||||
self.navigator = navigator
|
self.navigator = navigator
|
||||||
self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString)
|
self._urlFieldContents = State(initialValue: navigator.displayURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -33,8 +33,8 @@ struct NavigationBar: View {
|
||||||
.foregroundColor(Color(white: colorScheme == .dark ? 0.25 : 0.75))
|
.foregroundColor(Color(white: colorScheme == .dark ? 0.25 : 0.75))
|
||||||
}
|
}
|
||||||
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.top))
|
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.top))
|
||||||
.onReceive(navigator.$currentURL) { (newURL) in
|
.onReceive(navigator.$currentURL) { (_) in
|
||||||
urlFieldContents = newURL.absoluteString
|
urlFieldContents = navigator.displayURL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue