Refactor InstallerProgress tool into separate classes

This commit is contained in:
Zorg committed 2016-04-10 14:46:05 -04:00
1 parent 7015303726
commit 5fdc438fa6
7 files changed
+219 -87

No files matched your search

+18 -4
View File
@@ -267,6 +267,8 @@
72D9547C1CBA1FFF006F28BD /* SUInstallationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D9547A1CBA1FFE006F28BD /* SUInstallationInfo.m */; };
72D9547D1CBA1FFF006F28BD /* SUInstallationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D9547A1CBA1FFE006F28BD /* SUInstallationInfo.m */; };
72D9547E1CBA221E006F28BD /* SUAppcastItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */; };
72D954811CBACC35006F28BD /* InstallerProgressAppController.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954801CBACC35006F28BD /* InstallerProgressAppController.m */; };
72D954831CBAD34F006F28BD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954821CBAD34F006F28BD /* main.m */; };
72E41A391CB209CA003D47E0 /* SURemoteMessagePortProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 72E41A381CB209CA003D47E0 /* SURemoteMessagePortProtocol.h */; };
72E41A451CB20BA7003D47E0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 72E41A441CB20BA7003D47E0 /* main.m */; };
72E41A491CB20BA7003D47E0 /* RemoteMessagePort.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 72E41A3E1CB20BA7003D47E0 /* RemoteMessagePort.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@@ -279,7 +281,7 @@
72E45CFC1B641961005C701A /* sparkletestcast.xml in Resources */ = {isa = PBXBuildFile; fileRef = 72E45CFB1B641961005C701A /* sparkletestcast.xml */; };
72E45CFE1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem in Resources */ = {isa = PBXBuildFile; fileRef = 72E45CFD1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem */; };
72E45DDD1B65C3BD005C701A /* sign_update in Resources */ = {isa = PBXBuildFile; fileRef = 72E45DDC1B65C3BD005C701A /* sign_update */; };
72EB87EA1CB8798800C37F42 /* InstallerProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EB87E91CB8798800C37F42 /* InstallerProgress.m */; };
72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EB87E91CB8798800C37F42 /* ShowInstallerProgress.m */; };
72EB87EB1CB8859100C37F42 /* Updater.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
72EB87EC1CB8887E00C37F42 /* SUStatus.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C14BD8136EF00C00649790 /* SUStatus.xib */; };
767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */; };
@@ -848,6 +850,11 @@
72B767E51C9CFD7200A07552 /* SUAutomaticUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAutomaticUpdateDriver.m; sourceTree = "<group>"; };
72D954791CBA1FFE006F28BD /* SUInstallationInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUInstallationInfo.h; sourceTree = "<group>"; };
72D9547A1CBA1FFE006F28BD /* SUInstallationInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallationInfo.m; sourceTree = "<group>"; };
72D9547F1CBACC35006F28BD /* InstallerProgressAppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InstallerProgressAppController.h; path = Sparkle/InstallerProgress/InstallerProgressAppController.h; sourceTree = SOURCE_ROOT; };
72D954801CBACC35006F28BD /* InstallerProgressAppController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InstallerProgressAppController.m; path = Sparkle/InstallerProgress/InstallerProgressAppController.m; sourceTree = SOURCE_ROOT; };
72D954821CBAD34F006F28BD /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Sparkle/InstallerProgress/main.m; sourceTree = SOURCE_ROOT; };
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; };
72E41A381CB209CA003D47E0 /* SURemoteMessagePortProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SURemoteMessagePortProtocol.h; path = Sparkle/SURemoteMessagePortProtocol.h; sourceTree = SOURCE_ROOT; };
72E41A3E1CB20BA7003D47E0 /* RemoteMessagePort.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = RemoteMessagePort.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
72E41A441CB20BA7003D47E0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -863,7 +870,7 @@
72E45CFB1B641961005C701A /* sparkletestcast.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sparkletestcast.xml; sourceTree = "<group>"; };
72E45CFD1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test_app_only_dsa_priv_dont_ever_do_this_for_real.pem; sourceTree = "<group>"; };
72E45DDC1B65C3BD005C701A /* sign_update */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = sign_update; path = bin/sign_update; sourceTree = SOURCE_ROOT; };
72EB87E91CB8798800C37F42 /* InstallerProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InstallerProgress.m; path = Sparkle/InstallerProgress/InstallerProgress.m; sourceTree = SOURCE_ROOT; };
72EB87E91CB8798800C37F42 /* ShowInstallerProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ShowInstallerProgress.m; path = Sparkle/InstallerProgress/ShowInstallerProgress.m; sourceTree = SOURCE_ROOT; };
767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUGuidedPackageInstaller.h; sourceTree = "<group>"; };
767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUGuidedPackageInstaller.m; sourceTree = "<group>"; };
8DC2EF5A0486A6940098B216 /* Sparkle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Sparkle-Info.plist"; sourceTree = "<group>"; };
@@ -1398,7 +1405,12 @@
721C24461CB753E6005440CB /* Installer Progress */ = {
isa = PBXGroup;
children = (
72EB87E91CB8798800C37F42 /* InstallerProgress.m */,
72D954851CBAD4AE006F28BD /* InstallerProgressAppControllerDelegate.h */,
72D9547F1CBACC35006F28BD /* InstallerProgressAppController.h */,
72D954801CBACC35006F28BD /* InstallerProgressAppController.m */,
72D954841CBAD418006F28BD /* ShowInstallerProgress.h */,
72EB87E91CB8798800C37F42 /* ShowInstallerProgress.m */,
72D954821CBAD34F006F28BD /* main.m */,
721C24581CB7567D005440CB /* InstallerProgress-Info.plist */,
);
name = "Installer Progress";
@@ -2361,8 +2373,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
72D954831CBAD34F006F28BD /* main.m in Sources */,
721C24621CB75C68005440CB /* SULog.m in Sources */,
72EB87EA1CB8798800C37F42 /* InstallerProgress.m in Sources */,
72D954811CBACC35006F28BD /* InstallerProgressAppController.m in Sources */,
72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */,
721C24611CB75C5D005440CB /* SUHost.m in Sources */,
721C245F1CB75A6B005440CB /* SUMessageTypes.m in Sources */,
721C245E1CB757DE005440CB /* SUConstants.m in Sources */,
@@ -0,0 +1,23 @@
//
// InstallerProgressAppController.h
// Sparkle
//
// Created by Mayur Pawashe on 4/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@protocol InstallerProgressAppControllerDelegate;
@interface InstallerProgressAppController : NSObject
- (instancetype)initWithApplication:(NSApplication *)application arguments:(NSArray<NSString *> *)arguments delegate:(id<InstallerProgressAppControllerDelegate>)delegate;
- (void)run;
@end
NS_ASSUME_NONNULL_END
@@ -1,17 +1,15 @@
//
// InstallerProgress.m
// Installer Progress
// InstallerProgressAppController.m
// Sparkle
//
// Created by Mayur Pawashe on 4/7/16.
// Created by Mayur Pawashe on 4/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "InstallerProgressAppController.h"
#import "InstallerProgressAppControllerDelegate.h"
#import "SURemoteMessagePort.h"
#import "SUMessageTypes.h"
#import "SUStatusController.h"
#import "SUHost.h"
#import "SULocalizations.h"
#import "SULog.h"
/*!
@@ -21,34 +19,88 @@
*/
static const NSTimeInterval SUTerminationTimeDelay = 0.3;
@interface InstallerProgress : NSObject <NSApplicationDelegate>
@interface InstallerProgressAppController () <NSApplicationDelegate>
@property (nonatomic, readonly) NSApplication *application;
@property (nonatomic, readonly) NSBundle *bundle;
@property (nonatomic, readonly, weak) id<InstallerProgressAppControllerDelegate> delegate;
@property (nonatomic, readonly) SURemoteMessagePort *remotePort;
@property (nonatomic) SUStatusController *statusController;
@end
@implementation InstallerProgress
@implementation InstallerProgressAppController
@synthesize application = _application;
@synthesize bundle = _bundle;
@synthesize delegate = _delegate;
@synthesize remotePort = _remotePort;
@synthesize statusController = _statusController;
- (instancetype)initWithHost:(SUHost *)host
- (instancetype)initWithApplication:(NSApplication *)application arguments:(NSArray<NSString *> *)arguments delegate:(id<InstallerProgressAppControllerDelegate>)delegate
{
self = [super init];
if (self != nil) {
NSString *bundleIdentifier = host.bundle.bundleIdentifier;
if (bundleIdentifier == nil) {
SULog(@"Error: Bundle Identifier for host is nil");
exit(0);
if (arguments.count < 2) {
exit(EXIT_FAILURE);
}
NSImage *applicationIcon = nil;
if (arguments.count > 2) {
applicationIcon = [[NSImage alloc] initWithContentsOfFile:arguments[2]];
}
if (applicationIcon != nil) {
application.applicationIconImage = applicationIcon;
}
NSString *hostBundlePath = arguments[1];
NSBundle *bundle = [NSBundle bundleWithPath:hostBundlePath];
if (bundle == nil) {
SULog(@"Error: bundle at %@ is nil", hostBundlePath);
exit(EXIT_FAILURE);
}
NSString *bundleIdentifier = bundle.bundleIdentifier;
if (bundleIdentifier == nil) {
SULog(@"Error: Bundle Identifier for target is nil");
exit(EXIT_FAILURE);
}
application.delegate = self;
_application = application;
_delegate = delegate;
_bundle = bundle;
_remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForBundleIdentifier(bundleIdentifier)];
_statusController = [[SUStatusController alloc] initWithHost:host];
}
return self;
}
- (void)run
{
[self.application run];
}
- (void)applicationDidFinishLaunching:(NSNotification *)__unused notification
{
__weak InstallerProgressAppController *weakSelf = self;
[self.remotePort connectWithLookupCompletion:^(BOOL success) {
if (!success) {
[NSApp terminate:nil];
} else {
[weakSelf.remotePort setInvalidationHandler:^{
[weakSelf.application terminate:nil];
}];
dispatch_async(dispatch_get_main_queue(), ^{
InstallerProgressAppController *strongSelf = weakSelf;
if (strongSelf != nil) {
[strongSelf.delegate applicationDidFinishLaunchingWithTargetBundle:strongSelf.bundle];
}
});
}
}];
}
// Close status window immediately, but delay termination for a little bit to better increase the chance
// the updated application when relaunched will be the frontmost application
// This is related to OS X activation issues when terminating a frontmost application happens right before
@@ -59,74 +111,9 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
[sender replyToApplicationShouldTerminate:YES];
});
[self.statusController close];
self.statusController = nil;
[self.delegate applicationWillTerminateAfterDelay];
return NSTerminateLater;
}
- (void)applicationDidFinishLaunching:(NSNotification *)__unused notification
{
__weak InstallerProgress *weakSelf = self;
[self.remotePort connectWithLookupCompletion:^(BOOL success) {
if (!success) {
[NSApp terminate:nil];
} else {
[weakSelf.remotePort setInvalidationHandler:^{
[NSApp terminate:nil];
}];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf showInstallerProgress];
});
}
}];
}
- (void)showInstallerProgress
{
[self.statusController setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:nil isDefault:NO];
[self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"") maxProgressValue:0 statusText:@""];
[self.statusController showWindow:self];
}
@end
int main(int __unused argc, const char __unused *argv[])
{
@autoreleasepool
{
NSArray *args = [[NSProcessInfo processInfo] arguments];
if (args.count < 2) {
return EXIT_FAILURE;
}
NSString *hostBundlePath = args[1];
NSImage *applicationIcon = nil;
if (args.count > 2) {
applicationIcon = [[NSImage alloc] initWithContentsOfFile:args[2]];
}
NSBundle *bundle = [NSBundle bundleWithPath:hostBundlePath];
if (bundle == nil) {
SULog(@"Error: bundle at %@ is nil", hostBundlePath);
return EXIT_FAILURE;
}
SUHost *host = [[SUHost alloc] initWithBundle:bundle];
InstallerProgress *delegate = [[InstallerProgress alloc] initWithHost:host];
NSApplication *application = [NSApplication sharedApplication];
if (applicationIcon != nil) {
application.applicationIconImage = applicationIcon;
}
[application setDelegate:delegate];
[application run];
}
return EXIT_SUCCESS;
}
@@ -0,0 +1,20 @@
//
// InstallerProgressAppControllerDelegate.h
// Sparkle
//
// Created by Mayur Pawashe on 4/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol InstallerProgressAppControllerDelegate <NSObject>
- (void)applicationDidFinishLaunchingWithTargetBundle:(NSBundle *)bundle;
- (void)applicationWillTerminateAfterDelay;
@end
NS_ASSUME_NONNULL_END
+18
View File
@@ -0,0 +1,18 @@
//
// ShowInstallerProgress.h
// Sparkle
//
// Created by Mayur Pawashe on 4/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "InstallerProgressAppControllerDelegate.h"
NS_ASSUME_NONNULL_BEGIN
@interface ShowInstallerProgress : NSObject <InstallerProgressAppControllerDelegate>
@end
NS_ASSUME_NONNULL_END
+41
View File
@@ -0,0 +1,41 @@
//
// ShowInstallerProgress.m
// Installer Progress
//
// Created by Mayur Pawashe on 4/7/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <AppKit/AppKit.h>
#import "ShowInstallerProgress.h"
#import "SUStatusController.h"
#import "SUHost.h"
#import "SULocalizations.h"
@interface ShowInstallerProgress ()
@property (nonatomic) SUStatusController *statusController;
@end
@implementation ShowInstallerProgress
@synthesize statusController = _statusController;
- (void)applicationDidFinishLaunchingWithTargetBundle:(NSBundle *)bundle
{
SUHost *host = [[SUHost alloc] initWithBundle:bundle];
self.statusController = [[SUStatusController alloc] initWithHost:host];
[self.statusController setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:nil isDefault:NO];
[self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"") maxProgressValue:0 statusText:@""];
[self.statusController showWindow:self];
}
- (void)applicationWillTerminateAfterDelay
{
[self.statusController close];
self.statusController = nil;
}
@end
+29
View File
@@ -0,0 +1,29 @@
//
// main.m
// Sparkle
//
// Created by Mayur Pawashe on 4/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "InstallerProgressAppController.h"
#import "ShowInstallerProgress.h"
int main(int __unused argc, const char __unused *argv[])
{
@autoreleasepool
{
ShowInstallerProgress *showInstallerProgress = [[ShowInstallerProgress alloc] init];
InstallerProgressAppController *appController =
[[InstallerProgressAppController alloc]
initWithApplication:[NSApplication sharedApplication]
arguments:[[NSProcessInfo processInfo] arguments]
delegate:showInstallerProgress];
[appController run];
}
return EXIT_SUCCESS;
}