Skip to content

Commit

Permalink
process: disable macOS code from iOS builds
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Mar 4, 2024
1 parent 17a901c commit 3c36d80
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Services/UTMProcess.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ @interface UTMProcess ()
@implementation UTMProcess {
NSMutableArray<NSString *> *_argv;
NSMutableArray<NSURL *> *_urls;
#if TARGET_OS_OSX
NSXPCConnection *_connection;
#endif
}

static void *startProcess(void *args) {
Expand Down Expand Up @@ -92,7 +94,11 @@ - (NSURL *)libraryURL {
}

- (BOOL)hasRemoteProcess {
#if TARGET_OS_OSX
return _connection != nil;
#else
return NO;
#endif
}

- (NSString *)arguments {
Expand Down Expand Up @@ -219,6 +225,7 @@ - (void)startDylibThread:(nonnull NSString *)dylib completion:(nonnull void (^)(
completion(nil);
}

#if TARGET_OS_OSX
- (void)startQemuRemote:(nonnull NSString *)name completion:(nonnull void (^)(NSError * _Nullable))completion {
NSError *error;
NSData *libBookmark = [self.libraryURL bookmarkDataWithOptions:0
Expand Down Expand Up @@ -253,6 +260,7 @@ - (void)startQemuRemote:(nonnull NSString *)name completion:(nonnull void (^)(NS
}
}];
}
#endif

- (void)startProcess:(nonnull NSString *)name completion:(nonnull void (^)(NSError * _Nullable))completion {
#if TARGET_OS_IPHONE
Expand All @@ -262,18 +270,24 @@ - (void)startProcess:(nonnull NSString *)name completion:(nonnull void (^)(NSErr
#endif
NSString *dylib = [NSString stringWithFormat:@"%@.framework/%@%@", name, base, name];
self.processName = name;
#if TARGET_OS_OSX
if (_connection) {
[self startQemuRemote:dylib completion:completion];
} else {
#endif
[self startDylibThread:dylib completion:completion];
#if TARGET_OS_OSX
}
#endif
}

- (void)stopProcess {
#if TARGET_OS_OSX
if (_connection) {
[[_connection remoteObjectProxy] terminate];
[_connection invalidate];
}
#endif
for (NSURL *url in _urls) {
[url stopAccessingSecurityScopedResource];
}
Expand Down Expand Up @@ -320,11 +334,15 @@ - (void)accessDataWithBookmark:(NSData *)bookmark {
}

- (void)accessDataWithBookmark:(NSData *)bookmark securityScoped:(BOOL)securityScoped completion:(void(^)(BOOL, NSData * _Nullable, NSString * _Nullable))completion {
#if TARGET_OS_OSX
if (_connection) {
[[_connection remoteObjectProxy] accessDataWithBookmark:bookmark securityScoped:securityScoped completion:completion];
} else {
#endif
[self accessDataWithBookmarkThread:bookmark securityScoped:securityScoped completion:completion];
#if TARGET_OS_OSX
}
#endif
}

- (void)stopAccessingPathThread:(nullable NSString *)path {
Expand All @@ -342,11 +360,15 @@ - (void)stopAccessingPathThread:(nullable NSString *)path {
}

- (void)stopAccessingPath:(nullable NSString *)path {
#if TARGET_OS_OSX
if (_connection) {
[[_connection remoteObjectProxy] stopAccessingPath:path];
} else {
#endif
[self stopAccessingPathThread:path];
#if TARGET_OS_OSX
}
#endif
}

- (NSError *)errorWithMessage:(nullable NSString *)message {
Expand Down

0 comments on commit 3c36d80

Please sign in to comment.