updater is singleton

APPLEMAIL-28
Volker Birk 2020-06-12 10:15:35 +02:00
parent 652ac8b70c
commit 70c41939bd
4 changed files with 37 additions and 17 deletions

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];

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];
}
}

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`.

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;
}