@@ -27,6 +27,7 @@ @interface AppDelegate () {
2727 FSEventStreamRef fsEventStream;
2828 NSString * plistPath;
2929 NSString * pacPath;
30+ dispatch_queue_t taskQueue;
3031}
3132
3233@end
@@ -36,6 +37,9 @@ @implementation AppDelegate
3637static AppDelegate *appDelegate;
3738
3839- (void )applicationDidFinishLaunching : (NSNotification *)aNotification {
40+ // create a serial queue used for NSTask operations
41+ taskQueue = dispatch_queue_create (" cenmrev.v2rayx.nstask" , DISPATCH_QUEUE_SERIAL);
42+
3943 if (![self installHelper ]) {
4044 [[NSApplication sharedApplication ] terminate: nil ];// installation failed or stopped by user,
4145 };
@@ -284,8 +288,10 @@ - (NSDictionary*)readDefaultsAsDictionary {
284288
285289
286290-(void )unloadV2ray {
287- runCommandLine (@" /bin/launchctl" , @[@" unload" , plistPath]);
288- NSLog (@" V2Ray core unloaded." );
291+ dispatch_async (taskQueue, ^{
292+ runCommandLine (@" /bin/launchctl" , @[@" unload" , plistPath]);
293+ NSLog (@" V2Ray core unloaded." );
294+ });
289295}
290296
291297-(BOOL )loadV2ray {
@@ -295,8 +301,10 @@ -(BOOL)loadV2ray {
295301 NSData * v2rayJSONconfig = [NSJSONSerialization dataWithJSONObject: configDic options: NSJSONWritingPrettyPrinted error: nil ];
296302 [v2rayJSONconfig writeToFile: configPath atomically: NO ];
297303 [self generateLaunchdPlist: plistPath];
298- runCommandLine (@" /bin/launchctl" , @[@" load" , plistPath]);
299- NSLog (@" V2Ray core loaded at port: %ld ." , localPort);
304+ dispatch_async (taskQueue, ^{
305+ runCommandLine (@" /bin/launchctl" , @[@" load" , plistPath]);
306+ NSLog (@" V2Ray core loaded at port: %ld ." , localPort);
307+ });
300308 return YES ;
301309}
302310
0 commit comments