Skip to content

Commit

Permalink
Merge pull request #206 from mnoorenberghe/wkui_prompts
Browse files Browse the repository at this point in the history
Implement WKUIDelegate panels
  • Loading branch information
robbiet480 committed Feb 4, 2019
2 parents 31c410b + 8797084 commit de4f19d
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 16 deletions.
4 changes: 2 additions & 2 deletions APNSAttachmentService/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
Expand Down
9 changes: 9 additions & 0 deletions HomeAssistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2590,6 +2590,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Robert Trencheny (43BAGK8JW5)";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 35;
CURRENT_PROJECT_VERSION = 0;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = UTQFCBPQRF;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -2654,6 +2655,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: Robert Trencheny (UTQFCBPQRF)";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 35;
CURRENT_PROJECT_VERSION = 0;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = UTQFCBPQRF;
ENABLE_NS_ASSERTIONS = NO;
Expand Down Expand Up @@ -2938,11 +2940,13 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Robert Trencheny (43BAGK8JW5)";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 35;
CURRENT_PROJECT_VERSION = 0;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UTQFCBPQRF;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 35;
DYLIB_CURRENT_VERSION = 0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Shared/Info.plist;
Expand Down Expand Up @@ -2980,6 +2984,11 @@
DEVELOPMENT_TEAM = UTQFCBPQRF;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 35;
CURRENT_PROJECT_VERSION = 0;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UTQFCBPQRF;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Shared/Info.plist;
Expand Down
4 changes: 2 additions & 2 deletions HomeAssistant/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
5 changes: 5 additions & 0 deletions HomeAssistant/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
"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";
"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
50 changes: 50 additions & 0 deletions HomeAssistant/Views/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,56 @@ 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)
}

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

alertController.addTextField { (textField) in
textField.text = defaultText
}

alertController.addAction(UIAlertAction(title: L10n.Alerts.Prompt.ok, style: .default, handler: { (action) in
if let text = alertController.textFields?.first?.text {
completionHandler(text)
} else {
completionHandler(defaultText)
}
}))

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

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
4 changes: 2 additions & 2 deletions HomeAssistantTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions HomeAssistantUITests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions MapNotificationContentExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
4 changes: 2 additions & 2 deletions NotificationContentExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
Expand Down
4 changes: 2 additions & 2 deletions Shared/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
19 changes: 19 additions & 0 deletions Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,25 @@ 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")
/// You must sign in to continue
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 All @@ -108,6 +120,13 @@ internal enum L10n {
/// Open URL?
internal static let title = L10n.tr("Localizable", "alerts.open_url_from_notification.title")
}

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

internal enum ClError {
Expand Down
4 changes: 2 additions & 2 deletions SharedTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.1</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>0</string>
</dict>
</plist>

0 comments on commit de4f19d

Please sign in to comment.