From 83bb5354dcf64fb3ee201afe21f54b3eec9ba7f2 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 30 Apr 2016 23:02:21 -0400 Subject: [PATCH] Use NSRunLoop instead of NSApplication Don't use AppKit where we don't have to, especially for command line tools --- Sparkle.xcodeproj/project.pbxproj | 12 +++--- Sparkle/Autoupdate/Autoupdate.m | 38 ++----------------- .../{AppDelegate.h => SUCommandLineDriver.h} | 6 ++- .../{AppDelegate.m => SUCommandLineDriver.m} | 10 ++--- sparkle-cli/main.m | 14 +++---- 5 files changed, 24 insertions(+), 56 deletions(-) rename sparkle-cli/{AppDelegate.h => SUCommandLineDriver.h} (80%) rename sparkle-cli/{AppDelegate.m => SUCommandLineDriver.m} (91%) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index d632166b..5df9f5a0 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -267,7 +267,7 @@ 72D954811CBACC35006F28BD /* InstallerProgressAppController.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954801CBACC35006F28BD /* InstallerProgressAppController.m */; }; 72D954831CBAD34F006F28BD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954821CBAD34F006F28BD /* main.m */; }; 72D954861CBB179D006F28BD /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1420DF4F196247F900203BB0 /* Images.xcassets */; }; - 72D954A21CBB415C006F28BD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954A11CBB415C006F28BD /* AppDelegate.m */; }; + 72D954A21CBB415C006F28BD /* SUCommandLineDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954A11CBB415C006F28BD /* SUCommandLineDriver.m */; }; 72D954A51CBB415C006F28BD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954A41CBB415C006F28BD /* main.m */; }; 72D954B31CBB42DA006F28BD /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; }; 72D954B51CBB447A006F28BD /* Sparkle.framework in Copy Sparkle */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -897,8 +897,8 @@ 72D954841CBAD418006F28BD /* ShowInstallerProgress.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ShowInstallerProgress.h; path = Sparkle/InstallerProgress/ShowInstallerProgress.h; sourceTree = SOURCE_ROOT; }; 72D954851CBAD4AE006F28BD /* InstallerProgressAppControllerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = InstallerProgressAppControllerDelegate.h; path = Sparkle/InstallerProgress/InstallerProgressAppControllerDelegate.h; sourceTree = SOURCE_ROOT; }; 72D9549E1CBB415B006F28BD /* sparkle.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = sparkle.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 72D954A01CBB415C006F28BD /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 72D954A11CBB415C006F28BD /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 72D954A01CBB415C006F28BD /* SUCommandLineDriver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUCommandLineDriver.h; sourceTree = ""; }; + 72D954A11CBB415C006F28BD /* SUCommandLineDriver.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUCommandLineDriver.m; sourceTree = ""; }; 72D954A41CBB415C006F28BD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 72D954AB1CBB415C006F28BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 72D954B01CBB41E2006F28BD /* ConfigSparkleTool.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSparkleTool.xcconfig; sourceTree = ""; }; @@ -1600,8 +1600,8 @@ 72D9549F1CBB415C006F28BD /* sparkle-cli */ = { isa = PBXGroup; children = ( - 72D954A01CBB415C006F28BD /* AppDelegate.h */, - 72D954A11CBB415C006F28BD /* AppDelegate.m */, + 72D954A01CBB415C006F28BD /* SUCommandLineDriver.h */, + 72D954A11CBB415C006F28BD /* SUCommandLineDriver.m */, 72D954B61CBB467F006F28BD /* SUCommandLineUserDriver.h */, 72D954B71CBB467F006F28BD /* SUCommandLineUserDriver.m */, 72D954AB1CBB415C006F28BD /* Info.plist */, @@ -2564,7 +2564,7 @@ buildActionMask = 2147483647; files = ( 72D954A51CBB415C006F28BD /* main.m in Sources */, - 72D954A21CBB415C006F28BD /* AppDelegate.m in Sources */, + 72D954A21CBB415C006F28BD /* SUCommandLineDriver.m in Sources */, 72D954B81CBB467F006F28BD /* SUCommandLineUserDriver.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sparkle/Autoupdate/Autoupdate.m b/Sparkle/Autoupdate/Autoupdate.m index 5854c220..67a322c2 100644 --- a/Sparkle/Autoupdate/Autoupdate.m +++ b/Sparkle/Autoupdate/Autoupdate.m @@ -1,33 +1,6 @@ -#import -#import "SULog.h" +#import #import "AppInstaller.h" -@interface AppDelegate : NSObject - -@property (nonatomic, readonly) AppInstaller *appInstaller; - -@end - -@implementation AppDelegate - -@synthesize appInstaller = _appInstaller; - -- (instancetype)initWithAppInstaller:(AppInstaller *)appInstaller -{ - self = [super init]; - if (self != nil) { - _appInstaller = appInstaller; - } - return self; -} - -- (void)applicationDidFinishLaunching:(NSNotification __unused *)notification -{ - [self.appInstaller start]; -} - -@end - int main(int __unused argc, const char __unused *argv[]) { @autoreleasepool @@ -41,13 +14,8 @@ int main(int __unused argc, const char __unused *argv[]) BOOL inheritsPrivileges = args[2].boolValue; AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier inheritsPrivileges:inheritsPrivileges]; - - AppDelegate *delegate = [[AppDelegate alloc] initWithAppInstaller:appInstaller]; - - NSApplication *application = [NSApplication sharedApplication]; - [application setDelegate:delegate]; - - [application run]; + [appInstaller start]; + [[NSRunLoop currentRunLoop] run]; } return EXIT_SUCCESS; diff --git a/sparkle-cli/AppDelegate.h b/sparkle-cli/SUCommandLineDriver.h similarity index 80% rename from sparkle-cli/AppDelegate.h rename to sparkle-cli/SUCommandLineDriver.h index d674f275..0be57176 100644 --- a/sparkle-cli/AppDelegate.h +++ b/sparkle-cli/SUCommandLineDriver.h @@ -1,5 +1,5 @@ // -// AppDelegate.h +// SUCommandLineDriver.h // sparkle-cli // // Created by Mayur Pawashe on 4/10/16. @@ -10,10 +10,12 @@ NS_ASSUME_NONNULL_BEGIN -@interface AppDelegate : NSObject +@interface SUCommandLineDriver : NSObject - (instancetype)initWithUpdateBundlePath:(const char *)updateBundlePath relaunchBundlePath:(const char *)relaunchBundlePath; +- (void)run; + @end NS_ASSUME_NONNULL_END diff --git a/sparkle-cli/AppDelegate.m b/sparkle-cli/SUCommandLineDriver.m similarity index 91% rename from sparkle-cli/AppDelegate.m rename to sparkle-cli/SUCommandLineDriver.m index d0fec4c0..18b5f402 100644 --- a/sparkle-cli/AppDelegate.m +++ b/sparkle-cli/SUCommandLineDriver.m @@ -1,23 +1,23 @@ // -// AppDelegate.m +// SUCommandLineDriver.m // sparkle-cli // // Created by Mayur Pawashe on 4/10/16. // Copyright © 2016 Sparkle Project. All rights reserved. // -#import "AppDelegate.h" +#import "SUCommandLineDriver.h" #import #import "SUCommandLineUserDriver.h" -@interface AppDelegate () +@interface SUCommandLineDriver () @property (nonatomic, readonly) SUUpdater *updater; @property (nonatomic, readonly) NSString *relaunchBundlePath; @end -@implementation AppDelegate +@implementation SUCommandLineDriver @synthesize updater = _updater; @synthesize relaunchBundlePath = _relaunchBundlePath; @@ -64,7 +64,7 @@ return self.relaunchBundlePath; } -- (void)applicationDidFinishLaunching:(NSNotification *)__unused aNotification +- (void)run { // Kick off a scheduled update check once we start the updater later [self.updater checkForUpdates]; diff --git a/sparkle-cli/main.m b/sparkle-cli/main.m index 173687c0..031bd82c 100644 --- a/sparkle-cli/main.m +++ b/sparkle-cli/main.m @@ -6,8 +6,8 @@ // Copyright © 2016 Sparkle Project. All rights reserved. // -#import -#import "AppDelegate.h" +#import +#import "SUCommandLineDriver.h" int main(int argc, const char *argv[]) { @@ -18,16 +18,14 @@ int main(int argc, const char *argv[]) return EXIT_FAILURE; } - AppDelegate *delegate = [[AppDelegate alloc] initWithUpdateBundlePath:argv[1] relaunchBundlePath:argv[2]]; - if (delegate == nil) { + SUCommandLineDriver *driver = [[SUCommandLineDriver alloc] initWithUpdateBundlePath:argv[1] relaunchBundlePath:argv[2]]; + if (driver == nil) { printf("Error: Failed to initialize sparkle. Is the bundle you specified valid?\n"); return EXIT_FAILURE; } - NSApplication *application = [NSApplication sharedApplication]; - [application setDelegate:delegate]; - - [application run]; + [driver run]; + [[NSRunLoop currentRunLoop] run]; } return EXIT_SUCCESS;