pEp macOS Desktop adapter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.0 KiB

// main.m
// pEpMacOSAdapter
// Created by Volker Birk on 20.04.20.
// Copyleft © 2020 p≡p foundation.
// This file is under GNU General Public License 3.0
#include <signal.h>
#import <Foundation/Foundation.h>
#import <AppKit/NSWorkspace.h>
#import "pEpMacOSAdapter.h"
#import "pEpUpdater.h"
const NSString *kMachServiceName=@"";
pEpUpdater* updater = nil;
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
@implementation ServiceDelegate
- (id)init{
self = [super init];
return self;
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
NSLog(@"incoming connection");
// Configure the connection.
// First, set the interface that the exported object implements.
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(pEpMacOSAdapterProtocol)];
// Next, set the object that the connection exports. All messages sent on
// the connection to this service will be sent to the exported object to
// handle. The connection retains the exported object.
pEpMacOSAdapter *exportedObject = [pEpMacOSAdapter new];
newConnection.exportedObject = exportedObject;
if (!newConnection.exportedInterface || !newConnection.exportedObject) {
NSLog(@"failed to allocate object and interface");
return NO;
// Resuming the connection allows the system to deliver more incoming messages.
[newConnection resume];
// Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
NSLog(@"connection accepted");
return YES;
BOOL start_helper(void)
fileURLWithPath:@"/Library/Application Support/pEp/≡p"];
//return [[NSWorkspace sharedWorkspace] openURL:url];
return true;
void signal_TERM(int signal)
NSLog(@"stopping agent");
int main(int argc, const char *argv[])
signal(SIGTERM, signal_TERM);
updater = [pEpUpdater new];
// Create the delegate for the service.
ServiceDelegate *delegate = [ServiceDelegate new];
// Set up the one NSXPCListener for this service. It will handle all incoming connections.
NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName:kMachServiceName/*@"foundation.pEp.adapter.macOS"*/];
NSLog(@"Starting service [%@] ...", kMachServiceName);
listener.delegate = delegate;
[listener resume];
// start the GUI helper app
BOOL opened = start_helper();
/* FIXME: Modification to be reverted */
NSLog(@"going into main runLoop");
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
[runLoop run];