bug fixes

This commit is contained in:
Scott Pfeil 2022-08-11 22:34:35 -04:00
parent e6164026f6
commit 0196d5c190
3 changed files with 18 additions and 17 deletions

View File

@ -72,7 +72,7 @@ open class ActionOpenUrlHandler: MVMCoreJSONActionHandlerProtocol {
// Try loading the app url first, otherwise fall back to browser url. // Try loading the app url first, otherwise fall back to browser url.
if let appURL = model.appURL { if let appURL = model.appURL {
do { do {
try await openURL(model: model, additionalData: additionalData, delegateObject: delegateObject) try await ActionOpenUrlHandler.open(url: appURL)
return return
} catch { } catch {
// Log error and continue // Log error and continue

View File

@ -89,10 +89,10 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol {
defer { defer {
MVMCoreActionHandler.log(string: "End Action: \(model.actionType)", additionalData: additionalData) MVMCoreActionHandler.log(string: "End Action: \(model.actionType)", additionalData: additionalData)
} }
let json = try additionalData?.removeValue(forKey: jsonKey) as? [AnyHashable : Any] ?? MVMCoreActionHandler.convertActionToJSON(model) let json = try additionalData.removeValue(forKey: jsonKey) as? [AnyHashable : Any] ?? MVMCoreActionHandler.convertActionToJSON(model)
// Log the action // Log the action
delegateObject?.actionDelegate?.logAction?(withActionInformation: json, additionalData: additionalData) logAction(with: json, additionalData: additionalData, delegateObject: delegateObject)
do { do {
let handlerType = try ModelRegistry.getHandler(model) as! MVMCoreActionHandlerProtocol.Type let handlerType = try ModelRegistry.getHandler(model) as! MVMCoreActionHandlerProtocol.Type
@ -119,9 +119,9 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol {
// MARK: - Subclassables // MARK: - Subclassables
/// Subclass to log the action was fired. /// Subclass to log the action was fired.
open func logAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { open func logAction(with JSON: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
// Calls legacy log action function. // Calls legacy log action function.
delegateObject?.actionDelegate?.logAction?(withActionInformation: model.toJSON(), additionalData: additionalData) delegateObject?.actionDelegate?.logAction?(withActionInformation: JSON, additionalData: additionalData)
} }
/// Logs the error. /// Logs the error.
@ -132,8 +132,8 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol {
// MARK: - Legacy Holdovers // MARK: - Legacy Holdovers
static public func setUUID(additionalData: [AnyHashable: Any]?) -> [AnyHashable: Any]? { static public func setUUID(additionalData: [AnyHashable: Any]?, force: Bool = false) -> [AnyHashable: Any] {
guard getUUID(additionalData: additionalData) == nil else { return additionalData } if !force && getUUID(additionalData: additionalData) != nil { return additionalData! }
return additionalData.dictionaryAdding(key: "Action-UUID", value: UUID().uuidString) return additionalData.dictionaryAdding(key: "Action-UUID", value: UUID().uuidString)
} }
@ -148,7 +148,6 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol {
/// Legacy handle action with json. /// Legacy handle action with json.
@objc(handleActionWithDictionary:additionalData:delegateObject:) @objc(handleActionWithDictionary:additionalData:delegateObject:)
open func handleAction(with json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { open func handleAction(with json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
let additionalData = MVMCoreActionHandler.setUUID(additionalData: additionalData)
let task = Task(priority: .userInitiated) { let task = Task(priority: .userInitiated) {
try Task.checkCancellation() try Task.checkCancellation()
do { do {
@ -156,12 +155,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol {
throw ModelRegistry.Error.keyNotFound throw ModelRegistry.Error.keyNotFound
} }
let model = try MVMCoreActionHandler.createModel(with: json, delegateObject: delegateObject) let model = try MVMCoreActionHandler.createModel(with: json, delegateObject: delegateObject)
if let closure = (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction { try await handleAction(with: model, json: json, additionalData: additionalData, delegateObject: delegateObject)
// Allow newer delegates to handle calls from legacy functions
try await closure(model, additionalData, delegateObject)
} else {
try await handleAction(with: model, json: json, additionalData: additionalData, delegateObject: delegateObject)
}
} catch { } catch {
let actionType = json?.optionalStringForKey(KeyActionType) let actionType = json?.optionalStringForKey(KeyActionType)
switch error { switch error {
@ -192,8 +186,15 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol {
/// Bridges the legacy json using functions and the new model using functions. /// Bridges the legacy json using functions and the new model using functions.
open func handleAction(with model: ActionModelProtocol, json: [AnyHashable: Any], additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws { open func handleAction(with model: ActionModelProtocol, json: [AnyHashable: Any], additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws {
try Task.checkCancellation() try Task.checkCancellation()
let additionalData = additionalData.dictionaryAdding(key: jsonKey, value: json) var additionalData = additionalData.dictionaryAdding(key: jsonKey, value: json)
try await handleAction(with: model, additionalData: additionalData, delegateObject: delegateObject) additionalData = MVMCoreActionHandler.setUUID(additionalData: additionalData, force: true)
MVMCoreActionHandler.log(string: "JSON \(json)", additionalData: additionalData)
if let closure = (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction {
// Allow newer delegates to handle calls from legacy functions
try await closure(model, additionalData, delegateObject)
} else {
try await handleAction(with: model, additionalData: additionalData, delegateObject: delegateObject)
}
} }
/// Subclass to handle and any actions where a handler was not registered. Checks with the delegate handlesUnknownAction function /// Subclass to handle and any actions where a handler was not registered. Checks with the delegate handlesUnknownAction function

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
protocol MVMError: LocalizedError, CustomNSError {} public protocol MVMError: LocalizedError, CustomNSError {}
extension MVMError { extension MVMError {
public var errorDescription: String? { return MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess) } public var errorDescription: String? { return MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess) }