From c63a9d399493cfe9d61139865015b9e5e5804c4a Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 10 Aug 2023 16:44:28 +1000 Subject: [PATCH] Fixed an issue preventing notifications from working Fixed an issue where Storage could be left in an invalid state when it was completed silently before properly getting setup --- .../NotificationServiceExtension.swift | 12 ++++++++---- SessionUtilitiesKit/Database/Storage.swift | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index b4f40742a..22c6f4948 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -227,6 +227,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension // to process new messages. guard !didPerformSetup else { return } + NSLog("[NotificationServiceExtension] Performing setup") didPerformSetup = true _ = AppVersion.sharedInstance() @@ -243,7 +244,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension switch result { // Only 'NSLog' works in the extension - viewable via Console.app case .failure(let error): - NSLog("[NotificationServiceExtension] Failed to complete migrations") + NSLog("[NotificationServiceExtension] Failed to complete migrations: \(error)") self?.completeSilenty() case .success: @@ -288,7 +289,11 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension guard !AppReadiness.isAppReady() else { return } // App isn't ready until storage is ready AND all version migrations are complete. - guard Storage.shared.isValid && migrationsCompleted else { return } + guard Storage.shared.isValid && migrationsCompleted else { + NSLog("[NotificationServiceExtension] Storage invalid") + self.completeSilenty() + return + } SignalUtilitiesKit.Configuration.performMainSetup() @@ -305,8 +310,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension } private func completeSilenty() { - SNLog("Complete silenty") - + NSLog("[NotificationServiceExtension] Complete silently") Storage.suspendDatabaseAccess() self.contentHandler!(.init()) diff --git a/SessionUtilitiesKit/Database/Storage.swift b/SessionUtilitiesKit/Database/Storage.swift index 94acc226b..464bf8eb5 100644 --- a/SessionUtilitiesKit/Database/Storage.swift +++ b/SessionUtilitiesKit/Database/Storage.swift @@ -375,14 +375,14 @@ open class Storage { /// database and other files into the App folder public static func suspendDatabaseAccess(using dependencies: Dependencies = Dependencies()) { NotificationCenter.default.post(name: Database.suspendNotification, object: self) - dependencies.storage.isSuspendedUnsafe = true + if Storage.hasCreatedValidInstance { dependencies.storage.isSuspendedUnsafe = true } } /// This method reverses the database suspension used to prevent the `0xdead10cc` exception (see `suspendDatabaseAccess()` /// above for more information public static func resumeDatabaseAccess(using dependencies: Dependencies = Dependencies()) { NotificationCenter.default.post(name: Database.resumeNotification, object: self) - dependencies.storage.isSuspendedUnsafe = false + if Storage.hasCreatedValidInstance { dependencies.storage.isSuspendedUnsafe = false } } public static func resetAllStorage() {