mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Use XPC for IPC to the installer instead of CFMessagePort
We now use XPC for communication between Sparkle.framework and Autoupdate. Autoupdate is now ran as a launchd agaent/daemon. (Most of the time, it acts as an agent). Using XPC can only be done from non-sandboxed processes, so a connection and status service had to be created. Currently, the GUI progress tool doesn't work properly, but everything else should be behaving like before.
This commit is contained in:
1 parent
80bc8353ed
commit
8563a40cd2
59 files changed
+1394
-1521
No files matched your search
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// SUXPCInstallerConnection.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUXPCInstallerConnection.h"
|
||||
|
||||
@interface SUXPCInstallerConnection ()
|
||||
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
@property (nonatomic) id<SUInstallerCommunicationProtocol> delegate; // intentionally not weak for XPC reasons
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUXPCInstallerConnection
|
||||
|
||||
@synthesize connection = _connection;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_connection = [[NSXPCConnection alloc] initWithServiceName:@INSTALLER_CONNECTION_BUNDLE_ID];
|
||||
_connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerConnectionProtocol)];
|
||||
|
||||
__weak SUXPCInstallerConnection *weakSelf = self;
|
||||
_connection.invalidationHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
};
|
||||
|
||||
_connection.interruptionHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
[weakSelf.connection invalidate];
|
||||
};
|
||||
|
||||
_delegate = delegate;
|
||||
|
||||
_connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
_connection.exportedObject = _delegate;
|
||||
|
||||
[_connection resume];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
|
||||
{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
|
||||
__weak SUXPCInstallerConnection *weakSelf = self;
|
||||
[self.connection.remoteObjectProxy setInvalidationHandler:^{
|
||||
[weakSelf invokeInvalidation];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName
|
||||
{
|
||||
[self.connection.remoteObjectProxy setServiceName:serviceName];
|
||||
}
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
[self.connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
[self.connection.remoteObjectProxy invalidate];
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
}
|
||||
|
||||
- (void)invokeInvalidation
|
||||
{
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
}
|
||||
// Break our retain cycle
|
||||
self.delegate = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user