2020-11-16 00:34:47 +01:00
|
|
|
|
2020-11-11 06:30:54 +01:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "OWSWindowManager.h"
|
2020-11-26 00:37:56 +01:00
|
|
|
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>
|
2018-08-31 19:44:13 +02:00
|
|
|
#import "OWSPreferences.h"
|
2020-11-11 06:30:54 +01:00
|
|
|
#import "OWSSounds.h"
|
2017-12-01 21:17:29 +01:00
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
static Environment *sharedEnvironment = nil;
|
2017-12-01 21:17:29 +01:00
|
|
|
|
2018-10-15 18:50:07 +02:00
|
|
|
@interface Environment ()
|
|
|
|
|
2021-08-02 07:43:50 +02:00
|
|
|
@property (nonatomic) OWSAudioSession *audioSessionRef;
|
2018-10-15 18:50:07 +02:00
|
|
|
@property (nonatomic) OWSPreferences *preferences;
|
2018-10-24 22:38:05 +02:00
|
|
|
@property (nonatomic) id<OWSProximityMonitoringManager> proximityMonitoringManager;
|
2018-10-15 18:50:07 +02:00
|
|
|
@property (nonatomic) OWSSounds *sounds;
|
|
|
|
@property (nonatomic) OWSWindowManager *windowManager;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2017-12-01 21:17:29 +01:00
|
|
|
@implementation Environment
|
|
|
|
|
2018-08-31 19:16:31 +02:00
|
|
|
+ (Environment *)shared
|
2017-12-01 21:17:29 +01:00
|
|
|
{
|
2017-12-04 16:35:47 +01:00
|
|
|
return sharedEnvironment;
|
2017-12-01 21:17:29 +01:00
|
|
|
}
|
|
|
|
|
2018-08-31 19:16:31 +02:00
|
|
|
+ (void)setShared:(Environment *)environment
|
2017-12-01 21:17:29 +01:00
|
|
|
{
|
2017-12-07 19:53:13 +01:00
|
|
|
// The main app environment should only be set once.
|
|
|
|
//
|
|
|
|
// App extensions may be opened multiple times in the same process,
|
|
|
|
// so statics will persist.
|
2017-12-04 16:35:47 +01:00
|
|
|
|
|
|
|
sharedEnvironment = environment;
|
2017-12-01 21:17:29 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 23:19:24 +02:00
|
|
|
+ (void)clearSharedForTests
|
2017-12-05 19:42:50 +01:00
|
|
|
{
|
|
|
|
sharedEnvironment = nil;
|
|
|
|
}
|
|
|
|
|
2018-10-23 02:55:39 +02:00
|
|
|
- (instancetype)initWithAudioSession:(OWSAudioSession *)audioSession
|
|
|
|
preferences:(OWSPreferences *)preferences
|
2018-10-24 22:38:05 +02:00
|
|
|
proximityMonitoringManager:(id<OWSProximityMonitoringManager>)proximityMonitoringManager
|
2018-10-23 02:55:39 +02:00
|
|
|
sounds:(OWSSounds *)sounds
|
|
|
|
windowManager:(OWSWindowManager *)windowManager
|
|
|
|
{
|
2017-12-01 21:17:29 +01:00
|
|
|
self = [super init];
|
2020-11-16 00:34:47 +01:00
|
|
|
|
2017-12-01 21:17:29 +01:00
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-02 07:43:50 +02:00
|
|
|
_audioSessionRef = audioSession;
|
2018-09-17 15:27:58 +02:00
|
|
|
_preferences = preferences;
|
2018-10-24 22:38:05 +02:00
|
|
|
_proximityMonitoringManager = proximityMonitoringManager;
|
2018-10-12 22:39:40 +02:00
|
|
|
_sounds = sounds;
|
|
|
|
_windowManager = windowManager;
|
2021-04-08 05:36:20 +02:00
|
|
|
_isRequestingPermission = false;
|
2017-12-01 21:17:29 +01:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|