mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			89 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			89 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Swift
		
	
| 
								 
											7 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								//  Copyright (c) 2019 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import Foundation
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								import SignalUtilitiesKit
							 | 
						||
| 
								 | 
							
								import SignalUtilitiesKit
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								@objc public class AppEnvironment: NSObject {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    private static var _shared: AppEnvironment = AppEnvironment()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    @objc
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    public class var shared: AppEnvironment {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        get {
							 | 
						||
| 
								 | 
							
								            return _shared
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        set {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								            guard CurrentAppContext().isRunningTests else {
							 | 
						||
| 
								 | 
							
								                owsFailDebug("Can only switch environments in tests.")
							 | 
						||
| 
								 | 
							
								                return
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								            _shared = newValue
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public var accountManager: AccountManager
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    @objc
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    public var notificationPresenter: NotificationPresenter
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    @objc
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    public var pushRegistrationManager: PushRegistrationManager
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public var backup: OWSBackup
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    private var _legacyNotificationActionHandler: LegacyNotificationActionHandler
							 | 
						||
| 
								 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public var legacyNotificationActionHandler: LegacyNotificationActionHandler {
							 | 
						||
| 
								 | 
							
								        get {
							 | 
						||
| 
								 | 
							
								            if #available(iOS 10, *) {
							 | 
						||
| 
								 | 
							
								                owsFailDebug("shouldn't user legacyNotificationActionHandler on modern iOS")
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								            return _legacyNotificationActionHandler
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        set {
							 | 
						||
| 
								 | 
							
								            _legacyNotificationActionHandler = newValue
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // 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
							 | 
						||
| 
								 | 
							
								    @available(iOS 10.0, *)
							 | 
						||
| 
								 | 
							
								    public var userNotificationActionHandler: UserNotificationActionHandler {
							 | 
						||
| 
								 | 
							
								        return _userNotificationActionHandler as! UserNotificationActionHandler
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public var backupLazyRestore: BackupLazyRestore
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    private override init() {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        self.accountManager = AccountManager()
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        self.notificationPresenter = NotificationPresenter()
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        self.pushRegistrationManager = PushRegistrationManager()
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        self.backup = OWSBackup()
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        self.backupLazyRestore = BackupLazyRestore()
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        if #available(iOS 10.0, *) {
							 | 
						||
| 
								 | 
							
								            self._userNotificationActionHandler = UserNotificationActionHandler()
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        self._legacyNotificationActionHandler = LegacyNotificationActionHandler()
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        super.init()
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        SwiftSingletons.register(self)
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public func setup() {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        // Hang certain singletons on SSKEnvironment too.
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        SSKEnvironment.shared.notificationsManager = notificationPresenter
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |