Files
iOS/Sources/App/WebView/WebViewControllerProtocol+Implementation.swift
Bruno Pantaleão Gonçalves 364685aea9 Move parts of WebViewController to separate files (#3540)
<!-- 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. -->
2025-04-14 17:58:15 +02:00

57 lines
1.9 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 updateSettingsButton(state: String) {
// Possible values: connected, disconnected, auth-invalid
UIView.animate(withDuration: 1.0, delay: 0, options: .curveEaseInOut, animations: {
WebViewAccessoryViews.settingsButton.alpha = state == "connected" ? 0 : 1
}, completion: nil)
}
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()
}
}