Files
Sparkle/InstallerStatus/SUXPCInstallerStatus.m
T
Kent Sutherland d574574345 Explicitly specify types to silence "Messaging unqualified id" warning that's new in Xcode 10.
Removed __has_feature(objc_generics) check and use generisc to help silence the warnings.
2018-06-14 21:22:38 +02:00

89 lines
2.3 KiB
Objective-C

//
// SUXPCInstallerStatus.m
// Sparkle
//
// Created by Mayur Pawashe on 7/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import "SUXPCInstallerStatus.h"
#include "AppKitPrevention.h"
@interface SUXPCInstallerStatus ()
@property (nonatomic) NSXPCConnection *connection;
@property (nonatomic, copy) void (^invalidationBlock)(void);
@end
@implementation SUXPCInstallerStatus
@synthesize connection = _connection;
@synthesize invalidationBlock = _invalidationBlock;
- (instancetype)init
{
self = [super init];
if (self != nil) {
_connection = [[NSXPCConnection alloc] initWithServiceName:@INSTALLER_STATUS_BUNDLE_ID];
_connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerStatusProtocol)];
__weak SUXPCInstallerStatus *weakSelf = self;
_connection.invalidationHandler = ^{
[weakSelf invokeInvalidation];
};
_connection.interruptionHandler = ^{
[weakSelf invokeInvalidation];
[weakSelf.connection invalidate];
};
[_connection resume];
}
return self;
}
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
{
self.invalidationBlock = invalidationHandler;
__weak SUXPCInstallerStatus *weakSelf = self;
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy setInvalidationHandler:^{
[weakSelf invokeInvalidation];
}];
}
- (void)setServiceName:(NSString *)serviceName
{
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy setServiceName:serviceName];
}
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable installationInfoData))reply
{
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy probeStatusInfoWithReply:reply];
}
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply
{
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
}
- (void)invalidate
{
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy invalidate];
[self.connection invalidate];
self.connection = nil;
}
- (void)invokeInvalidation
{
if (self.invalidationBlock != nil) {
self.invalidationBlock();
self.invalidationBlock = nil;
}
}
@end