Files
Sparkle/TestApplication/SUUpdateSettingsWindowController.m
T
Zorg 1fad56c4c3 Add user driver methods for automatic updating
Note that the protocol API for the user updater driver can still be improved.

applicationWillTerminate: is done from the user driver because that's the only way that will
function across different processes.
2016-02-20 19:39:48 -05:00

166 lines
4.2 KiB
Objective-C

//
// SUUpdateSettingsWindowController.m
// Sparkle
//
// Created by Mayur Pawashe on 7/25/15.
// Copyright (c) 2015 Sparkle Project. All rights reserved.
//
#import "SUUpdateSettingsWindowController.h"
#import <Sparkle/Sparkle.h>
#import "SUUserUpdaterDriver.h"
@interface SULoggerUpdateDriver : NSObject <SUUserUpdaterDriver>
@property (nonatomic, copy) void (^applicationWillTerminate)(void);
@end
@implementation SULoggerUpdateDriver
@synthesize applicationWillTerminate = _applicationWillTerminate;
- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply
{
NSLog(@"Giving permission to automatically install updates!");
reply([SUUpdatePermissionPromptResult updatePermissionPromptResultWithChoice:SUAutomaticallyCheck shouldSendProfile:YES]);
}
- (void)showUserInitiatedUpdateCheckWithCancelCallback:(void (^)(void))cancelUpdateCheck
{
NSLog(@"Evil user initiated an update check!");
}
- (void)dismissUserInitiatedUpdateCheck
{
NSLog(@"Update check is done!");
}
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id<SUVersionDisplay>)versionDisplayer reply:(void (^)(SUUpdateAlertChoice))reply
{
NSLog(@"OMG new update was found! Let's install it!");
reply(SUInstallUpdateChoice);
}
- (void)showUpdateNotFound
{
NSLog(@":( there was no new update");
}
- (BOOL)showsUpdateNotFoundModally
{
return NO;
}
- (void)showUpdaterError:(NSError *)error
{
NSLog(@"Update error: %@", error);
}
- (BOOL)showsUpdateErrorModally
{
return NO;
}
- (void)showDownloadInitiatedWithCancelCallback:(void (^)(void))cancelDownload
{
NSLog(@"Downloading update...");
}
- (void)showDownloadDidReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Download recieved length: %lld", response.expectedContentLength);
}
- (void)showDownloadDidReceiveDataOfLength:(NSUInteger)length
{
NSLog(@"Download received progress: %lu", length);
}
- (void)showDownloadFinishedAndStartedExtractingUpdate
{
NSLog(@"Download finished.. Extracting..");
}
- (void)showExtractionReceivedProgress:(double)progress
{
NSLog(@"Extracting progress: %f", progress);
}
- (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(void))installUpdateAndRelaunch
{
NSLog(@"Extracting finished.. Letting it install & relaunch..");
installUpdateAndRelaunch();
}
- (void)showInstallingUpdate
{
NSLog(@"Installing update...");
}
- (void)dismissUpdateInstallation
{
NSLog(@"Dismissing the installation.");
}
- (void)requestAutomaticUpdatePermissionWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply
{
NSLog(@"OK, requested automatic update permission.. replying..");
reply(SUInstallLaterChoice);
}
- (void)startListeningForTermination:(void (^)(void))applicationWillTerminate
{
NSLog(@"Start listening for termination, eh?");
self.applicationWillTerminate = applicationWillTerminate;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
}
- (void)applicationWillTerminate:(NSNotification *)__unused note
{
NSLog(@"Terminating app..");
if (self.applicationWillTerminate) {
NSLog(@"App will terminate");
self.applicationWillTerminate();
self.applicationWillTerminate = nil;
}
}
- (void)dismissAutomaticUpdateInstallation
{
NSLog(@"Done with automatic update installation");
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
}
@end
@interface SUUpdateSettingsWindowController ()
@property (nonatomic) IBOutlet SUUpdater *updater;
@end
@implementation SUUpdateSettingsWindowController
@synthesize updater = _updater;
- (void)windowDidLoad
{
//self.updater.userUpdaterDriver = [[SUSparkleUserUpdaterDriver alloc] initWithHost:[[SUHost alloc] initWithBundle:[NSBundle mainBundle]]];
self.updater.userUpdaterDriver = [[SULoggerUpdateDriver alloc] init];
}
- (NSString *)windowNibName
{
return NSStringFromClass([self class]);
}
- (IBAction)checkForUpdates:(id __unused)sender
{
[self.updater checkForUpdates:nil];
}
@end