Skip to content

Commit

Permalink
Open non-frontend pages in external browser (#2125)
Browse files Browse the repository at this point in the history
Fixes e.g. [Frigate](https://docs.frigate.video/)'s notifications which open a /api/something path to show a video. Non-frontend pages will cause us to potentially get stuck since there's no on-screen UI to go 'back'.
  • Loading branch information
zacwest authored May 8, 2022
1 parent 63641ef commit 4ab8c84
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Sources/App/WebView/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,21 @@ class WebViewController: UIViewController, WKNavigationDelegate, WKUIDelegate, U

public func open(inline url: URL) {
loadViewIfNeeded()
webView.load(URLRequest(url: url))

// these paths do not show frontend pages, and so we don't want to display them in our webview
// otherwise the user will get stuck. e.g. /api is loaded by frigate to show video clips and images
let ignoredPaths = [
"/api",
"/static",
"/hacsfiles",
"/local",
]

if ignoredPaths.allSatisfy({ !url.path.hasPrefix($0) }) {
webView.load(URLRequest(url: url))
} else {
openURLInBrowser(url, self)
}
}

private var lastNavigationWasServerError = false
Expand Down

0 comments on commit 4ab8c84

Please sign in to comment.