Skip to content

Commit

Permalink
Merge pull request #310 from lindegroup/v1.2.1-rc2
Browse files Browse the repository at this point in the history
Merge to master for 1.2.1.
  • Loading branch information
homebysix committed Mar 8, 2015
2 parents 9681f84 + 50d02f0 commit df6f119
Show file tree
Hide file tree
Showing 33 changed files with 2,450 additions and 552 deletions.
26 changes: 26 additions & 0 deletions AutoPkgr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
BE025CF719BAE93400D36345 /* LGAutoPkgTask.m in Sources */ = {isa = PBXBuildFile; fileRef = BE025CF519BAE93400D36345 /* LGAutoPkgTask.m */; };
BE025CFE19BAEF8800D36345 /* LGAutoPkgSchedule.m in Sources */ = {isa = PBXBuildFile; fileRef = BE025CFD19BAEF8800D36345 /* LGAutoPkgSchedule.m */; };
BE025CFF19BAEF8800D36345 /* LGAutoPkgSchedule.m in Sources */ = {isa = PBXBuildFile; fileRef = BE025CFD19BAEF8800D36345 /* LGAutoPkgSchedule.m */; };
BE053D151A8F90920021D97B /* LGPasswords.m in Sources */ = {isa = PBXBuildFile; fileRef = BE053D141A8F90920021D97B /* LGPasswords.m */; };
BE053D181A8F9DAA0021D97B /* SNTCodesignChecker.m in Sources */ = {isa = PBXBuildFile; fileRef = BE053D171A8F9DAA0021D97B /* SNTCodesignChecker.m */; };
BE053D1B1A8F9DC00021D97B /* SNTCertificate.m in Sources */ = {isa = PBXBuildFile; fileRef = BE053D1A1A8F9DC00021D97B /* SNTCertificate.m */; };
BE05CE6A19DAF26B0089068B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BE05CE6919DAF26B0089068B /* main.m */; };
BE05CE7519DAF4DA0089068B /* com.lindegroup.AutoPkgr.helper in Copy Files: Helper Tool */ = {isa = PBXBuildFile; fileRef = BE05CE6719DAF26B0089068B /* com.lindegroup.AutoPkgr.helper */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
BE05CE7C19DAF5A30089068B /* LGAutoPkgrHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = BE05CE7A19DAF5A30089068B /* LGAutoPkgrHelper.m */; };
Expand All @@ -58,6 +61,8 @@
BE73CDC719E062AC00441443 /* NSString+cleaned.m in Sources */ = {isa = PBXBuildFile; fileRef = BE73CDC619E062AC00441443 /* NSString+cleaned.m */; };
BE8526B219D5F641007DFA9E /* SecurityInterface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BE8526B119D5F641007DFA9E /* SecurityInterface.framework */; };
BE87994B1995BA410082472B /* LGDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = BE87994A1995BA410082472B /* LGDefaults.m */; };
BE8C7D6E1A86CEF600EBD32A /* LGTools.m in Sources */ = {isa = PBXBuildFile; fileRef = BE8C7D6D1A86CEF600EBD32A /* LGTools.m */; };
BE8C7D6F1A86D32B00EBD32A /* LGTools.m in Sources */ = {isa = PBXBuildFile; fileRef = BE8C7D6D1A86CEF600EBD32A /* LGTools.m */; };
BEBF7B171A4894AC00E9967F /* LGVersioner.m in Sources */ = {isa = PBXBuildFile; fileRef = BEBF7B161A4894AC00E9967F /* LGVersioner.m */; };
BEBF7B1F1A48955C00E9967F /* LGVersioner.m in Sources */ = {isa = PBXBuildFile; fileRef = BEBF7B161A4894AC00E9967F /* LGVersioner.m */; };
BEC1258519F045EB006696C4 /* LGRecipes.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A0ACE33196FB349002C7FE4 /* LGRecipes.m */; };
Expand Down Expand Up @@ -183,6 +188,12 @@
BE025CF519BAE93400D36345 /* LGAutoPkgTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGAutoPkgTask.m; sourceTree = "<group>"; };
BE025CFC19BAEF8800D36345 /* LGAutoPkgSchedule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGAutoPkgSchedule.h; sourceTree = "<group>"; };
BE025CFD19BAEF8800D36345 /* LGAutoPkgSchedule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGAutoPkgSchedule.m; sourceTree = "<group>"; };
BE053D131A8F90920021D97B /* LGPasswords.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGPasswords.h; sourceTree = "<group>"; };
BE053D141A8F90920021D97B /* LGPasswords.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGPasswords.m; sourceTree = "<group>"; };
BE053D161A8F9DAA0021D97B /* SNTCodesignChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SNTCodesignChecker.h; sourceTree = "<group>"; };
BE053D171A8F9DAA0021D97B /* SNTCodesignChecker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SNTCodesignChecker.m; sourceTree = "<group>"; };
BE053D191A8F9DC00021D97B /* SNTCertificate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SNTCertificate.h; sourceTree = "<group>"; };
BE053D1A1A8F9DC00021D97B /* SNTCertificate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SNTCertificate.m; sourceTree = "<group>"; };
BE05CE6719DAF26B0089068B /* com.lindegroup.AutoPkgr.helper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = com.lindegroup.AutoPkgr.helper; sourceTree = BUILT_PRODUCTS_DIR; };
BE05CE6919DAF26B0089068B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
BE05CE7619DAF5A30089068B /* helper-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "helper-Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -225,6 +236,8 @@
BE8526B119D5F641007DFA9E /* SecurityInterface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SecurityInterface.framework; path = System/Library/Frameworks/SecurityInterface.framework; sourceTree = SDKROOT; };
BE8799491995BA410082472B /* LGDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGDefaults.h; sourceTree = "<group>"; };
BE87994A1995BA410082472B /* LGDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGDefaults.m; sourceTree = "<group>"; };
BE8C7D6C1A86CEF600EBD32A /* LGTools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGTools.h; sourceTree = "<group>"; };
BE8C7D6D1A86CEF600EBD32A /* LGTools.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGTools.m; sourceTree = "<group>"; };
BE94AA7B19BB8A78001A00D0 /* LGProgressDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LGProgressDelegate.h; sourceTree = "<group>"; };
BEAA76CA19BFD635002D73EE /* LGInstaller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGInstaller.h; sourceTree = "<group>"; };
BEAA76CB19BFD635002D73EE /* LGInstaller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGInstaller.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -449,6 +462,10 @@
BE05CE7D19DAF5B80089068B /* Supporting Files */ = {
isa = PBXGroup;
children = (
BE053D191A8F9DC00021D97B /* SNTCertificate.h */,
BE053D1A1A8F9DC00021D97B /* SNTCertificate.m */,
BE053D161A8F9DAA0021D97B /* SNTCodesignChecker.h */,
BE053D171A8F9DAA0021D97B /* SNTCodesignChecker.m */,
BE05CE7619DAF5A30089068B /* helper-Info.plist */,
BE05CE7719DAF5A30089068B /* helper-Launchd.plist */,
BE05CE7819DAF5A30089068B /* helper-Prefix.pch */,
Expand Down Expand Up @@ -523,8 +540,12 @@
BEFC931C1995F0710074C938 /* LGError.m */,
1AC86D3B195E0AC6006FDD2B /* LGHostInfo.h */,
1AC86D3C195E0AC6006FDD2B /* LGHostInfo.m */,
BE8C7D6C1A86CEF600EBD32A /* LGTools.h */,
BE8C7D6D1A86CEF600EBD32A /* LGTools.m */,
BE0E857719D668F600B25B5E /* LGHTTPRequest.h */,
BE0E857819D668F600B25B5E /* LGHTTPRequest.m */,
BE053D131A8F90920021D97B /* LGPasswords.h */,
BE053D141A8F90920021D97B /* LGPasswords.m */,
1A1BAD94197A0407008192A7 /* LGVersionComparator.h */,
1A1BAD95197A0407008192A7 /* LGVersionComparator.m */,
BEBF7B151A4894AC00E9967F /* LGVersioner.h */,
Expand Down Expand Up @@ -818,6 +839,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BE053D151A8F90920021D97B /* LGPasswords.m in Sources */,
BE0BACD11A2560AE00554989 /* LGJSSDistributionPointsPrefPanel.m in Sources */,
BEC1258919F046FA006696C4 /* main.m in Sources */,
BED02ADC1A194F9C00714CC2 /* NSArray+filtered.m in Sources */,
Expand All @@ -828,6 +850,7 @@
1AC86D3D195E0AC6006FDD2B /* LGHostInfo.m in Sources */,
BEC1258719F0465F006696C4 /* LGAutoPkgTask.m in Sources */,
BE025CFE19BAEF8800D36345 /* LGAutoPkgSchedule.m in Sources */,
BE8C7D6E1A86CEF600EBD32A /* LGTools.m in Sources */,
1AC98412195CE8520071CAB3 /* LGEmailer.m in Sources */,
BE6815D51A0B18DE004AD310 /* LGUserNotifications.m in Sources */,
BEC1258A19F04703006696C4 /* LGInstaller.m in Sources */,
Expand Down Expand Up @@ -866,6 +889,7 @@
BEFC3C7E1A3DF16700C789E9 /* LGRecipeOverrides.m in Sources */,
BEFC3C7F1A3DF16700C789E9 /* LGTableView.m in Sources */,
BEFC3C821A3DF16700C789E9 /* LGConstants.m in Sources */,
BE8C7D6F1A86D32B00EBD32A /* LGTools.m in Sources */,
BEFC3C831A3DF16700C789E9 /* LGDefaults.m in Sources */,
BEFC3C841A3DF16700C789E9 /* LGError.m in Sources */,
BEFC3C851A3DF16700C789E9 /* LGHostInfo.m in Sources */,
Expand All @@ -891,6 +915,8 @@
BE05CE9119DB380F0089068B /* LGConstants.m in Sources */,
BE1C810419E8224000EF77F3 /* NSImage+statusLight.m in Sources */,
BE05CE6A19DAF26B0089068B /* main.m in Sources */,
BE053D1B1A8F9DC00021D97B /* SNTCertificate.m in Sources */,
BE053D181A8F9DAA0021D97B /* SNTCodesignChecker.m in Sources */,
BE05CE7C19DAF5A30089068B /* LGAutoPkgrHelper.m in Sources */,
BE05CE8D19DB379C0089068B /* LGAutoPkgrAuthorizer.m in Sources */,
BE05CE9219DB38180089068B /* LGError.m in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions AutoPkgr/AutoPkgr-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<string>1.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>683</string>
<string>724</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 2 additions & 0 deletions AutoPkgr/Custom Catagories/NSString+cleaned.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
*/
@property (copy, nonatomic, readonly) NSString *blankIsNil;

- (NSString *)truncateToLength:(NSInteger)length;

@end
10 changes: 10 additions & 0 deletions AutoPkgr/Custom Catagories/NSString+cleaned.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ - (NSString *)blankIsNil
return aString;
}

- (NSString *)truncateToLength:(NSInteger)length
{
if ((self.length > length) && (length > 0)) {
NSRange stringRange = { 0, length };

return [[self substringWithRange:stringRange] stringByAppendingString:@"..."];
}
return self;
}

@end
126 changes: 71 additions & 55 deletions AutoPkgr/LGAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ @implementation LGAppDelegate {
- (void)applicationWillFinishLaunching:(NSNotification *)notification
{
// Setup activation policy. By default set as menubar only.
[[LGDefaults standardUserDefaults] registerDefaults:@{ kLGApplicationDisplayStyle : @(kLGDisplayStyleShowMenu) }];
[[LGDefaults standardUserDefaults] registerDefaults:@{ kLGApplicationDisplayStyle : @(kLGDisplayStyleShowMenu | kLGDisplayStyleShowDock) }];

if (([[LGDefaults standardUserDefaults] applicationDisplayStyle] & kLGDisplayStyleShowDock)) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
Expand All @@ -75,17 +75,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
NSLog(@"Welcome to AutoPkgr!");
DLog(@"Verbose logging is active. To deactivate, option-click the AutoPkgr menu icon and uncheck Verbose Logs.");

// Start observing distributed notifications for background runs
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveStatusUpdate:)
name:kLGNotificationProgressMessageUpdate
object:nil];
// Setup the status item
[self setupStatusItem];

// Check if we're authorized to install helper tool,
// if not just quit
NSError *error;

if (![AHLaunchCtl installHelper:kLGAutoPkgrHelperToolName prompt:@"" error:&error]) {
if (error) {
NSLog(@"%@", error.localizedDescription);
Expand All @@ -94,6 +90,17 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
}
}

// Register to get background progress updates...
LGAutoPkgrHelperConnection *backgroundMonitor = [LGAutoPkgrHelperConnection new];

[backgroundMonitor connectToHelper];
backgroundMonitor.connection.exportedObject = self;
backgroundMonitor.connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(LGProgressDelegate)];

[[backgroundMonitor.connection remoteObjectProxy] registerMainApplication:^(BOOL resign) {
DLog(@"No longer monitoring scheduled autopkg run");
}];

if (![LGRecipes migrateToIdentifiers:nil]) {
[NSApp presentError:[NSError errorWithDomain:kLGApplicationName code:-1 userInfo:@{ NSLocalizedDescriptionKey : @"AutoPkgr will now quit.",
NSLocalizedRecoverySuggestionErrorKey : @"You've chosen not to upgrade your recipe list. Either relaunch AutoPkgr to restart the migration process, or downgrade to an older 1.1.x AutoPkgr release." }]];
Expand All @@ -119,12 +126,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification

- (void)applicationWillTerminate:(NSNotification *)notification
{
if (jobIsRunning(kLGAutoPkgrHelperToolName, kAHGlobalLaunchDaemon)) {
LGAutoPkgrHelperConnection *helper = [LGAutoPkgrHelperConnection new];
[helper connectToHelper];
[[helper.connection remoteObjectProxy] quitHelper:^(BOOL success) {}];
}

// Stop observing...
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kLGNotificationProgressMessageUpdate object:nil];
}
Expand All @@ -135,6 +136,30 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisible
return YES;
}

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
if (jobIsRunning(kLGAutoPkgrHelperToolName, kAHGlobalLaunchDaemon)) {
LGAutoPkgrHelperConnection *helper = [LGAutoPkgrHelperConnection new];
[helper connectToHelper];

DLog(@"Sending quit signal to helper tool...");
[[helper.connection remoteObjectProxyWithErrorHandler:^(NSError *error) {
[[NSApplication sharedApplication] replyToApplicationShouldTerminate:YES];
}] quitHelper:^(BOOL success) {
[[NSApplication sharedApplication] replyToApplicationShouldTerminate:YES];
}];

return NSTerminateLater;
}
return NSTerminateNow;
}

- (void)applicationWillResignActive:(NSNotification *)notification
{
// Write out preferences to disk to ensure the background run picks up any changes.
[[LGDefaults standardUserDefaults] synchronize];
}

#pragma mark - Setup
- (void)setupStatusItem
{
Expand Down Expand Up @@ -223,53 +248,31 @@ - (void)showConfigurationWindow:(id)sender

- (IBAction)uninstallHelper:(id)sender
{
LGAutoPkgrHelperConnection *helper = [LGAutoPkgrHelperConnection new];
NSData *authData = [LGAutoPkgrAuthorizer authorizeHelper];

[helper connectToHelper];
[[helper.connection remoteObjectProxyWithErrorHandler:^(NSError *error) {
[NSApp presentError:error];
}] uninstall:authData
reply:^(NSError *error) {
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
if (error) {
if (error.code != errAuthorizationCanceled) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[NSApp presentError:error];
}];
}
} else {
// if uninstalling turn off schedule in defaults so it's not automatically recreated
NSAlert *alert = [NSAlert alertWithMessageText:@"Removed AutoPkgr associated files" defaultButton:@"Thanks for using AutoPkgr" alternateButton:nil otherButton:nil informativeTextWithFormat: @"including the helper tool, launchd schedule, and other launchd plist. You can safely remove it from your Applications folder."];
[alert runModal];
[[NSApplication sharedApplication]terminate:self];
}
}];
}];
}

#pragma mark - Progress Protocol
- (void)didReceiveStatusUpdate:(NSNotification *)aNotification
{
NSDictionary *info = aNotification.userInfo;
NSString *message = info[kLGNotificationUserInfoMessage];
NSError *error;

if (!_initialMessageFromBackgroundRunProcessed) {
_configurationWindowInitiallyVisible = [_configurationWindowController.window isVisible];
if (_configurationWindowController && _configurationWindowInitiallyVisible) {
[_configurationWindowController startProgressWithMessage:@"Performing AutoPkg background run."];
if (jobIsRunning(kLGAutoPkgrLaunchDaemonPlist, kAHGlobalLaunchDaemon)) {
[[AHLaunchCtl sharedController] remove:kLGAutoPkgrLaunchDaemonPlist fromDomain:kAHGlobalLaunchDaemon error:&error];
if (error) {
NSLog(@"%@", error.localizedDescription);
} else {
NSLog(@"Disabled schedule.");
}
_initialMessageFromBackgroundRunProcessed = YES;
}

if ([info[kLGNotificationUserInfoSuccess] boolValue]) {
[self stopProgress:nil];
if (![AHLaunchCtl uninstallHelper:kLGAutoPkgrHelperToolName prompt:@"Remove AutoPkgr's components." error:&error]) {
if (error.code != errAuthorizationCanceled) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[NSApp presentError:error];
}];
}
} else {
double progress = [info[kLGNotificationUserInfoProgress] doubleValue];
[self updateProgress:message progress:progress];
NSAlert *alert = [NSAlert alertWithMessageText:@"Removed AutoPkgr associated files." defaultButton:@"Thanks for using AutoPkgr" alternateButton:nil otherButton:nil informativeTextWithFormat:@"This includes the helper tool, launchd schedule, and other launchd plist. You can safely remove it from your Applications folder."];
[alert runModal];
[[NSApplication sharedApplication] terminate:self];
}
}

#pragma mark - Progress Protocol
- (void)startProgressWithMessage:(NSString *)message
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
Expand Down Expand Up @@ -318,10 +321,8 @@ - (void)updateProgress:(NSString *)message progress:(double)progress
[_configurationWindowController updateProgress:message progress:progress];
}

if (message.length < 50) {
NSMenuItem *runStatus = [self.statusMenu itemAtIndex:0];
runStatus.title = message;
}
NSMenuItem *runStatus = [self.statusMenu itemAtIndex:0];
runStatus.title = [message truncateToLength:50];
}];
}

Expand Down Expand Up @@ -384,6 +385,21 @@ - (IBAction)changeCheckForNewVersionsOfAppsAutomatically:(id)sender
}

#pragma mark - Menu Delegate
- (void)menuWillOpen:(NSMenu *)menu
{
// The preferences set via the background run are not picked up
// despite aggressive synchronization, so we need to pull the value from
// the actual preference file until a better work around is found...

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/com.lindegroup.AutoPkgr.plist" stringByExpandingTildeInPath]];

NSString *date = dict[@"LastAutoPkgRun"];
if (date) {
NSString *status = [NSString stringWithFormat:@"Last AutoPkg Run: %@", date ?: @"Never by AutoPkgr"];
[_progressMenuItem setTitle:status];
}
}

- (void)menuDidClose:(NSMenu *)menu
{
self.statusItem.image = [NSImage imageNamed:@"autopkgr.png"];
Expand Down
Loading

0 comments on commit df6f119

Please sign in to comment.