app: prevent sleeping with timed events
Change-Id: Id70f5ddf592f9e658c201246a0cebe14e278284a
Reviewed-by: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
diff --git a/src/AppDelegate.mm b/src/AppDelegate.mm
index bb0d719..a7dd326 100644
--- a/src/AppDelegate.mm
+++ b/src/AppDelegate.mm
@@ -55,6 +55,8 @@
@implementation AppDelegate
+NSTimer* preventSleepTimer;
+
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"];
@@ -74,6 +76,18 @@
queue = dispatch_queue_create("scNetworkReachability", DISPATCH_QUEUE_SERIAL);
[self setScNetworkQueue:queue];
[self beginObservingReachabilityStatus];
+ [self startSleepPreventionTimer];
+}
+
+- (void) startSleepPreventionTimer
+{
+ if (preventSleepTimer != nil) {
+ [preventSleepTimer invalidate];
+ }
+ preventSleepTimer = [NSTimer timerWithTimeInterval:30.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
+ UpdateSystemActivity(OverallAct);
+ }];
+ [[NSRunLoop mainRunLoop] addTimer:preventSleepTimer forMode:NSRunLoopCommonModes];
}
- (void) beginObservingReachabilityStatus
@@ -303,6 +317,9 @@
- (void) cleanExit
{
+ if (preventSleepTimer != nil) {
+ [preventSleepTimer invalidate];
+ }
[self.wizard close];
[self.ringWindowController close];
delete CallModel::instance().QObject::parent();