Skip to content

Commit

Permalink
Implement WKUIDelegate runJavaScriptConfirmPanelWithMessage support. F…
Browse files Browse the repository at this point in the history
…ixes #174 and fixes #156
  • Loading branch information
mnoorenberghe committed Jan 26, 2019
1 parent d8e6f46 commit cab486c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HomeAssistant/Resources/en.lproj/Localizable.strings
Expand Up @@ -152,6 +152,8 @@
"about.beta.title" = "Join Beta";
"alerts.auth_required.message" = "The server has rejected your credentials, and you must sign in again to continue.";
"alerts.auth_required.title" = "You must sign in to continue";
"alerts.confirm.ok" = "OK";
"alerts.confirm.cancel" = "Cancel";
"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
16 changes: 16 additions & 0 deletions HomeAssistant/Views/WebViewController.swift
Expand Up @@ -257,6 +257,22 @@ class WebViewController: UIViewController, WKNavigationDelegate, WKUIDelegate, C
self.setToolbarItems(items, animated: true)
}

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

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

alertController.addAction(UIAlertAction(title: L10n.Alerts.Confirm.cancel, style: .cancel, handler: { (action) in
completionHandler(false)
}))

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

@objc func loadActiveURLIfNeeded() {
if HomeAssistantAPI.authenticatedAPI() != nil,
let connectionInfo = Current.settingsStore.connectionInfo,
Expand Down
7 changes: 7 additions & 0 deletions Shared/Resources/Swiftgen/Strings.swift
Expand Up @@ -100,6 +100,13 @@ internal enum L10n {
internal static let title = L10n.tr("Localizable", "alerts.auth_required.title")
}

internal enum Confirm {
/// Cancel
internal static let cancel = L10n.tr("Localizable", "alerts.confirm.cancel")
/// OK
internal static let ok = L10n.tr("Localizable", "alerts.confirm.ok")
}

internal enum OpenUrlFromNotification {
/// Open URL (%@) found in notification?
internal static func message(_ p1: String) -> String {
Expand Down

0 comments on commit cab486c

Please sign in to comment.