Browse Source

schedule on main thread

works_for_me
Volker Birk 2 years ago
parent
commit
dfcb5c3e42
3 changed files with 19 additions and 11 deletions
  1. +4
    -1
      pEpMacOSAdapter/main.m
  2. +2
    -2
      pEpMacOSAdapter/pEpUpdater.h
  3. +13
    -8
      pEpMacOSAdapter/pEpUpdater.mm

+ 4
- 1
pEpMacOSAdapter/main.m View File

@ -72,7 +72,10 @@ int main(int argc, const char *argv[])
NSLog(@"starting agent");
listener.delegate = delegate;
[listener resume];
[[NSRunLoop currentRunLoop] run];
NSLog(@"going into main runLoop");
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
[runLoop run];
return EXIT_FAILURE;
}

+ 2
- 2
pEpMacOSAdapter/pEpUpdater.h View File

@ -14,13 +14,13 @@
@interface pEpUpdater : NSObject
/// default 2 hours = 7200 seconds
@property (strong) NSTimer* timer;
@property (retain) NSTimer* timer;
/// path with config files
@property (retain) NSString* configPath;
/// subscriber for notifications
@property (strong) pEpNotification* subscriber;
@property (retain) pEpNotification* subscriber;
/// initializes the pEpUpdater
- (id)init;


+ 13
- 8
pEpMacOSAdapter/pEpUpdater.mm View File

@ -11,7 +11,7 @@
#include "../../downloadclient/downloadclient.hh"
const double CYCLE = 7200; // 7200 seconds = 2 hours
const double CYCLE = 7.2; // 7200 seconds = 2 hours
NSString* CONFIG_PATH = @"/Library/Application Support/pEp/Updater";
@implementation pEpUpdater
@ -27,20 +27,25 @@ NSString* CONFIG_PATH = @"/Library/Application Support/pEp/Updater";
- (void)scheduleUpdates
{
NSLog(@"schedule updates");
if (!self.timer) {
self.timer = [NSTimer scheduledTimerWithTimeInterval:CYCLE target:self
selector:@selector(updateAll:)
userInfo:nil repeats:YES];
NSLog(@"schedule updates");
dispatch_async(dispatch_get_main_queue(), ^{
self.timer = [NSTimer scheduledTimerWithTimeInterval:CYCLE
target:self
selector:@selector(updateAll:)
userInfo:nil
repeats:YES];
});
}
else {
NSLog(@"timer already there");
}
}
- (void)stopUpdates
{
NSLog(@"stop auto updates");
if (self.timer) {
NSLog(@"stop auto updates");
[self.timer invalidate];
self.timer = nil;
}


Loading…
Cancel
Save