Add no-AppKit guards against all "core" files

Also move system shut off handling to the user driver.
Observing system shut off is difficult without AppKit, and
a client may want to observe for varying types of events.
I suppose this is consistent with application termination
notifications though.
This commit is contained in:
Zorg committed 2016-02-29 01:42:16 -05:00
1 parent 02ee6f9c15
commit 4a26c395d8
37 files changed
+196 -14

No files matched your search

+4
View File
@@ -17,6 +17,10 @@
#import "SUErrors.h"
#import "SULocalizations.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@interface NSXMLElement (SUAppcastExtensions)
@property (readonly, copy) NSDictionary *attributesAsDictionary;
@end
+4
View File
@@ -15,6 +15,10 @@
#import "SULog.h"
#import "SUConstants.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@interface SUAppcastItem ()
@property (copy, readwrite) NSString *title;
@property (copy, readwrite) NSString *dateString;
-1
View File
@@ -11,7 +11,6 @@
#import <Foundation/Foundation.h>
#import "SUBasicUpdateDriver.h"
#import "SUAutomaticUpdateAlert.h"
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
+23 -8
View File
@@ -13,6 +13,11 @@
#import "SUConstants.h"
#import "SUErrors.h"
#import "SUAppcastItem.h"
#import "SULog.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
// If the user hasn't quit in a week, ask them if they want to relaunch to get the latest bits. It doesn't matter that this measure of "one day" is imprecise.
static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 24 * 7;
@@ -52,7 +57,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
- (void)installUpdateWithTerminationStatus:(NSNumber *)terminationStatus
{
switch ((SUApplicationTerminationStatus)(terminationStatus.integerValue)) {
switch ((SUApplicationTerminationStatus)(terminationStatus.unsignedIntegerValue)) {
case SUApplicationStoppedObservingTermination:
if (self.willUpdateOnTermination) {
[self abortUpdate];
@@ -76,7 +81,10 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
[self performSelectorOnMainThread:@selector(installUpdateWithTerminationStatus:) withObject:@(terminationStatus) waitUntilDone:YES];
}];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(systemWillPowerOff:) name:NSWorkspaceWillPowerOffNotification object:nil];
[self.updater.userUpdaterDriver registerSystemPowerOff:^(SUSystemPowerOffStatus systemPowerOffStatus) {
// See above comment for why we use -performSelectorOnMainThread:withObject:waitUntilDone:
[self performSelectorOnMainThread:@selector(systemWillPowerOff:) withObject:@(systemPowerOffStatus) waitUntilDone:YES];
}];
self.willUpdateOnTermination = YES;
@@ -115,8 +123,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
self.willUpdateOnTermination = NO;
[self.updater.userUpdaterDriver unregisterApplicationTermination];
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self name:NSWorkspaceWillPowerOffNotification object:nil];
[self.updater.userUpdaterDriver unregisterSystemPowerOff];
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
if ([updaterDelegate respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)])
@@ -177,11 +184,19 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
[super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI];
}
- (void)systemWillPowerOff:(NSNotification *)__unused note
- (void)systemWillPowerOff:(NSNumber *)systemPowerOffStatus
{
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSystemPowerOffError userInfo:@{
NSLocalizedDescriptionKey: SULocalizedString(@"The update will not be installed because the user requested for the system to power off", nil)
}]];
if (self.willUpdateOnTermination) {
switch ((SUSystemPowerOffStatus)(systemPowerOffStatus.unsignedIntegerValue)) {
case SUStoppedObservingSystemPowerOff:
[self abortUpdate];
break;
case SUSystemWillPowerOff:
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSystemPowerOffError userInfo:@{
NSLocalizedDescriptionKey: SULocalizedString(@"The update will not be installed because the user requested for the system to power off", nil) }]];
break;
}
}
}
- (void)abortUpdateWithError:(NSError *)error
+4
View File
@@ -26,6 +26,10 @@
#import "SULocalizations.h"
#import "SUAppcastItem.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@interface SUBasicUpdateDriver ()
@property (strong) SUAppcastItem *updateItem;
+4
View File
@@ -15,6 +15,10 @@
#include <stdlib.h>
#include <xar/xar.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
static BOOL applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFilePath, NSString *destinationFilePath)
{
NSString *patchFile = temporaryFilename(@"apply-binary-delta");
+4
View File
@@ -18,6 +18,10 @@
#include <sys/stat.h>
#include <xar/xar.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
int compareFiles(const FTSENT **a, const FTSENT **b)
{
return strcoll((*a)->fts_name, (*b)->fts_name);
+4
View File
@@ -21,6 +21,10 @@
#include <sys/xattr.h>
#include <xar/xar.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
extern int bsdiff(int argc, const char **argv);
@interface CreateBinaryDeltaOperation : NSOperation
+4
View File
@@ -12,6 +12,10 @@
#include <Foundation/Foundation.h>
#include <xar/xar.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
#define VERBOSE_FLAG @"--verbose"
#define VERSION_FLAG @"--version"
+4
View File
@@ -13,6 +13,10 @@
#import "SUHost.h"
#import "SULog.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUBinaryDeltaUnarchiver
+ (BOOL)canUnarchivePath:(NSString *)path
+4
View File
@@ -11,6 +11,10 @@
#import "SUCodeSigningVerifier.h"
#import "SULog.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUCodeSigningVerifier
+ (BOOL)codeSignatureAtPath:(NSString *)oldApplicationPath matchesSignatureAtPath:(NSString *)newApplicationPath error:(NSError *__autoreleasing *)error
+4
View File
@@ -18,6 +18,10 @@
#define DEBUG 0
#endif
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
// Define some minimum intervals to avoid DoS-like checking attacks
const NSTimeInterval SUMinimumUpdateCheckInterval = DEBUG ? 60 : (60 * 60);
const NSTimeInterval SUDefaultUpdateCheckInterval = DEBUG ? 60 : (60 * 60 * 24);
+4
View File
@@ -16,6 +16,10 @@
#import "SULog.h"
#include <CommonCrypto/CommonDigest.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUDSAVerifier {
SecKeyRef _secKey;
}
+4
View File
@@ -11,6 +11,10 @@
#import "SULog.h"
#include <CoreServices/CoreServices.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUDiskImageUnarchiver
+ (BOOL)canUnarchivePath:(NSString *)path
+4
View File
@@ -14,6 +14,10 @@
#include <sys/errno.h>
#include <sys/time.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine";
// Authorization code based on generous contribution from Allan Odgaard. Thanks, Allan!
-1
View File
@@ -23,7 +23,6 @@ A guided installation can be started by applications other than the application
#define SUGUIDEDPACKAGEINSTALLER_H
#import <Foundation/Foundation.h>
#import "Sparkle.h"
#import "SUInstaller.h"
@interface SUGuidedPackageInstaller : SUInstaller
+5
View File
@@ -10,6 +10,11 @@
#import <Security/Security.h>
#import "SUParameterAssert.h"
#import "SUGuidedPackageInstaller.h"
#import "SUErrors.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, char* const* arguments)
{
+4
View File
@@ -14,6 +14,10 @@
#import "SULog.h"
#import "SUParameterAssert.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@interface SUHost ()
@property (strong, readwrite) NSBundle *bundle;
+5
View File
@@ -14,6 +14,11 @@
#import "SUConstants.h"
#import "SULog.h"
#import "SUParameterAssert.h"
#import "SUErrors.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUInstaller
+4
View File
@@ -13,6 +13,10 @@
#include "SULog.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" implementation and should NOT import AppKit
#endif
// -----------------------------------------------------------------------------
// Constants:
+4
View File
@@ -7,6 +7,10 @@
#import "SUOperatingSystem.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000
@interface NSProcessInfo ()
- (NSOperatingSystemVersion)operatingSystemVersion;
+4
View File
@@ -10,6 +10,10 @@
#import "SUConstants.h"
#import "SUErrors.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUPackageInstaller
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)__unused host versionComparator:(id<SUVersionComparison>)__unused comparator completionHandler:(void (^)(NSError *))completionHandler
+3
View File
@@ -10,6 +10,9 @@
#import "SUUnarchiver_Private.h"
#import "SULog.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUPipedUnarchiver
+4
View File
@@ -15,6 +15,10 @@
#import "SUErrors.h"
#import "SUParameterAssert.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUPlainInstaller
// Returns the bundle version from the specified host that is appropriate to use as a filename, or nil if we're unable to retrieve one
+4
View File
@@ -9,6 +9,10 @@
#import "SUProbingUpdateDriver.h"
#import "SUUpdater.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUProbingUpdateDriver
// Stop as soon as we have an answer! Since the superclass implementations are not called, we are responsible for notifying the delegate.
+4
View File
@@ -13,6 +13,10 @@
#import "SUAppcastItem.h"
#import "SUVersionComparisonProtocol.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@interface SUScheduledUpdateDriver ()
@property (assign) BOOL showErrors;
+40
View File
@@ -54,6 +54,8 @@
@property (nonatomic, copy) void (^applicationTerminationHandler)(SUApplicationTerminationStatus);
@property (nonatomic, copy) void (^systemPowerOffHandler)(SUSystemPowerOffStatus);
@property (nonatomic) BOOL installingUpdateOnTermination;
@end
@@ -73,6 +75,7 @@
@synthesize downloadStatusCompletion = _downloadStatusCompletion;
@synthesize installUpdateHandler = _installUpdateHandler;
@synthesize applicationTerminationHandler = _applicationTerminationHandler;
@synthesize systemPowerOffHandler = _systemPowerOffHandler;
@synthesize installingUpdateOnTermination = _installingUpdateOnTermination;
#pragma mark Birth
@@ -537,6 +540,42 @@
});
}
#pragma mark System Death
- (void)registerSystemPowerOff:(void (^)(SUSystemPowerOffStatus))systemPowerOffHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
self.systemPowerOffHandler = systemPowerOffHandler;
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(systemWillPowerOff:) name:NSWorkspaceWillPowerOffNotification object:nil];
});
}
- (void)cancelObservingSystemPowerOff
{
if (self.systemPowerOffHandler != nil) {
self.systemPowerOffHandler(SUStoppedObservingSystemPowerOff);
self.systemPowerOffHandler = nil;
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self name:NSWorkspaceWillPowerOffNotification object:nil];
}
}
- (void)unregisterSystemPowerOff
{
dispatch_async(dispatch_get_main_queue(), ^{
[self cancelObservingSystemPowerOff];
});
}
- (void)systemWillPowerOff:(NSNotification *)__unused notification
{
if (self.systemPowerOffHandler != nil) {
self.systemPowerOffHandler(SUSystemWillPowerOff);
self.systemPowerOffHandler = nil;
}
}
#pragma mark Aborting Update
- (void)dismissUpdateInstallation
@@ -563,6 +602,7 @@
}
[self cancelObservingApplicationTermination];
[self cancelObservingSystemPowerOff];
[self cancelInstallAndRestart];
});
}
+4
View File
@@ -13,6 +13,10 @@
#import "SUVersionComparisonProtocol.h"
#import "SUStandardVersionComparator.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUStandardVersionComparator
+ (SUStandardVersionComparator *)defaultComparator
+4
View File
@@ -13,6 +13,10 @@
#import "SUOperatingSystem.h"
#include <sys/sysctl.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
static NSString *const SUSystemProfilerApplicationNameKey = @"appName";
static NSString *const SUSystemProfilerApplicationVersionKey = @"appVersion";
static NSString *const SUSystemProfilerCPU64bitKey = @"cpu64bit";
-1
View File
@@ -11,7 +11,6 @@
#import <Foundation/Foundation.h>
#import "SUBasicUpdateDriver.h"
#import "SUUpdateAlert.h"
@class SUStatusController;
+4
View File
@@ -14,6 +14,10 @@
#import "SUConstants.h"
#import "SUAppcastItem.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUUIBasedUpdateDriver
- (instancetype)initWithUpdater:(SUUpdater *)anUpdater host:(SUHost *)aHost
+4
View File
@@ -15,6 +15,10 @@
#import "SUUnarchiver.h"
#import "SUUnarchiver_Private.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@implementation SUUnarchiver
@synthesize archivePath;
+4
View File
@@ -12,6 +12,10 @@
#import <Foundation/Foundation.h>
#import "SUUnarchiver.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@interface SUUnarchiver (Private)
+ (void)registerImplementation:(Class)implementation;
+ (NSArray *)unarchiverImplementations;
+4
View File
@@ -10,6 +10,10 @@
#import "SUHost.h"
#import "SULog.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
NSString *const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished";
@interface SUUpdateDriver ()
+4 -3
View File
@@ -8,10 +8,7 @@
#import "SUUpdater.h"
#import "SUSparkleUserUpdaterDriver.h"
#import "SUHost.h"
#import "SUUpdatePermissionPrompt.h"
#import "SUUpdatePermissionPromptResult.h"
#import "SUAutomaticUpdateDriver.h"
@@ -24,6 +21,10 @@
#import "SUSystemProfiler.h"
#include <SystemConfiguration/SystemConfiguration.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
NSString *const SUUpdaterDidFinishLoadingAppCastNotification = @"SUUpdaterDidFinishLoadingAppCastNotification";
NSString *const SUUpdaterDidFindValidUpdateNotification = @"SUUpdaterDidFindValidUpdateNotification";
NSString *const SUUpdaterDidNotFindUpdateNotification = @"SUUpdaterDidNotFindUpdateNotification";
+4
View File
@@ -10,6 +10,10 @@
#import "SUUpdater.h"
#import "SUHost.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
#endif
@interface SUUserInitiatedUpdateDriver ()
@property (assign, getter=isCanceled) BOOL canceled;
+8
View File
@@ -35,6 +35,11 @@ typedef NS_ENUM(NSUInteger, SUApplicationTerminationStatus) {
SUApplicationStoppedObservingTermination
};
typedef NS_ENUM(NSUInteger, SUSystemPowerOffStatus) {
SUSystemWillPowerOff,
SUStoppedObservingSystemPowerOff
};
typedef NS_ENUM(NSUInteger, SUInstallUpdateStatus) {
SUInstallAndRelaunchUpdateNow,
SUCancelUpdateInstallation
@@ -87,6 +92,9 @@ typedef NS_ENUM(NSUInteger, SUInstallUpdateStatus) {
- (void)unregisterApplicationTermination;
- (void)terminateApplication;
- (void)registerSystemPowerOff:(void (^)(SUSystemPowerOffStatus))systemPowerOffHandler;
- (void)unregisterSystemPowerOff;
- (void)dismissUpdateInstallation;
@end