session-ios/LokiPushNotificationService/NotificationServiceExtensio...

95 lines
3.3 KiB
Swift

//
// Copyright (c) 2020 Open Whisper Systems. All rights reserved.
//
import Foundation
import SignalServiceKit
import SignalMessaging
class NotificationServiceExtensionContext: NSObject, AppContext {
var wasWokenUpBySilentPushNotification: Bool = true
var openSystemSettingsAction: UIAlertAction?
let isMainApp = false
let isMainAppAndActive = false
func isInBackground() -> Bool { true }
func isAppForegroundAndActive() -> Bool { false }
func mainApplicationStateOnLaunch() -> UIApplication.State { .inactive }
var shouldProcessIncomingMessages: Bool { true }
func canPresentNotifications() -> Bool { true }
let appLaunchTime = Date()
lazy var buildTime: Date = {
guard let buildTimestamp = Bundle.main.object(forInfoDictionaryKey: "BuildTimestamp") as? TimeInterval, buildTimestamp > 0 else {
Logger.debug("No build timestamp, assuming app never expires.")
return .distantFuture
}
return .init(timeIntervalSince1970: buildTimestamp)
}()
func keychainStorage() -> SSKKeychainStorage {
return SSKDefaultKeychainStorage.shared
}
func appDocumentDirectoryPath() -> String {
guard let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else {
owsFail("failed to query document directory")
}
return documentDirectoryURL.path
}
func appSharedDataDirectoryPath() -> String {
guard let groupContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SignalApplicationGroup) else {
owsFail("failed to query group container")
}
return groupContainerURL.path
}
func appDatabaseBaseDirectoryPath() -> String {
return appSharedDataDirectoryPath()
}
func appUserDefaults() -> UserDefaults {
guard let userDefaults = UserDefaults(suiteName: SignalApplicationGroup) else {
owsFail("failed to initialize user defaults")
}
return userDefaults
}
override init() { super.init() }
// MARK: - Unused in this extension
let isRTL = false
let isRunningTests = false
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 endBackgroundTask(_ backgroundTaskIdentifier: UIBackgroundTaskIdentifier) {}
func ensureSleepBlocking(_ shouldBeBlocking: Bool, blockingObjectsDescription: String) {}
func setMainAppBadgeNumber(_ value: Int) {}
func setStatusBarHidden(_ isHidden: Bool, animated isAnimated: Bool) {}
func frontmostViewController() -> UIViewController? { nil }
func setNetworkActivityIndicatorVisible(_ value: Bool) {}
func runNowOr(whenMainAppIsActive block: @escaping AppActiveBlock) {}
func ensureSleepBlocking(_ shouldBeBlocking: Bool, blockingObjects: [Any]) {}
}