session-ios/Signal/src/util/MainAppContext.m

112 lines
3.1 KiB
Mathematica
Raw Normal View History

2017-11-29 20:51:39 +01:00
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "MainAppContext.h"
#import "Signal-Swift.h"
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/OWSIdentityManager.h>
2017-11-29 20:51:39 +01:00
2017-11-30 16:10:30 +01:00
NS_ASSUME_NONNULL_BEGIN
2017-11-29 20:51:39 +01:00
@implementation MainAppContext
- (BOOL)isMainApp
{
return YES;
}
- (BOOL)isMainAppAndActive
{
return [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
}
- (BOOL)isRTL
{
return
[[UIApplication sharedApplication] userInterfaceLayoutDirection] == UIUserInterfaceLayoutDirectionRightToLeft;
}
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle
{
[[UIApplication sharedApplication] setStatusBarStyle:statusBarStyle];
}
- (UIApplicationState)mainApplicationState
{
return [UIApplication sharedApplication].applicationState;
}
2017-11-29 20:51:39 +01:00
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
(BackgroundTaskExpirationHandler)expirationHandler
{
return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
}
- (void)endBackgroundTask:(UIBackgroundTaskIdentifier)backgroundTaskIdentifier
{
[UIApplication.sharedApplication endBackgroundTask:backgroundTaskIdentifier];
}
- (void)ensureSleepBlocking:(BOOL)shouldBeBlocking blockingObjects:(NSArray<id> *)blockingObjects;
{
if (UIApplication.sharedApplication.isIdleTimerDisabled != shouldBeBlocking) {
if (shouldBeBlocking) {
NSMutableString *logString = [NSMutableString
stringWithFormat:@"%@ Blocking sleep because of: %@", self.logTag, blockingObjects.firstObject];
if (blockingObjects.count > 1) {
[logString appendString:[NSString stringWithFormat:@"(and %lu others)", blockingObjects.count - 1]];
}
DDLogInfo(@"%@", logString);
} else {
DDLogInfo(@"%@ Unblocking Sleep.", self.logTag);
}
}
UIApplication.sharedApplication.idleTimerDisabled = shouldBeBlocking;
}
- (void)setMainAppBadgeNumber:(NSInteger)value
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:value];
}
- (nullable UIViewController *)frontmostViewController
{
return UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
}
- (nullable UIView *)rootReferenceView
{
return UIApplication.sharedApplication.keyWindow;
}
- (void)openSystemSettings
{
[UIApplication.sharedApplication openSystemSettings];
}
- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey
{
OWSAssert(profileKey);
[MultiDeviceProfileKeyUpdateJob runWithProfileKey:profileKey
identityManager:OWSIdentityManager.sharedManager
messageSender:Environment.current.messageSender
profileManager:OWSProfileManager.sharedManager];
}
2017-12-04 18:38:44 +01:00
- (BOOL)isRunningTests
{
return getenv("runningTests_dontStartApp");
}
2017-12-04 22:09:26 +01:00
- (void)setNetworkActivityIndicatorVisible:(BOOL)value
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:value];
}
2017-11-29 20:51:39 +01:00
@end
2017-11-30 16:10:30 +01:00
NS_ASSUME_NONNULL_END