From 9a3763f57a153a8512c0545a96b6d180dfffaacc Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 10 Jan 2020 16:32:06 -0700 Subject: [PATCH] Change to resume database earlier for notifications and home screen shortcuts. Issue #1597 --- iOS/AppDelegate.swift | 11 ++++++----- iOS/SceneDelegate.swift | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 27964ddf1..a79c70147 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -126,6 +126,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } // MARK: - API + func resumeDatabaseProcessingIfNecessary() { + if AccountManager.shared.isSuspended { + AccountManager.shared.resumeAll() + os_log("Application processing resumed.", log: self.log, type: .info) + } + } func prepareAccountsForBackground() { syncTimer?.invalidate() @@ -135,11 +141,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } func prepareAccountsForForeground() { - if AccountManager.shared.isSuspended { - AccountManager.shared.resumeAll() - os_log("Application processing resumed.", log: self.log, type: .info) - } - if let lastRefresh = AppDefaults.lastRefresh { if Date() > lastRefresh.addingTimeInterval(15 * 60) { AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index fa289c74f..6c6447e5d 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -45,11 +45,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { + appDelegate.resumeDatabaseProcessingIfNecessary() handleShortcutItem(shortcutItem) completionHandler(true) } func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { + appDelegate.resumeDatabaseProcessingIfNecessary() coordinator.handle(userActivity) } @@ -59,6 +61,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } func sceneWillEnterForeground(_ scene: UIScene) { + appDelegate.resumeDatabaseProcessingIfNecessary() appDelegate.prepareAccountsForForeground() self.coordinator.configurePanelMode(for: window!.frame.size) } @@ -70,6 +73,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // API func handle(_ response: UNNotificationResponse) { + appDelegate.resumeDatabaseProcessingIfNecessary() coordinator.handle(response) }