Files
Sparkle/InstallerStatus/SUInstallerStatus.m
T
Zorg 8563a40cd2 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.
2016-07-12 19:59:24 -04:00

79 lines
2.1 KiB
Objective-C

//
// SUInstallerStatus.m
// InstallerStatus
//
// Created by Mayur Pawashe on 7/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import "SUInstallerStatus.h"
#import "SUSystemAuthorization.h"
@interface SUInstallerStatus ()
@property (nonatomic, copy) void (^invalidationBlock)(void);
@property (nonatomic) NSXPCConnection *connection;
@end
@implementation SUInstallerStatus
@synthesize invalidationBlock = _invalidationBlock;
@synthesize connection = _connection;
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
{
self.invalidationBlock = invalidationHandler;
}
- (void)setServiceName:(NSString *)serviceName
{
NSXPCConnectionOptions options = SUGrantsSystemAuthorizationAccess() ? NSXPCConnectionPrivileged : 0;
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:options];
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUStatusInfoProtocol)];
self.connection = connection;
__weak SUInstallerStatus *weakSelf = self;
self.connection.interruptionHandler = ^{
[weakSelf invalidate];
};
self.connection.invalidationHandler = ^{
SUInstallerStatus *strongSelf = weakSelf;
if (strongSelf != nil) {
strongSelf.connection = nil;
[strongSelf invalidate];
}
};
[self.connection resume];
}
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable installationInfoData))reply
{
[self.connection.remoteObjectProxy probeStatusInfoWithReply:reply];
}
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply
{
[self.connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
}
// This method can be called by us or from a remote
- (void)invalidate
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.connection invalidate];
self.connection = nil;
if (self.invalidationBlock != nil) {
self.invalidationBlock();
self.invalidationBlock = nil;
}
});
}
@end