summaryrefslogtreecommitdiffstats
path: root/macosx/HBRemoteCore.m
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/HBRemoteCore.m')
-rw-r--r--macosx/HBRemoteCore.m72
1 files changed, 53 insertions, 19 deletions
diff --git a/macosx/HBRemoteCore.m b/macosx/HBRemoteCore.m
index b3db5b37b..7ed606ae2 100644
--- a/macosx/HBRemoteCore.m
+++ b/macosx/HBRemoteCore.m
@@ -14,6 +14,8 @@
@property (nonatomic, readonly) id<HBRemoteCoreProtocol> proxy;
@property (nonatomic, readwrite) HBState state;
+@property (nonatomic, readonly) NSInteger level;
+@property (nonatomic, readonly, copy) NSString *name;
@property (nonatomic, readwrite, copy) HBCoreProgressHandler progressHandler;
@property (nonatomic, readwrite, copy) HBCoreCompletionHandler completionHandler;
@@ -44,29 +46,54 @@
_connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HBRemoteProgressProtocol)];
_connection.exportedObject = self;
- _proxy = [_connection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
-
- }];
+ __weak HBRemoteCore *weakSelf = self;
+
+ _connection.interruptionHandler = ^{
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ [weakSelf handleInterruption];
+ });
+ };
+
+ _proxy = [_connection remoteObjectProxy];
[_connection resume];
}
+
+- (void)invalidate
+{
+ [[_connection synchronousRemoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {}] tearDown];
+ [_connection invalidate];
+ _connection = nil;
+}
+
+- (void)handleInterruption
+{
+ if (self.state != HBStateIdle)
+ {
+ self.progressHandler = nil;
+ if (self.completionHandler)
+ {
+ self.completionHandler(HBCoreResultFailed);
+ }
+ self.completionHandler = nil;
+ self.state = HBStateIdle;
+ }
+ [_proxy setUpWithLogLevel:self.level name:self.name];
+}
+
- (instancetype)initWithLogLevel:(NSInteger)level name:(NSString *)name
{
self = [self init];
if (self)
{
+ _level = level;
+ _name = name;
[_proxy setUpWithLogLevel:level name:name];
}
return self;
}
-- (void)dealloc
-{
- [_connection.remoteObjectProxy tearDown];
- [_connection invalidate];
-}
-
- (void)updateState:(HBState)state {
dispatch_sync(dispatch_get_main_queue(), ^{
self.state = state;
@@ -94,14 +121,16 @@
self.completionHandler = completionHandler;
NSData *bookmark = [url bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];
- [_connection.remoteObjectProxy provideResourceAccessWithBookmarks:@[bookmark]];
+ [_proxy provideResourceAccessWithBookmarks:@[bookmark]];
self.state = HBStateScanning;
- [_connection.remoteObjectProxy scanURL:url titleIndex:index previews:previewsNum minDuration:seconds withReply:^(HBCoreResult result) {
+ __weak HBRemoteCore *weakSelf = self;
+
+ [_proxy scanURL:url titleIndex:index previews:previewsNum minDuration:seconds withReply:^(HBCoreResult result) {
dispatch_sync(dispatch_get_main_queue(), ^{
- self.progressHandler = nil;
- self.completionHandler(result);
+ weakSelf.progressHandler = nil;
+ weakSelf.completionHandler(result);
});
}];
}
@@ -114,17 +143,19 @@
- (void)encodeJob:(HBJob *)job progressHandler:(HBCoreProgressHandler)progressHandler completionHandler:(HBCoreCompletionHandler)completionHandler
{
NSData *bookmark = [job.outputURL bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];
- [_connection.remoteObjectProxy provideResourceAccessWithBookmarks:@[bookmark]];
+ [_proxy provideResourceAccessWithBookmarks:@[bookmark]];
self.progressHandler = progressHandler;
self.completionHandler = completionHandler;
self.state = HBStateWorking;
- [_connection.remoteObjectProxy encodeJob:job withReply:^(HBCoreResult result) {
+ __weak HBRemoteCore *weakSelf = self;
+
+ [_proxy encodeJob:job withReply:^(HBCoreResult result) {
dispatch_sync(dispatch_get_main_queue(), ^{
- self.progressHandler = nil;
- self.completionHandler(result);
+ weakSelf.progressHandler = nil;
+ weakSelf.completionHandler(result);
});
}];
}
@@ -135,10 +166,13 @@
}
- (void)updateProgress:(double)currentProgress hours:(int)hours minutes:(int)minutes seconds:(int)seconds state:(HBState)state info:(NSString *)info {
+
+ __weak HBRemoteCore *weakSelf = self;
+
dispatch_sync(dispatch_get_main_queue(), ^{
HBProgress progress = {currentProgress , hours, minutes, seconds};
- self.state = state;
- self.progressHandler(state, progress, info);
+ weakSelf.state = state;
+ weakSelf.progressHandler(state, progress, info);
});
}