From 6c73432eed98be91d86933d16bc873a0ab0b609f Mon Sep 17 00:00:00 2001 From: Qiu Yuzhou Date: Tue, 28 Mar 2017 20:25:35 +0800 Subject: [PATCH] Reimplement auto launch helper by objective-c. --- .../LaunchHelper.xcodeproj/project.pbxproj | 123 ++-- .../xcschemes/LaunchHelper.xcscheme | 91 --- LaunchHelper/LaunchHelper/AppDelegate.h | 15 + LaunchHelper/LaunchHelper/AppDelegate.m | 43 ++ LaunchHelper/LaunchHelper/AppDelegate.swift | 48 -- .../LaunchHelper/Base.lproj/MainMenu.xib | 665 +----------------- LaunchHelper/LaunchHelper/Info.plist | 4 +- LaunchHelper/LaunchHelper/main.m | 13 + ShadowsocksX-NG.xcodeproj/project.pbxproj | 26 +- ShadowsocksX-NG/LaunchAtLoginController.m | 4 +- 10 files changed, 156 insertions(+), 876 deletions(-) delete mode 100644 LaunchHelper/LaunchHelper.xcodeproj/xcshareddata/xcschemes/LaunchHelper.xcscheme create mode 100644 LaunchHelper/LaunchHelper/AppDelegate.h create mode 100644 LaunchHelper/LaunchHelper/AppDelegate.m delete mode 100644 LaunchHelper/LaunchHelper/AppDelegate.swift create mode 100644 LaunchHelper/LaunchHelper/main.m diff --git a/LaunchHelper/LaunchHelper.xcodeproj/project.pbxproj b/LaunchHelper/LaunchHelper.xcodeproj/project.pbxproj index 898023d..8ceb744 100644 --- a/LaunchHelper/LaunchHelper.xcodeproj/project.pbxproj +++ b/LaunchHelper/LaunchHelper.xcodeproj/project.pbxproj @@ -7,21 +7,24 @@ objects = { /* Begin PBXBuildFile section */ - 9B6BF93F1E27B1F10061B9A7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B6BF93E1E27B1F10061B9A7 /* AppDelegate.swift */; }; - 9B6BF9411E27B1F10061B9A7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9B6BF9401E27B1F10061B9A7 /* Assets.xcassets */; }; - 9B6BF9441E27B1F10061B9A7 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9B6BF9421E27B1F10061B9A7 /* MainMenu.xib */; }; + 9B9F13921E8A282C00DE4794 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9F13911E8A282C00DE4794 /* AppDelegate.m */; }; + 9B9F13951E8A282C00DE4794 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9F13941E8A282C00DE4794 /* main.m */; }; + 9B9F13971E8A282C00DE4794 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9B9F13961E8A282C00DE4794 /* Assets.xcassets */; }; + 9B9F139A1E8A282C00DE4794 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9B9F13981E8A282C00DE4794 /* MainMenu.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 9B6BF93B1E27B1F10061B9A7 /* LaunchHelper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LaunchHelper.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 9B6BF93E1E27B1F10061B9A7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 9B6BF9401E27B1F10061B9A7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 9B6BF9431E27B1F10061B9A7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; - 9B6BF9451E27B1F10061B9A7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 9B9F138D1E8A282C00DE4794 /* LaunchHelper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LaunchHelper.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 9B9F13901E8A282C00DE4794 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 9B9F13911E8A282C00DE4794 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 9B9F13941E8A282C00DE4794 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 9B9F13961E8A282C00DE4794 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 9B9F13991E8A282C00DE4794 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 9B9F139B1E8A282C00DE4794 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 9B6BF9381E27B1F10061B9A7 /* Frameworks */ = { + 9B9F138A1E8A282C00DE4794 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( @@ -31,43 +34,53 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 9B6BF9321E27B1F10061B9A7 = { + 9B9F13841E8A282C00DE4794 = { isa = PBXGroup; children = ( - 9B6BF93D1E27B1F10061B9A7 /* LaunchHelper */, - 9B6BF93C1E27B1F10061B9A7 /* Products */, + 9B9F138F1E8A282C00DE4794 /* LaunchHelper */, + 9B9F138E1E8A282C00DE4794 /* Products */, ); sourceTree = ""; }; - 9B6BF93C1E27B1F10061B9A7 /* Products */ = { + 9B9F138E1E8A282C00DE4794 /* Products */ = { isa = PBXGroup; children = ( - 9B6BF93B1E27B1F10061B9A7 /* LaunchHelper.app */, + 9B9F138D1E8A282C00DE4794 /* LaunchHelper.app */, ); name = Products; sourceTree = ""; }; - 9B6BF93D1E27B1F10061B9A7 /* LaunchHelper */ = { + 9B9F138F1E8A282C00DE4794 /* LaunchHelper */ = { isa = PBXGroup; children = ( - 9B6BF93E1E27B1F10061B9A7 /* AppDelegate.swift */, - 9B6BF9401E27B1F10061B9A7 /* Assets.xcassets */, - 9B6BF9421E27B1F10061B9A7 /* MainMenu.xib */, - 9B6BF9451E27B1F10061B9A7 /* Info.plist */, + 9B9F13901E8A282C00DE4794 /* AppDelegate.h */, + 9B9F13911E8A282C00DE4794 /* AppDelegate.m */, + 9B9F13961E8A282C00DE4794 /* Assets.xcassets */, + 9B9F13981E8A282C00DE4794 /* MainMenu.xib */, + 9B9F139B1E8A282C00DE4794 /* Info.plist */, + 9B9F13931E8A282C00DE4794 /* Supporting Files */, ); path = LaunchHelper; sourceTree = ""; }; + 9B9F13931E8A282C00DE4794 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 9B9F13941E8A282C00DE4794 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 9B6BF93A1E27B1F10061B9A7 /* LaunchHelper */ = { + 9B9F138C1E8A282C00DE4794 /* LaunchHelper */ = { isa = PBXNativeTarget; - buildConfigurationList = 9B6BF9481E27B1F10061B9A7 /* Build configuration list for PBXNativeTarget "LaunchHelper" */; + buildConfigurationList = 9B9F139E1E8A282C00DE4794 /* Build configuration list for PBXNativeTarget "LaunchHelper" */; buildPhases = ( - 9B6BF9371E27B1F10061B9A7 /* Sources */, - 9B6BF9381E27B1F10061B9A7 /* Frameworks */, - 9B6BF9391E27B1F10061B9A7 /* Resources */, + 9B9F13891E8A282C00DE4794 /* Sources */, + 9B9F138A1E8A282C00DE4794 /* Frameworks */, + 9B9F138B1E8A282C00DE4794 /* Resources */, ); buildRules = ( ); @@ -75,27 +88,25 @@ ); name = LaunchHelper; productName = LaunchHelper; - productReference = 9B6BF93B1E27B1F10061B9A7 /* LaunchHelper.app */; + productReference = 9B9F138D1E8A282C00DE4794 /* LaunchHelper.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ - 9B6BF9331E27B1F10061B9A7 /* Project object */ = { + 9B9F13851E8A282C00DE4794 /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0820; LastUpgradeCheck = 0820; ORGANIZATIONNAME = qiuyuzhou; TargetAttributes = { - 9B6BF93A1E27B1F10061B9A7 = { + 9B9F138C1E8A282C00DE4794 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = S878RH3PA8; ProvisioningStyle = Automatic; }; }; }; - buildConfigurationList = 9B6BF9361E27B1F10061B9A7 /* Build configuration list for PBXProject "LaunchHelper" */; + buildConfigurationList = 9B9F13881E8A282C00DE4794 /* Build configuration list for PBXProject "LaunchHelper" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; @@ -103,44 +114,45 @@ en, Base, ); - mainGroup = 9B6BF9321E27B1F10061B9A7; - productRefGroup = 9B6BF93C1E27B1F10061B9A7 /* Products */; + mainGroup = 9B9F13841E8A282C00DE4794; + productRefGroup = 9B9F138E1E8A282C00DE4794 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( - 9B6BF93A1E27B1F10061B9A7 /* LaunchHelper */, + 9B9F138C1E8A282C00DE4794 /* LaunchHelper */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 9B6BF9391E27B1F10061B9A7 /* Resources */ = { + 9B9F138B1E8A282C00DE4794 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9B6BF9411E27B1F10061B9A7 /* Assets.xcassets in Resources */, - 9B6BF9441E27B1F10061B9A7 /* MainMenu.xib in Resources */, + 9B9F13971E8A282C00DE4794 /* Assets.xcassets in Resources */, + 9B9F139A1E8A282C00DE4794 /* MainMenu.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - 9B6BF9371E27B1F10061B9A7 /* Sources */ = { + 9B9F13891E8A282C00DE4794 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9B6BF93F1E27B1F10061B9A7 /* AppDelegate.swift in Sources */, + 9B9F13951E8A282C00DE4794 /* main.m in Sources */, + 9B9F13921E8A282C00DE4794 /* AppDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 9B6BF9421E27B1F10061B9A7 /* MainMenu.xib */ = { + 9B9F13981E8A282C00DE4794 /* MainMenu.xib */ = { isa = PBXVariantGroup; children = ( - 9B6BF9431E27B1F10061B9A7 /* Base */, + 9B9F13991E8A282C00DE4794 /* Base */, ); name = MainMenu.xib; sourceTree = ""; @@ -148,7 +160,7 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ - 9B6BF9461E27B1F10061B9A7 /* Debug */ = { + 9B9F139C1E8A282C00DE4794 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; @@ -192,12 +204,10 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; }; - 9B6BF9471E27B1F10061B9A7 /* Release */ = { + 9B9F139D1E8A282C00DE4794 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; @@ -234,62 +244,59 @@ MACOSX_DEPLOYMENT_TARGET = 10.12; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; - 9B6BF9491E27B1F10061B9A7 /* Debug */ = { + 9B9F139F1E8A282C00DE4794 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = S878RH3PA8; INFOPLIST_FILE = LaunchHelper/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.qiuyuzhou.ShadowsocksX-NG.LaunchHelper"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; }; name = Debug; }; - 9B6BF94A1E27B1F10061B9A7 /* Release */ = { + 9B9F13A01E8A282C00DE4794 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = S878RH3PA8; INFOPLIST_FILE = LaunchHelper/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.qiuyuzhou.ShadowsocksX-NG.LaunchHelper"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 9B6BF9361E27B1F10061B9A7 /* Build configuration list for PBXProject "LaunchHelper" */ = { + 9B9F13881E8A282C00DE4794 /* Build configuration list for PBXProject "LaunchHelper" */ = { isa = XCConfigurationList; buildConfigurations = ( - 9B6BF9461E27B1F10061B9A7 /* Debug */, - 9B6BF9471E27B1F10061B9A7 /* Release */, + 9B9F139C1E8A282C00DE4794 /* Debug */, + 9B9F139D1E8A282C00DE4794 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 9B6BF9481E27B1F10061B9A7 /* Build configuration list for PBXNativeTarget "LaunchHelper" */ = { + 9B9F139E1E8A282C00DE4794 /* Build configuration list for PBXNativeTarget "LaunchHelper" */ = { isa = XCConfigurationList; buildConfigurations = ( - 9B6BF9491E27B1F10061B9A7 /* Debug */, - 9B6BF94A1E27B1F10061B9A7 /* Release */, + 9B9F139F1E8A282C00DE4794 /* Debug */, + 9B9F13A01E8A282C00DE4794 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; - rootObject = 9B6BF9331E27B1F10061B9A7 /* Project object */; + rootObject = 9B9F13851E8A282C00DE4794 /* Project object */; } diff --git a/LaunchHelper/LaunchHelper.xcodeproj/xcshareddata/xcschemes/LaunchHelper.xcscheme b/LaunchHelper/LaunchHelper.xcodeproj/xcshareddata/xcschemes/LaunchHelper.xcscheme deleted file mode 100644 index af6dfe3..0000000 --- a/LaunchHelper/LaunchHelper.xcodeproj/xcshareddata/xcschemes/LaunchHelper.xcscheme +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LaunchHelper/LaunchHelper/AppDelegate.h b/LaunchHelper/LaunchHelper/AppDelegate.h new file mode 100644 index 0000000..20bacd1 --- /dev/null +++ b/LaunchHelper/LaunchHelper/AppDelegate.h @@ -0,0 +1,15 @@ +// +// AppDelegate.h +// LaunchHelper +// +// Created by 邱宇舟 on 2017/3/28. +// Copyright © 2017年 qiuyuzhou. All rights reserved. +// + +#import + +@interface AppDelegate : NSObject + + +@end + diff --git a/LaunchHelper/LaunchHelper/AppDelegate.m b/LaunchHelper/LaunchHelper/AppDelegate.m new file mode 100644 index 0000000..9fc3646 --- /dev/null +++ b/LaunchHelper/LaunchHelper/AppDelegate.m @@ -0,0 +1,43 @@ +// +// AppDelegate.m +// LaunchHelper +// +// Created by 邱宇舟 on 2017/3/28. +// Copyright © 2017年 qiuyuzhou. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@property (weak) IBOutlet NSWindow *window; +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application + NSLog(@"ShadowsocksX-NG LaunchHelper"); + + NSWorkspace* ws = [NSWorkspace sharedWorkspace]; + BOOL bLaunched = NO; + bLaunched = [ws launchApplication: @"/Applications/ShadowsocksX-NG.app"]; + if (!bLaunched) { + bLaunched = [ws launchApplication: @"ShadowsocksX-NG.app"]; + } + if (!bLaunched) { + NSArray *pathComponents = [[[NSBundle mainBundle] bundlePath] pathComponents]; + pathComponents = [pathComponents subarrayWithRange:NSMakeRange(0, [pathComponents count] - 4)]; + NSString *path = [NSString pathWithComponents:pathComponents]; + [[NSWorkspace sharedWorkspace] launchApplication:path]; + } + [NSApp terminate:nil]; +} + + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + // Insert code here to tear down your application +} + + +@end diff --git a/LaunchHelper/LaunchHelper/AppDelegate.swift b/LaunchHelper/LaunchHelper/AppDelegate.swift deleted file mode 100644 index 14f7bed..0000000 --- a/LaunchHelper/LaunchHelper/AppDelegate.swift +++ /dev/null @@ -1,48 +0,0 @@ -// -// AppDelegate.swift -// LaunchHelper -// -// Created by 邱宇舟 on 2017/1/12. -// Copyright © 2017年 qiuyuzhou. All rights reserved. -// - -import Cocoa - -@NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate { - - @IBOutlet weak var window: NSWindow! - - - func applicationDidFinishLaunching(_ aNotification: Notification) { - // Insert code here to initialize your application - let mainBundleId = "com.qiuyuzhou.ShadowsocksX-NG" - var alreadyRunning = false; - for app in NSWorkspace.shared().runningApplications { - if app.bundleIdentifier == mainBundleId { - alreadyRunning = true - break - } - } - - if (!alreadyRunning) { - let helperPath: NSString = Bundle.main.bundlePath as NSString; - var pathComponents = helperPath.pathComponents; - pathComponents.removeLast(3); - let mainBundlePath = NSString.path(withComponents: pathComponents); - - if !NSWorkspace.shared().launchApplication(mainBundlePath) { - NSLog("Launch app \(mainBundleId) failed.") - } -// if !NSWorkspace.shared().launchApplication("/Applications/ShadowsocksX-NG.app") { -// NSLog("Launch app \(mainBundleId) failed.") -// } - } - NSApp.terminate(nil); - } - - func applicationWillTerminate(_ aNotification: Notification) { - // Insert code here to tear down your application - } -} - diff --git a/LaunchHelper/LaunchHelper/Base.lproj/MainMenu.xib b/LaunchHelper/LaunchHelper/Base.lproj/MainMenu.xib index ddb5c97..0edb2c8 100644 --- a/LaunchHelper/LaunchHelper/Base.lproj/MainMenu.xib +++ b/LaunchHelper/LaunchHelper/Base.lproj/MainMenu.xib @@ -1,5 +1,5 @@ - + @@ -12,668 +12,7 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LaunchHelper/LaunchHelper/Info.plist b/LaunchHelper/LaunchHelper/Info.plist index 909b70e..58edf89 100644 --- a/LaunchHelper/LaunchHelper/Info.plist +++ b/LaunchHelper/LaunchHelper/Info.plist @@ -19,9 +19,9 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 1 + 2 LSBackgroundOnly - + LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/LaunchHelper/LaunchHelper/main.m b/LaunchHelper/LaunchHelper/main.m new file mode 100644 index 0000000..c6f3286 --- /dev/null +++ b/LaunchHelper/LaunchHelper/main.m @@ -0,0 +1,13 @@ +// +// main.m +// LaunchHelper +// +// Created by 邱宇舟 on 2017/3/28. +// Copyright © 2017年 qiuyuzhou. All rights reserved. +// + +#import + +int main(int argc, const char * argv[]) { + return NSApplicationMain(argc, argv); +} diff --git a/ShadowsocksX-NG.xcodeproj/project.pbxproj b/ShadowsocksX-NG.xcodeproj/project.pbxproj index a415602..4d1e918 100755 --- a/ShadowsocksX-NG.xcodeproj/project.pbxproj +++ b/ShadowsocksX-NG.xcodeproj/project.pbxproj @@ -46,7 +46,6 @@ 9B5832071E7421B2009D5B7D /* virtual-server-icon-3.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B5832061E7421B2009D5B7D /* virtual-server-icon-3.png */; }; 9B58320B1E7422DB009D5B7D /* http.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B58320A1E7422DB009D5B7D /* http.png */; }; 9B5832111E742632009D5B7D /* kcptun_1.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B5832101E742632009D5B7D /* kcptun_1.png */; }; - 9B6BF9521E27B23F0061B9A7 /* LaunchHelper.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9B6BF9501E27B1F20061B9A7 /* LaunchHelper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 9B6BF9541E27B2570061B9A7 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B6BF9531E27B2570061B9A7 /* ServiceManagement.framework */; }; 9B86459D1E7C2CAD00A84029 /* ProxyInterfacesViewCtrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B86459C1E7C2CAD00A84029 /* ProxyInterfacesViewCtrl.swift */; }; 9B938D991E864B38005F5636 /* menu_g_icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B938D931E864B38005F5636 /* menu_g_icon.png */; }; @@ -61,6 +60,7 @@ 9B9CBCAF1E263B1600FC61AA /* libpcre.1.dylib in Resources */ = {isa = PBXBuildFile; fileRef = 9B9CBCAD1E263A6600FC61AA /* libpcre.1.dylib */; }; 9B9CBCB41E26453C00FC61AA /* start_kcptun.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9B9CBCB01E2644DC00FC61AA /* start_kcptun.sh */; }; 9B9CBCB51E26453C00FC61AA /* stop_kcptun.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9B9CBCB11E26450D00FC61AA /* stop_kcptun.sh */; }; + 9B9F13A71E8A28B300DE4794 /* LaunchHelper.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9B9F13A61E8A282D00DE4794 /* LaunchHelper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 9BA04B231D23D5A5005AAD7F /* ProxyConfTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BA04B221D23D5A5005AAD7F /* ProxyConfTool.m */; }; 9BAFE2E21E83ED7F00F71CCE /* PreferencesWinController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9BAFE2E41E83ED7F00F71CCE /* PreferencesWinController.xib */; }; 9BB706A71D1B982300551F0E /* SWBApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BB706A51D1B982300551F0E /* SWBApplication.m */; }; @@ -99,11 +99,11 @@ remoteGlobalIDString = 9B3FFF431D09CD3B0019A709; remoteInfo = proxy_conf_helper; }; - 9B6BF94F1E27B1F20061B9A7 /* PBXContainerItemProxy */ = { + 9B9F13A51E8A282D00DE4794 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 9B6BF94B1E27B1F10061B9A7 /* LaunchHelper.xcodeproj */; + containerPortal = 9B9F13A11E8A282C00DE4794 /* LaunchHelper.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 9B6BF93B1E27B1F10061B9A7; + remoteGlobalIDString = 9B9F138D1E8A282C00DE4794; remoteInfo = LaunchHelper; }; /* End PBXContainerItemProxy section */ @@ -124,7 +124,7 @@ dstPath = Contents/Library/LoginItems; dstSubfolderSpec = 1; files = ( - 9B6BF9521E27B23F0061B9A7 /* LaunchHelper.app in CopyFiles */, + 9B9F13A71E8A28B300DE4794 /* LaunchHelper.app in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -194,7 +194,6 @@ 9B5832061E7421B2009D5B7D /* virtual-server-icon-3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "virtual-server-icon-3.png"; sourceTree = ""; }; 9B58320A1E7422DB009D5B7D /* http.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = http.png; sourceTree = ""; }; 9B5832101E742632009D5B7D /* kcptun_1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = kcptun_1.png; sourceTree = ""; }; - 9B6BF94B1E27B1F10061B9A7 /* LaunchHelper.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LaunchHelper.xcodeproj; path = LaunchHelper/LaunchHelper.xcodeproj; sourceTree = ""; }; 9B6BF9531E27B2570061B9A7 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; }; 9B86459C1E7C2CAD00A84029 /* ProxyInterfacesViewCtrl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxyInterfacesViewCtrl.swift; sourceTree = ""; }; 9B938D931E864B38005F5636 /* menu_g_icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu_g_icon.png; sourceTree = ""; }; @@ -209,6 +208,7 @@ 9B9CBCAD1E263A6600FC61AA /* libpcre.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libpcre.1.dylib; sourceTree = ""; }; 9B9CBCB01E2644DC00FC61AA /* start_kcptun.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = start_kcptun.sh; sourceTree = ""; }; 9B9CBCB11E26450D00FC61AA /* stop_kcptun.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stop_kcptun.sh; sourceTree = ""; }; + 9B9F13A11E8A282C00DE4794 /* LaunchHelper.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LaunchHelper.xcodeproj; path = LaunchHelper/LaunchHelper.xcodeproj; sourceTree = ""; }; 9BA04B211D23D5A5005AAD7F /* ProxyConfTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyConfTool.h; sourceTree = ""; }; 9BA04B221D23D5A5005AAD7F /* ProxyConfTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProxyConfTool.m; sourceTree = ""; }; 9BAFE2E31E83ED7F00F71CCE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PreferencesWinController.xib; sourceTree = ""; }; @@ -332,8 +332,8 @@ isa = PBXGroup; children = ( 9B5831FA1E73098F009D5B7D /* README.md */, - 9B6BF94B1E27B1F10061B9A7 /* LaunchHelper.xcodeproj */, 9B172A601D0ADA5B00B87B9A /* genstrings.py */, + 9B9F13A11E8A282C00DE4794 /* LaunchHelper.xcodeproj */, 9B0BFFE71D0460A70040E62B /* ShadowsocksX-NG */, 9B0BFFF71D0460A70040E62B /* ShadowsocksX-NGTests */, 9B3FFF451D09CD3B0019A709 /* proxy_conf_helper */, @@ -424,10 +424,10 @@ path = proxy_conf_helper; sourceTree = ""; }; - 9B6BF94C1E27B1F10061B9A7 /* Products */ = { + 9B9F13A21E8A282C00DE4794 /* Products */ = { isa = PBXGroup; children = ( - 9B6BF9501E27B1F20061B9A7 /* LaunchHelper.app */, + 9B9F13A61E8A282D00DE4794 /* LaunchHelper.app */, ); name = Products; sourceTree = ""; @@ -549,8 +549,8 @@ projectDirPath = ""; projectReferences = ( { - ProductGroup = 9B6BF94C1E27B1F10061B9A7 /* Products */; - ProjectRef = 9B6BF94B1E27B1F10061B9A7 /* LaunchHelper.xcodeproj */; + ProductGroup = 9B9F13A21E8A282C00DE4794 /* Products */; + ProjectRef = 9B9F13A11E8A282C00DE4794 /* LaunchHelper.xcodeproj */; }, ); projectRoot = ""; @@ -563,11 +563,11 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 9B6BF9501E27B1F20061B9A7 /* LaunchHelper.app */ = { + 9B9F13A61E8A282D00DE4794 /* LaunchHelper.app */ = { isa = PBXReferenceProxy; fileType = wrapper.application; path = LaunchHelper.app; - remoteRef = 9B6BF94F1E27B1F20061B9A7 /* PBXContainerItemProxy */; + remoteRef = 9B9F13A51E8A282D00DE4794 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ diff --git a/ShadowsocksX-NG/LaunchAtLoginController.m b/ShadowsocksX-NG/LaunchAtLoginController.m index f14d0d4..586fb0b 100755 --- a/ShadowsocksX-NG/LaunchAtLoginController.m +++ b/ShadowsocksX-NG/LaunchAtLoginController.m @@ -66,8 +66,10 @@ - (void) setLaunchAtLogin: (BOOL) enabled { + static NSString* bundleID = @"com.qiuyuzhou.ShadowsocksX-NG.LaunchHelper"; + if (SMLoginItemSetEnabled( - (__bridge CFStringRef)@"com.qiuyuzhou.ShadowsocksX-NG.LaunchHelper" + (__bridge CFStringRef)bundleID , enabled)) { _enabled = enabled; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];