Clean up NotificationServiceExtensionContext

pull/156/head
gmbnt 6 years ago
parent 28f1f79a75
commit b3c661c1fd

@ -6,89 +6,80 @@ import Foundation
import SignalServiceKit import SignalServiceKit
import SignalMessaging import SignalMessaging
class NotificationServiceExtensionContext: NSObject, AppContext { final class NotificationServiceExtensionContext : NSObject, AppContext {
var wasWokenUpBySilentPushNotification: Bool = true let appLaunchTime = Date()
var openSystemSettingsAction: UIAlertAction?
let isMainApp = false let isMainApp = false
let isMainAppAndActive = false let isMainAppAndActive = false
func isInBackground() -> Bool { true } var openSystemSettingsAction: UIAlertAction?
func isAppForegroundAndActive() -> Bool { false } var wasWokenUpBySilentPushNotification = true
func mainApplicationStateOnLaunch() -> UIApplication.State { .inactive }
var shouldProcessIncomingMessages: Bool { true } var shouldProcessIncomingMessages: Bool { true }
func canPresentNotifications() -> Bool { true }
let appLaunchTime = Date()
lazy var buildTime: Date = { lazy var buildTime: Date = {
guard let buildTimestamp = Bundle.main.object(forInfoDictionaryKey: "BuildTimestamp") as? TimeInterval, buildTimestamp > 0 else { guard let buildTimestamp = Bundle.main.object(forInfoDictionaryKey: "BuildTimestamp") as? TimeInterval, buildTimestamp > 0 else {
Logger.debug("No build timestamp, assuming app never expires.") print("[Loki] No build timestamp; assuming app never expires.")
return .distantFuture return .distantFuture
} }
return .init(timeIntervalSince1970: buildTimestamp) return .init(timeIntervalSince1970: buildTimestamp)
}() }()
func keychainStorage() -> SSKKeychainStorage { override init() { super.init() }
return SSKDefaultKeychainStorage.shared
func canPresentNotifications() -> Bool { true }
func isAppForegroundAndActive() -> Bool { false }
func isInBackground() -> Bool { true }
func mainApplicationStateOnLaunch() -> UIApplication.State { .inactive }
func appDatabaseBaseDirectoryPath() -> String {
return appSharedDataDirectoryPath()
} }
func appDocumentDirectoryPath() -> String { func appDocumentDirectoryPath() -> String {
guard let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else { guard let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else {
owsFail("failed to query document directory") preconditionFailure("Couldn't get document directory.")
} }
return documentDirectoryURL.path return documentDirectoryURL.path
} }
func appSharedDataDirectoryPath() -> String { func appSharedDataDirectoryPath() -> String {
guard let groupContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SignalApplicationGroup) else { guard let groupContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SignalApplicationGroup) else {
owsFail("failed to query group container") preconditionFailure("Couldn't get shared data directory.")
} }
return groupContainerURL.path return groupContainerURL.path
} }
func appDatabaseBaseDirectoryPath() -> String {
return appSharedDataDirectoryPath()
}
func appUserDefaults() -> UserDefaults { func appUserDefaults() -> UserDefaults {
guard let userDefaults = UserDefaults(suiteName: SignalApplicationGroup) else { guard let userDefaults = UserDefaults(suiteName: SignalApplicationGroup) else {
owsFail("failed to initialize user defaults") preconditionFailure("Couldn't set up shared user defaults.")
} }
return userDefaults return userDefaults
} }
override init() { super.init() } func keychainStorage() -> SSKKeychainStorage {
return SSKDefaultKeychainStorage.shared
// MARK: - Unused in this extension }
// MARK: - Currently Unused
let frame = CGRect.zero
let interfaceOrientation = UIInterfaceOrientation.unknown
let isRTL = false let isRTL = false
let isRunningTests = false let isRunningTests = false
let reportedApplicationState = UIApplication.State.background
let statusBarHeight = CGFloat.zero
var mainWindow: UIWindow? var mainWindow: UIWindow?
let frame: CGRect = .zero
let interfaceOrientation: UIInterfaceOrientation = .unknown
let reportedApplicationState: UIApplication.State = .background
let statusBarHeight: CGFloat = .zero
func beginBackgroundTask(expirationHandler: @escaping BackgroundTaskExpirationHandler) -> UInt { 0 }
func endBackgroundTask(_ backgroundTaskIdentifier: UInt) {}
func beginBackgroundTask(expirationHandler: @escaping BackgroundTaskExpirationHandler) -> UIBackgroundTaskIdentifier { .invalid } func beginBackgroundTask(expirationHandler: @escaping BackgroundTaskExpirationHandler) -> UIBackgroundTaskIdentifier { .invalid }
func endBackgroundTask(_ backgroundTaskIdentifier: UIBackgroundTaskIdentifier) {} func beginBackgroundTask(expirationHandler: @escaping BackgroundTaskExpirationHandler) -> UInt { 0 }
func endBackgroundTask(_ backgroundTaskIdentifier: UIBackgroundTaskIdentifier) { }
func ensureSleepBlocking(_ shouldBeBlocking: Bool, blockingObjectsDescription: String) {} func endBackgroundTask(_ backgroundTaskIdentifier: UInt) { }
func ensureSleepBlocking(_ shouldBeBlocking: Bool, blockingObjects: [Any]) { }
func setMainAppBadgeNumber(_ value: Int) {} func ensureSleepBlocking(_ shouldBeBlocking: Bool, blockingObjectsDescription: String) { }
func setStatusBarHidden(_ isHidden: Bool, animated isAnimated: Bool) {}
func frontmostViewController() -> UIViewController? { nil } func frontmostViewController() -> UIViewController? { nil }
func runNowOr(whenMainAppIsActive block: @escaping AppActiveBlock) { }
func setNetworkActivityIndicatorVisible(_ value: Bool) {} func setMainAppBadgeNumber(_ value: Int) { }
func setNetworkActivityIndicatorVisible(_ value: Bool) { }
func runNowOr(whenMainAppIsActive block: @escaping AppActiveBlock) {} func setStatusBarHidden(_ isHidden: Bool, animated isAnimated: Bool) { }
func ensureSleepBlocking(_ shouldBeBlocking: Bool, blockingObjects: [Any]) {}
} }

@ -1 +1 @@
Subproject commit e1846369c87557efc66f7994c5e7d924e707e579 Subproject commit d81e847f499c83c17e3c0259462583e8ca0e2de5
Loading…
Cancel
Save