Files
Sparkle/TestApplication/SUUpdateSettingsWindowController.m
T
Zorg 46a75cde97 Terminate application in the progress agent instead of user driver
This allows us to remove SPUUserDriverUIComponent and remove a bunch of logic in the user driver regarding termination. The user drivers generally don't need to know about the application bundle anymore, and strictly now only show UI events.

This has another advantage of the agent being able to quit multiple instances of an application even if the application to update is sandboxed.

We enforce the logic that an application can only be relaunched if it was running initially.
2016-08-25 23:46:42 -04:00

78 lines
2.0 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 "SUPopUpTitlebarUserDriver.h"
@interface SUUpdateSettingsWindowController ()
@property (nonatomic) SPUUpdater *updater;
@property (nonatomic, readonly) BOOL customUserDriver;
@property (nonatomic) id<SPUStandardUserDriverProtocol> userDriver;
@end
@implementation SUUpdateSettingsWindowController
@synthesize updater = _updater;
@synthesize customUserDriver = _customUserDriver;
@synthesize userDriver = _userDriver;
- (instancetype)initWithCustomUserDriver:(BOOL)customUserDriver
{
self = [super init];
if (self != nil) {
_customUserDriver = customUserDriver;
}
return self;
}
- (NSString *)windowNibName
{
return NSStringFromClass([self class]);
}
- (void)windowDidLoad
{
NSBundle *hostBundle = [NSBundle mainBundle];
NSBundle *applicationBundle = hostBundle;
// If the user is holding down command, we use the popup title user driver instead
id<SPUUserDriver, SPUStandardUserDriverProtocol> userDriver;
if (self.customUserDriver) {
userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:self.window];
} else {
userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:nil];
}
self.userDriver = userDriver;
self.updater = [[SPUUpdater alloc] initWithHostBundle:hostBundle applicationBundle:applicationBundle userDriver:userDriver delegate:nil];
NSError *updaterError = nil;
if (![self.updater startUpdater:&updaterError]) {
NSLog(@"Failed to start updater with error: %@", updaterError);
abort();
}
}
- (IBAction)checkForUpdates:(id __unused)sender
{
[self.updater checkForUpdates];
}
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
if (menuItem.action == @selector(checkForUpdates:)) {
return self.userDriver.canCheckForUpdates;
}
return YES;
}
@end