fix: fix daemon crash in some case
This commit is contained in:
parent
16167b15d2
commit
3cb5d25dae
@ -9,6 +9,7 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
0D318CDAC9464E01DAD1F92B /* Pods_ClashX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0358BF8F0CBD7FF9A7EA4E30 /* Pods_ClashX.framework */; };
|
||||
4913C82321157D0200F6B87C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4913C82221157D0200F6B87C /* Notification.swift */; };
|
||||
491E6203258A424D00313AEF /* CommonUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 491E61FD258A424500313AEF /* CommonUtils.m */; };
|
||||
492C4869210EE6B9004554A0 /* ApiRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492C4868210EE6B9004554A0 /* ApiRequest.swift */; };
|
||||
492C4871210EF62E004554A0 /* ClashConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492C4870210EF62E004554A0 /* ClashConfig.swift */; };
|
||||
493A9F282453E60400D35296 /* ProxyDelayHistoryMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 493A9F272453E60400D35296 /* ProxyDelayHistoryMenu.swift */; };
|
||||
@ -120,6 +121,8 @@
|
||||
/* Begin PBXFileReference section */
|
||||
0358BF8F0CBD7FF9A7EA4E30 /* Pods_ClashX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ClashX.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4913C82221157D0200F6B87C /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
|
||||
491E61FC258A424500313AEF /* CommonUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonUtils.h; sourceTree = "<group>"; };
|
||||
491E61FD258A424500313AEF /* CommonUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonUtils.m; sourceTree = "<group>"; };
|
||||
492C4868210EE6B9004554A0 /* ApiRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiRequest.swift; sourceTree = "<group>"; };
|
||||
492C4870210EF62E004554A0 /* ClashConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashConfig.swift; sourceTree = "<group>"; };
|
||||
493A9F272453E60400D35296 /* ProxyDelayHistoryMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyDelayHistoryMenu.swift; sourceTree = "<group>"; };
|
||||
@ -463,6 +466,8 @@
|
||||
F9A7C06A2306E874007163C7 /* ProxyConfigHelper */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
491E61FC258A424500313AEF /* CommonUtils.h */,
|
||||
491E61FD258A424500313AEF /* CommonUtils.m */,
|
||||
498960722340F21C00AFB7EC /* com.west2online.ClashX.ProxyConfigHelper.entitlements */,
|
||||
F9A7C06B2306E874007163C7 /* main.m */,
|
||||
F935B2F12307C802009E4D33 /* Helper-Launchd.plist */,
|
||||
@ -713,6 +718,7 @@
|
||||
files = (
|
||||
F935B2F42307CD32009E4D33 /* ProxyConfigHelper.m in Sources */,
|
||||
F9A7C06C2306E874007163C7 /* main.m in Sources */,
|
||||
491E6203258A424D00313AEF /* CommonUtils.m in Sources */,
|
||||
F935B2FA23083EE6009E4D33 /* ProxySettingTool.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@ -963,7 +969,7 @@
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/ProxyConfigHelper/Helper-Info.plist";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MARKETING_VERSION = 1.5;
|
||||
MARKETING_VERSION = 1.6;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
OTHER_LDFLAGS = (
|
||||
@ -994,7 +1000,7 @@
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/ProxyConfigHelper/Helper-Info.plist";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MARKETING_VERSION = 1.5;
|
||||
MARKETING_VERSION = 1.6;
|
||||
MTL_FAST_MATH = YES;
|
||||
OTHER_LDFLAGS = (
|
||||
"-sectcreate",
|
||||
|
@ -27,8 +27,6 @@
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
@ -38,8 +36,8 @@
|
||||
ReferencedContainer = "container:ClashX.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
@ -61,8 +59,6 @@
|
||||
ReferencedContainer = "container:ClashX.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
|
17
ProxyConfigHelper/CommonUtils.h
Normal file
17
ProxyConfigHelper/CommonUtils.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// CommonUtils.h
|
||||
// ClashX
|
||||
//
|
||||
// Created by yicheng on 2020/4/2.
|
||||
// Copyright © 2020 west2online. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface CommonUtils : NSObject
|
||||
+ (NSString *)runCommand:(NSString *)path args:(nullable NSArray *)args;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
31
ProxyConfigHelper/CommonUtils.m
Normal file
31
ProxyConfigHelper/CommonUtils.m
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// CommonUtils.m
|
||||
// ClashX
|
||||
//
|
||||
// Created by yicheng on 2020/4/2.
|
||||
// Copyright © 2020 west2online. All rights reserved.
|
||||
//
|
||||
|
||||
#import "CommonUtils.h"
|
||||
|
||||
@implementation CommonUtils
|
||||
+ (NSString *)runCommand:(NSString *)path args:(nullable NSArray *)args {
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
[task setLaunchPath:path];
|
||||
[task setArguments:args];
|
||||
|
||||
NSPipe *pipe = [NSPipe pipe];
|
||||
[task setStandardOutput: pipe];
|
||||
|
||||
NSFileHandle *file = [pipe fileHandleForReading];
|
||||
|
||||
[task launch];
|
||||
|
||||
NSData *data = [file readDataToEndOfFile];
|
||||
NSString *output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
|
||||
#if DEBUG
|
||||
NSLog(@"%@",output);
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
@end
|
@ -9,7 +9,7 @@
|
||||
<key>CFBundleName</key>
|
||||
<string>com.west2online.ClashX.ProxyConfigHelper</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.5</string>
|
||||
<string>1.6</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2</string>
|
||||
<key>SMAuthorizedClients</key>
|
||||
|
@ -91,15 +91,19 @@ ProxyConfigRemoteProcessProtocol
|
||||
- (void)enableProxyWithPort:(int)port
|
||||
socksPort:(int)socksPort
|
||||
error:(stringReplyBlock)reply {
|
||||
ProxySettingTool *tool = [ProxySettingTool new];
|
||||
[tool enableProxyWithport:port socksPort:socksPort];
|
||||
reply(nil);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
ProxySettingTool *tool = [ProxySettingTool new];
|
||||
[tool enableProxyWithport:port socksPort:socksPort];
|
||||
reply(nil);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)disableProxy:(stringReplyBlock)reply {
|
||||
ProxySettingTool *tool = [ProxySettingTool new];
|
||||
[tool disableProxy];
|
||||
reply(nil);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
ProxySettingTool *tool = [ProxySettingTool new];
|
||||
[tool disableProxy];
|
||||
reply(nil);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -107,14 +111,18 @@ ProxyConfigRemoteProcessProtocol
|
||||
socksPort:(int)socksPort
|
||||
info:(NSDictionary *)dict
|
||||
error:(stringReplyBlock)reply {
|
||||
ProxySettingTool *tool = [ProxySettingTool new];
|
||||
[tool restoreProxySettint:dict currentPort:port currentSocksPort:socksPort];
|
||||
reply(nil);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
ProxySettingTool *tool = [ProxySettingTool new];
|
||||
[tool restoreProxySettint:dict currentPort:port currentSocksPort:socksPort];
|
||||
reply(nil);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)getCurrentProxySetting:(dictReplyBlock)reply {
|
||||
NSDictionary *info = [ProxySettingTool currentProxySettings];
|
||||
reply(info);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSDictionary *info = [ProxySettingTool currentProxySettings];
|
||||
reply(info);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,10 +9,7 @@
|
||||
#import "ProxySettingTool.h"
|
||||
#import <SystemConfiguration/SystemConfiguration.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#import "CommonUtils.h"
|
||||
|
||||
@interface ProxySettingTool()
|
||||
@property (nonatomic, assign) AuthorizationRef authRef;
|
||||
@ -108,25 +105,16 @@
|
||||
|
||||
|
||||
+ (NSString *)getUserHomePath {
|
||||
SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("com.west2online.ClashX.ProxyConfigHelper"), NULL, NULL);
|
||||
CFStringRef CopyCurrentConsoleUsername(SCDynamicStoreRef store);
|
||||
CFStringRef result;
|
||||
uid_t uid;
|
||||
result = SCDynamicStoreCopyConsoleUser(store, &uid, NULL);
|
||||
if ((result != NULL) && CFEqual(result, CFSTR("loginwindow"))) {
|
||||
CFRelease(result);
|
||||
result = NULL;
|
||||
CFRelease(store);
|
||||
NSString *userName = [CommonUtils runCommand:@"/usr/bin/stat" args:@[@"-f",@"%Su",@"/dev/console"]];
|
||||
userName = [userName stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
|
||||
if (!userName) {
|
||||
return nil;
|
||||
}
|
||||
if (result != NULL) {
|
||||
CFRelease(result);
|
||||
result = NULL;
|
||||
NSString *path = [NSString stringWithFormat:@"/Users/%@", userName];
|
||||
if([NSFileManager.defaultManager fileExistsAtPath:path]) {
|
||||
return path;
|
||||
}
|
||||
CFRelease(store);
|
||||
char *dir = getpwuid(uid)->pw_dir;
|
||||
NSString *path = [NSString stringWithUTF8String:dir];
|
||||
return path;
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@ -253,41 +241,6 @@
|
||||
return authFlags;
|
||||
}
|
||||
|
||||
/*
|
||||
- (NSString *)setupAuth:(NSData *)authData {
|
||||
if (authData.length == 0 || authData.length != kAuthorizationExternalFormLength) {
|
||||
return @"PrivilegedTaskRunnerHelper: Authorization data is malformed";
|
||||
}
|
||||
AuthorizationRef authRef;
|
||||
|
||||
OSStatus status = AuthorizationCreateFromExternalForm([authData bytes],&authRef);
|
||||
if (status != errAuthorizationSuccess) {
|
||||
return @"AuthorizationCreateFromExternalForm fail";
|
||||
}
|
||||
|
||||
NSString *authName = @"com.west2online.ClashX.ProxyConfigHelper.config";
|
||||
AuthorizationItem authItem = {authName.UTF8String, 0, NULL, 0};
|
||||
AuthorizationRights authRight = {1, &authItem};
|
||||
|
||||
AuthorizationFlags authFlags = [self authFlags];
|
||||
|
||||
status = AuthorizationCopyRights(authRef, &authRight, nil, authFlags, nil);
|
||||
if (status != errAuthorizationSuccess) {
|
||||
AuthorizationFree(authRef, authFlags);
|
||||
return @"AuthorizationCopyRights fail";
|
||||
}
|
||||
|
||||
OSStatus authErr = AuthorizationCreate(nil, kAuthorizationEmptyEnvironment, authFlags, &authRef);
|
||||
|
||||
if (authErr != noErr) {
|
||||
AuthorizationFree(authRef, authFlags);
|
||||
return @"AuthorizationCreate fail";
|
||||
}
|
||||
self.authRef = authRef;
|
||||
return nil;
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)localAuth {
|
||||
OSStatus myStatus;
|
||||
AuthorizationFlags myFlags = [self authFlags];
|
||||
|
Loading…
Reference in New Issue
Block a user