also looking at this
fix(ios): answer a malformed argument instead of leaving the page waiting
#246
2 files
+136
-0
| @@ -863,6 +863,8 @@ struct CraftWebView: UIViewRepresentable { | ||
| 863 | 863 | case "setBadge": |
| 864 | 864 | if let count = body["count"] as? Int { |
| 865 | 865 | setBadgeCount(count, callbackId: callbackId) |
| 866 | } else { | |
| 867 | rejectCallback(callbackId, error: "setBadge needs a whole number of badges", code: "INVALID_ARGUMENT") | |
| 866 | 868 | } |
| 867 | 869 | case "clearBadge": |
| 868 | 870 | setBadgeCount(0, callbackId: callbackId) |
| @@ -877,6 +879,8 @@ struct CraftWebView: UIViewRepresentable { | ||
| 877 | 879 | case "setFlashlight": |
| 878 | 880 | if let enabled = body["enabled"] as? Bool { |
| 879 | 881 | setFlashlight(enabled: enabled, callbackId: callbackId) |
| 882 | } else { | |
| 883 | rejectCallback(callbackId, error: "setFlashlight needs true or false", code: "INVALID_ARGUMENT") | |
| 880 | 884 | } |
| 881 | 885 | // Vibrate pattern |
| 882 | 886 | case "vibrate": |
| @@ -891,6 +895,8 @@ struct CraftWebView: UIViewRepresentable { | ||
| 891 | 895 | if let urlString = body["url"] as? String, let url = URL(string: urlString) { |
| 892 | 896 | UIApplication.shared.open(url) |
| 893 | 897 | resolveCallback(callbackId, result: true) |
| 898 | } else { | |
| 899 | rejectCallback(callbackId, error: "openURL needs a URL it can parse", code: "INVALID_ARGUMENT") | |
| 894 | 900 | } |
| 895 | 901 | // App state |
| 896 | 902 | case "getAppState": |
| @@ -1298,6 +1304,8 @@ struct CraftWebView: UIViewRepresentable { | ||
| 1298 | 1304 | case "setShortcuts": |
| 1299 | 1305 | if let shortcuts = body["shortcuts"] as? [[String: Any]] { |
| 1300 | 1306 | setAppShortcuts(shortcuts: shortcuts, callbackId: callbackId) |
| 1307 | } else { | |
| 1308 | rejectCallback(callbackId, error: "setShortcuts needs a list of shortcuts", code: "INVALID_ARGUMENT") | |
| 1301 | 1309 | } |
| 1302 | 1310 | case "clearShortcuts": |
| 1303 | 1311 | clearAppShortcuts(callbackId: callbackId) |
| @@ -1308,16 +1316,22 @@ struct CraftWebView: UIViewRepresentable { | ||
| 1308 | 1316 | let value = body["value"] as? String { |
| 1309 | 1317 | let group = body["group"] as? String |
| 1310 | 1318 | setSharedKeychainItem(key: key, value: value, group: group, callbackId: callbackId) |
| 1319 | } else { | |
| 1320 | rejectCallback(callbackId, error: "setSharedItem needs both a key and a value", code: "INVALID_ARGUMENT") | |
| 1311 | 1321 | } |
| 1312 | 1322 | case "getSharedItem": |
| 1313 | 1323 | if let key = body["key"] as? String { |
| 1314 | 1324 | let group = body["group"] as? String |
| 1315 | 1325 | getSharedKeychainItem(key: key, group: group, callbackId: callbackId) |
| 1326 | } else { | |
| 1327 | rejectCallback(callbackId, error: "getSharedItem needs a key", code: "INVALID_ARGUMENT") | |
| 1316 | 1328 | } |
| 1317 | 1329 | case "removeSharedItem": |
| 1318 | 1330 | if let key = body["key"] as? String { |
| 1319 | 1331 | let group = body["group"] as? String |
| 1320 | 1332 | removeSharedKeychainItem(key: key, group: group, callbackId: callbackId) |
| 1333 | } else { | |
| 1334 | rejectCallback(callbackId, error: "removeSharedItem needs a key", code: "INVALID_ARGUMENT") | |
| 1321 | 1335 | } |
| 1322 | 1336 | |
| 1323 | 1337 | // MARK: - Local Auth Persistence |
| @@ -1325,6 +1339,8 @@ struct CraftWebView: UIViewRepresentable { | ||
| 1325 | 1339 | if let enabled = body["enabled"] as? Bool { |
| 1326 | 1340 | let duration = body["duration"] as? Double ?? 300 // 5 min default |
| 1327 | 1341 | setBiometricPersistence(enabled: enabled, duration: duration, callbackId: callbackId) |
| 1342 | } else { | |
| 1343 | rejectCallback(callbackId, error: "setBiometricPersistence needs true or false", code: "INVALID_ARGUMENT") | |
| 1328 | 1344 | } |
| 1329 | 1345 | case "checkBiometricPersistence": |
| 1330 | 1346 | checkBiometricPersistence(callbackId: callbackId) |
| @@ -1408,6 +1424,8 @@ struct CraftWebView: UIViewRepresentable { | ||
| 1408 | 1424 | case "updateWidget": |
| 1409 | 1425 | if let data = body["data"] as? [String: Any] { |
| 1410 | 1426 | updateWidget(data: data, callbackId: callbackId) |
| 1427 | } else { | |
| 1428 | rejectCallback(callbackId, error: "updateWidget needs a data object", code: "INVALID_ARGUMENT") | |
| 1411 | 1429 | } |
| 1412 | 1430 | case "reloadWidgets": |
| 1413 | 1431 | reloadAllWidgets(callbackId: callbackId) |
| @@ -1417,20 +1435,28 @@ struct CraftWebView: UIViewRepresentable { | ||
| 1417 | 1435 | if let phrase = body["phrase"] as? String, |
| 1418 | 1436 | let action = body["shortcutAction"] as? String { |
| 1419 | 1437 | registerSiriShortcut(phrase: phrase, action: action, callbackId: callbackId) |
| 1438 | } else { | |
| 1439 | rejectCallback(callbackId, error: "registerSiriShortcut needs both a phrase and a shortcutAction", code: "INVALID_ARGUMENT") | |
| 1420 | 1440 | } |
| 1421 | 1441 | case "removeSiriShortcut": |
| 1422 | 1442 | if let action = body["shortcutAction"] as? String { |
| 1423 | 1443 | removeSiriShortcut(action: action, callbackId: callbackId) |
| 1444 | } else { | |
| 1445 | rejectCallback(callbackId, error: "removeSiriShortcut needs a shortcutAction", code: "INVALID_ARGUMENT") | |
| 1424 | 1446 | } |
| 1425 | 1447 | |
| 1426 | 1448 | // MARK: - Watch Connectivity |
| 1427 | 1449 | case "sendToWatch": |
| 1428 | 1450 | if let message = body["message"] as? [String: Any] { |
| 1429 | 1451 | sendMessageToWatch(message: message, callbackId: callbackId) |
| 1452 | } else { | |
| 1453 | rejectCallback(callbackId, error: "sendToWatch needs a message object", code: "INVALID_ARGUMENT") | |
| 1430 | 1454 | } |
| 1431 | 1455 | case "updateWatchContext": |
| 1432 | 1456 | if let context = body["context"] as? [String: Any] { |
| 1433 | 1457 | updateWatchContext(context: context, callbackId: callbackId) |
| 1458 | } else { | |
| 1459 | rejectCallback(callbackId, error: "updateWatchContext needs a context object", code: "INVALID_ARGUMENT") | |
| 1434 | 1460 | } |
| 1435 | 1461 | case "isWatchReachable": |
| 1436 | 1462 | isWatchReachable(callbackId: callbackId) |