diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift index a108649..c353ba4 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift @@ -25,11 +25,16 @@ open class ActionRestartHandler: MVMCoreActionHandlerProtocol { return } continuation.resume(throwing: MVMCoreError.errorObject(error)) - } else { - // Restarts the app (forcing any passed in page types). - MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, request: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) - continuation.resume() + return } + if let sessionObject = MVMCoreSessionObject.sharedGlobal() { + if model.hardReset { + sessionObject.clearPeristentCache() + } + // Restarts the app (forcing any passed in page types). + sessionObject.restartSession(withPageType: model.pageType, request: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) + } + continuation.resume() }) } } diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift index 4cde79c..c8c4fef 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift @@ -16,6 +16,7 @@ public struct ActionRestartModel: ActionModelProtocol { public static var identifier: String = "restart" public var actionType: String = ActionRestartModel.identifier public var requestURL: URL? + @DecodableDefault.True public var hardReset: Bool public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? @@ -26,11 +27,12 @@ public struct ActionRestartModel: ActionModelProtocol { // MARK: - Initializer //-------------------------------------------------- - public init(_ pageType: String? = nil, _ requestUrl: URL? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + public init(_ pageType: String? = nil, _ requestUrl: URL? = nil, hardReset: Bool? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.pageType = pageType self.requestURL = requestUrl self.extraParameters = extraParameters self.analyticsData = analyticsData + self.hardReset = hardReset ?? true } public func isEqual(to model: any ModelComparisonProtocol) -> Bool { @@ -39,5 +41,6 @@ public struct ActionRestartModel: ActionModelProtocol { && analyticsData == model.analyticsData && requestURL == model.requestURL && pageType == model.pageType + && hardReset == model.hardReset } } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift index e562854..c23b113 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift @@ -70,9 +70,35 @@ import os #endif } + open func handleWarningMessage(_ message: String, category: String?) { + #if LOGGING + guard message.count < 1024 else { + getLogger(category: category).warning("\(message.prefix(300), privacy: .public)... ") // Send initial log to console. + print(message) // Print the whole on stdout. + return + } + getLogger(category: category).warning("\(message, privacy: .public)") // Assume that becaues this is a LOGGING build we want these messages to be unmasked. + #endif + } + + open func handleErrorMessage(_ message: String, category: String?) { + #if LOGGING + guard message.count < 1024 else { + getLogger(category: category).error("\(message.prefix(300), privacy: .public)... ") // Send initial log to console. + print(message) // Print the whole on stdout. + return + } + getLogger(category: category).error("\(message, privacy: .public)") // Assume that becaues this is a LOGGING build we want these messages to be unmasked. + #endif + } + @objc(addErrorToLog:) open func addError(toLog errorObject: MVMCoreErrorObject) { - // Subclass to handle. + if errorObject.silentError { + handleWarningMessage(errorObject.messageToLog ?? errorObject.messageToDisplay ?? "Some error occrured.", category: "Handled Exception") + } else { + handleErrorMessage(errorObject.messageToLog ?? errorObject.messageToDisplay ?? "Some error occurred.", category: "Handled Exception") + } } open func logLoadFinished(_ loadObject: MVMCoreLoadObject?, loadedViewController: MVMCoreViewControllerProtocol?, error: MVMCoreErrorObject?) {} diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h index aed5cb1..0bea882 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h @@ -38,6 +38,9 @@ /// Clears the session singleton. Creates a new session NSURLSession also. - (void)clearSessionObject; +/// Clears any persistent cache related to the current session. +- (void)clearPeristentCache; + /// Copys string to clipboard and assigns self.clipboardString for validation /// Should only be used when expected string is a secure string -(void)copyStringToClipboard :(nullable NSString *)clipboardString; diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index 628f7a6..e0998ef 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -53,4 +53,6 @@ self.session = [self createNSURLSession]; } +- (void)clearPeristentCache {} + @end