session-ios/Session/Meta/AppEnvironment.swift

82 lines
2.2 KiB
Swift
Raw Normal View History

2018-10-15 20:34:41 +02:00
//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
2018-10-15 20:34:41 +02:00
//
import Foundation
2020-11-11 07:45:50 +01:00
import SignalUtilitiesKit
import SignalUtilitiesKit
2018-10-15 20:58:15 +02:00
2018-10-15 21:51:43 +02:00
@objc public class AppEnvironment: NSObject {
private static var _shared: AppEnvironment = AppEnvironment()
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public class var shared: AppEnvironment {
2018-10-15 20:58:15 +02:00
get {
return _shared
}
set {
2018-10-15 21:51:43 +02:00
guard CurrentAppContext().isRunningTests else {
owsFailDebug("Can only switch environments in tests.")
return
}
2018-10-15 20:34:41 +02:00
_shared = newValue
}
}
2018-10-15 21:51:43 +02:00
@objc
public var accountManager: AccountManager
2018-10-15 20:58:15 +02:00
@objc
public var notificationPresenter: NotificationPresenter
2018-10-15 21:51:43 +02:00
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public var pushRegistrationManager: PushRegistrationManager
2018-11-19 15:36:18 +01:00
@objc
public var backup: OWSBackup
2021-10-01 01:18:40 +02:00
@objc
public var fileLogger: DDFileLogger
2018-11-19 15:36:18 +01:00
// Stored properties cannot be marked as `@available`, only classes and functions.
// Instead, store a private `Any` and wrap it with a public `@available` getter
private var _userNotificationActionHandler: Any?
@objc
public var userNotificationActionHandler: UserNotificationActionHandler {
return _userNotificationActionHandler as! UserNotificationActionHandler
}
2018-11-29 18:09:18 +01:00
@objc
public var backupLazyRestore: BackupLazyRestore
2018-10-15 21:11:20 +02:00
private override init() {
2018-10-16 17:47:54 +02:00
self.accountManager = AccountManager()
self.notificationPresenter = NotificationPresenter()
2018-10-16 17:47:54 +02:00
self.pushRegistrationManager = PushRegistrationManager()
2018-11-21 18:25:24 +01:00
self.backup = OWSBackup()
2018-11-29 18:09:18 +01:00
self.backupLazyRestore = BackupLazyRestore()
2021-02-23 05:38:55 +01:00
self._userNotificationActionHandler = UserNotificationActionHandler()
2021-10-01 01:18:40 +02:00
self.fileLogger = DDFileLogger()
2018-10-15 21:51:43 +02:00
2018-10-15 20:58:15 +02:00
super.init()
2018-10-15 21:51:43 +02:00
2018-10-15 20:58:15 +02:00
SwiftSingletons.register(self)
2018-10-15 20:34:41 +02:00
}
2018-10-15 21:51:43 +02:00
@objc
public func setup() {
2018-10-15 20:34:41 +02:00
// Hang certain singletons on SSKEnvironment too.
SSKEnvironment.shared.notificationsManager = notificationPresenter
2021-10-01 01:18:40 +02:00
setupLogFiles()
}
private func setupLogFiles() {
fileLogger.rollingFrequency = kDayInterval // Refresh everyday
fileLogger.logFileManager.maximumNumberOfLogFiles = 3 // Save 3 days' log files
DDLog.add(fileLogger)
2018-10-15 20:34:41 +02:00
}
}