mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-17 04:10:52 -06:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
68 lines
2.3 KiB
Swift
68 lines
2.3 KiB
Swift
import Foundation
|
|
import Shared
|
|
|
|
extension WebViewController: WebViewControllerProtocol {
|
|
var overlayedController: UIViewController? {
|
|
presentedViewController
|
|
}
|
|
|
|
func presentOverlayController(controller: UIViewController, animated: Bool) {
|
|
DispatchQueue.main.async { [weak self] in
|
|
self?.dismissOverlayController(animated: false, completion: { [weak self] in
|
|
self?.present(controller, animated: animated, completion: nil)
|
|
})
|
|
}
|
|
}
|
|
|
|
func presentAlertController(controller: UIViewController, animated: Bool) {
|
|
DispatchQueue.main.async { [weak self] in
|
|
guard let self else { return }
|
|
if let overlayedController {
|
|
overlayedController.present(controller, animated: animated, completion: nil)
|
|
} else {
|
|
present(controller, animated: animated, completion: nil)
|
|
}
|
|
}
|
|
}
|
|
|
|
func evaluateJavaScript(_ script: String, completion: ((Any?, (any Error)?) -> Void)?) {
|
|
webView.evaluateJavaScript(script, completionHandler: completion)
|
|
}
|
|
|
|
func dismissOverlayController(animated: Bool, completion: (() -> Void)?) {
|
|
dismissAllViewControllersAbove(completion: completion)
|
|
}
|
|
|
|
func dismissControllerAboveOverlayController() {
|
|
overlayedController?.dismissAllViewControllersAbove()
|
|
}
|
|
|
|
func updateFrontendConnectionState(state: String) {
|
|
emptyStateTimer?.invalidate()
|
|
emptyStateTimer = nil
|
|
|
|
let state = FrontEndConnectionState(rawValue: state) ?? .unknown
|
|
isConnected = state == .connected
|
|
|
|
// Possible values: connected, disconnected, auth-invalid
|
|
if state == .connected {
|
|
hideEmptyState()
|
|
} else {
|
|
// Start a 4-second timer. If not interrupted by a 'connected' state, set alpha to 1.
|
|
emptyStateTimer = Timer.scheduledTimer(withTimeInterval: 4.0, repeats: false) { [weak self] _ in
|
|
self?.showEmptyState()
|
|
}
|
|
}
|
|
}
|
|
|
|
func navigateToPath(path: String) {
|
|
if let activeURL = server.info.connection.activeURL(), let url = URL(string: activeURL.absoluteString + path) {
|
|
webView.load(URLRequest(url: url))
|
|
}
|
|
}
|
|
|
|
func reload() {
|
|
webView.reload()
|
|
}
|
|
}
|