Browse Source

updater is singleton

works_for_me
Volker Birk 2 years ago
parent
commit
70c41939bd
4 changed files with 37 additions and 17 deletions
  1. +4
    -0
      pEpMacOSAdapter/main.m
  2. +12
    -13
      pEpMacOSAdapter/pEpMacOSAdapter.m
  3. +3
    -0
      pEpMacOSAdapter/pEpUpdater.h
  4. +18
    -4
      pEpMacOSAdapter/pEpUpdater.mm

+ 4
- 0
pEpMacOSAdapter/main.m View File

@ -10,6 +10,9 @@
#include <signal.h>
#import <Foundation/Foundation.h>
#import "pEpMacOSAdapter.h"
#import "pEpUpdater.h"
pEpUpdater* updater = nil;
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
@end
@ -59,6 +62,7 @@ void signal_TERM(int signal)
int main(int argc, const char *argv[])
{
signal(SIGTERM, signal_TERM);
updater = [pEpUpdater new];
// Create the delegate for the service.
ServiceDelegate *delegate = [ServiceDelegate new];


+ 12
- 13
pEpMacOSAdapter/pEpMacOSAdapter.m View File

@ -10,7 +10,7 @@
#import "pEpMacOSAdapter.h"
#import "pEpUpdater.h"
static pEpUpdater* _updater = nil;
extern pEpUpdater* updater;
@implementation pEpMacOSAdapter
@ -20,11 +20,15 @@ static pEpUpdater* _updater = nil;
{
NSLog(@"subscribeForUpdate called");
if (!updater) {
updater = [pEpUpdater new];
}
_clientConnection = [[NSXPCConnection alloc] initWithListenerEndpoint:endpoint];
_clientConnection.remoteObjectInterface = [NSXPCInterface
interfaceWithProtocol:@protocol(pEpNotificationProtocol)];
_clientConnection.interruptionHandler = ^(){NSLog(@"interruption");};
_clientConnection.invalidationHandler = ^(){NSLog(@"invalidation");};
_clientConnection.interruptionHandler = ^(){NSLog(@"interruption"); updater.subscriber=nil;};
_clientConnection.invalidationHandler = ^(){NSLog(@"invalidation"); updater.subscriber=nil;};
[_clientConnection resume];
@ -32,28 +36,23 @@ static pEpUpdater* _updater = nil;
NSLog(@"%@", err);
}];
updater.subscriber = downloadNotification;
if (downloadNotification) {
if (!_updater) {
_updater = [[pEpUpdater alloc] initWithSubscriber:downloadNotification];
[_updater scheduleUpdates];
}
else {
_updater.subscriber = downloadNotification;
}
[downloadNotification notifyDownload:ready withName:@"" withFilename:@""];
}
}
- (void)unsubscribeForUpdate
{
NSLog(@"unsubscribeForUpdate called");
_updater.subscriber = nil;
updater.subscriber = nil;
}
- (void)updateNow
{
NSLog(@"updateNow called");
if (_updater) {
[_updater updateAll:nil];
if (updater) {
[updater updateAll:nil];
}
}


+ 3
- 0
pEpMacOSAdapter/pEpUpdater.h View File

@ -22,6 +22,9 @@
/// subscriber for notifications
@property (strong) pEpNotification* subscriber;
/// initializes the pEpUpdater
- (id)init;
/// initializes the pEpUpdater
///
/// - parameter subscriber: object fulfilling the `pEpMacOSAdapterSubscriberProtocol`.


+ 18
- 4
pEpMacOSAdapter/pEpUpdater.mm View File

@ -11,16 +11,30 @@
#include "../../downloadclient/downloadclient.hh"
static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
const double CYCLE = 7200.0; // 7200 seconds = 2 hours
NSString* CONFIG_PATH = @"/Library/Application Support/pEp/Updater";
@implementation pEpUpdater
- (id)init
{
self = [super init];
if (self) {
self.configPath = CONFIG_PATH;
}
return self;
}
- (id)initWithSubscriber:(pEpNotification*)subscriber
{
self = [super init];
self.configPath = @"/Library/Application Support/pEp/Updater";
self.subscriber = subscriber;
[_subscriber notifyDownload:ready withName:@"" withFilename:@""];
if (self) {
self.configPath = CONFIG_PATH;
self.subscriber = subscriber;
if (self.subscriber) {
[_subscriber notifyDownload:ready withName:@"" withFilename:@""];
}
}
return self;
}


Loading…
Cancel
Save