From 4fe78bdda482db7dd8655541c3a1cfa9d936259b Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Fri, 31 Jul 2020 14:20:09 +1000 Subject: [PATCH] fix homeVC not refreshing because of PN --- .../NotificationServiceExtension.swift | 8 ++++++++ Signal/src/AppDelegate.m | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/LokiPushNotificationService/NotificationServiceExtension.swift b/LokiPushNotificationService/NotificationServiceExtension.swift index f5aa06a9e..fe2e628dd 100644 --- a/LokiPushNotificationService/NotificationServiceExtension.swift +++ b/LokiPushNotificationService/NotificationServiceExtension.swift @@ -16,6 +16,14 @@ final class NotificationServiceExtension : UNNotificationServiceExtension { self.contentHandler = contentHandler notificationContent = (request.content.mutableCopy() as? UNMutableNotificationContent) + var isMainAppActive = false + if let sharedUserDefaults = UserDefaults(suiteName: "group.com.loki-project.loki-messenger") { + isMainAppActive = sharedUserDefaults.bool(forKey: "isMainAppActive") + } + print("[Ryan debug] isMainAppActive \(isMainAppActive)") + // If the main app is running, skip the whole process + guard !isMainAppActive else { return self.completeWithFailure(content: notificationContent!) } + // The code using DispatchQueue.main.async { self.setUpIfNecessary() { Modify the notification content } } will somehow cause a freeze when a second PN comes DispatchQueue.main.sync { self.setUpIfNecessary() {} } diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 4c4767cea..02f47365f 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -306,6 +306,10 @@ static NSTimeInterval launchStartedAt; if (CurrentAppContext().isRunningTests) { return; } + + NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.loki-project.loki-messenger"]; + [sharedUserDefaults setBool:true forKey:@"isMainAppActive"]; + [sharedUserDefaults synchronize]; [self ensureRootViewController]; @@ -333,6 +337,10 @@ static NSTimeInterval launchStartedAt; } [self clearAllNotificationsAndRestoreBadgeCount]; + + NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.loki-project.loki-messenger"]; + [sharedUserDefaults setBool:false forKey:@"isMainAppActive"]; + [sharedUserDefaults synchronize]; [DDLog flushLog]; }