Skip to content

Commit

Permalink
Implement WKUIDelegate runJavaScriptAlertPanelWithMessage support
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoorenberghe committed Jan 26, 2019
1 parent a3aaab6 commit 8797084
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions HomeAssistant/Resources/en.lproj/Localizable.strings
Expand Up @@ -156,6 +156,7 @@
"alerts.confirm.cancel" = "Cancel";
"alerts.prompt.ok" = "OK";
"alerts.prompt.cancel" = "Cancel";
"alerts.alert.ok" = "OK";
"cl_error.description.deferred_accuracy_too_low" = "Deferred mode is not supported for the requested accuracy.";
"cl_error.description.deferred_canceled" = "The request for deferred updates was canceled by your app or by the location manager.";
"cl_error.description.deferred_distance_filtered" = "Deferred mode does not support distance filters.";
Expand Down
11 changes: 11 additions & 0 deletions HomeAssistant/Views/WebViewController.swift
Expand Up @@ -296,6 +296,17 @@ class WebViewController: UIViewController, WKNavigationDelegate, WKUIDelegate, C
self.present(alertController, animated: true, completion: nil)
}

func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet)

alertController.addAction(UIAlertAction(title: L10n.Alerts.Alert.ok, style: .default, handler: { (action) in
completionHandler()
}))

self.present(alertController, animated: true, completion: nil)
}

@objc func loadActiveURLIfNeeded() {
if HomeAssistantAPI.authenticatedAPI() != nil,
let connectionInfo = Current.settingsStore.connectionInfo,
Expand Down
5 changes: 5 additions & 0 deletions Shared/Resources/Swiftgen/Strings.swift
Expand Up @@ -93,6 +93,11 @@ internal enum L10n {

internal enum Alerts {

internal enum Alert {
/// OK
internal static let ok = L10n.tr("Localizable", "alerts.alert.ok")
}

internal enum AuthRequired {
/// The server has rejected your credentials, and you must sign in again to continue.
internal static let message = L10n.tr("Localizable", "alerts.auth_required.message")
Expand Down

0 comments on commit 8797084

Please sign in to comment.