| 1 | // |
|---|
| 2 | // SUAutomaticUpdateDriver.m |
|---|
| 3 | // Sparkle |
|---|
| 4 | // |
|---|
| 5 | // Created by Andy Matuschak on 5/6/08. |
|---|
| 6 | // Copyright 2008 Andy Matuschak. All rights reserved. |
|---|
| 7 | // |
|---|
| 8 | |
|---|
| 9 | #import "SUAutomaticUpdateDriver.h" |
|---|
| 10 | |
|---|
| 11 | #import "SUAutomaticUpdateAlert.h" |
|---|
| 12 | #import "SUHost.h" |
|---|
| 13 | |
|---|
| 14 | @implementation SUAutomaticUpdateDriver |
|---|
| 15 | |
|---|
| 16 | - (void)unarchiverDidFinish:(SUUnarchiver *)ua |
|---|
| 17 | { |
|---|
| 18 | alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem host:host delegate:self]; |
|---|
| 19 | if ([NSApp isActive]) |
|---|
| 20 | [[alert window] makeKeyAndOrderFront:self]; |
|---|
| 21 | else |
|---|
| 22 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | - (void)applicationDidBecomeActive:(NSNotification *)aNotification |
|---|
| 26 | { |
|---|
| 27 | [[alert window] makeKeyAndOrderFront:self]; |
|---|
| 28 | [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSApplicationDidBecomeActiveNotification" object:NSApp]; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | - (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)aua finishedWithChoice:(SUAutomaticInstallationChoice)choice; |
|---|
| 32 | { |
|---|
| 33 | switch (choice) |
|---|
| 34 | { |
|---|
| 35 | case SUInstallNowChoice: |
|---|
| 36 | [self installUpdate]; |
|---|
| 37 | break; |
|---|
| 38 | |
|---|
| 39 | case SUInstallLaterChoice: |
|---|
| 40 | postponingInstallation = YES; |
|---|
| 41 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; |
|---|
| 42 | break; |
|---|
| 43 | |
|---|
| 44 | case SUDoNotInstallChoice: |
|---|
| 45 | [host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; |
|---|
| 46 | [self abortUpdate]; |
|---|
| 47 | break; |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | - (BOOL)shouldInstallSynchronously { return postponingInstallation; } |
|---|
| 52 | |
|---|
| 53 | - (void)installUpdate |
|---|
| 54 | { |
|---|
| 55 | showErrors = YES; |
|---|
| 56 | [super installUpdate]; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | - (void)applicationWillTerminate:(NSNotification *)note |
|---|
| 60 | { |
|---|
| 61 | [self installUpdate]; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | - (void)installerFinishedForHost:(SUHost *)aHost |
|---|
| 65 | { |
|---|
| 66 | if (aHost != host) { return; } |
|---|
| 67 | if (!postponingInstallation) |
|---|
| 68 | [self relaunchHostApp]; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | - (void)abortUpdateWithError:(NSError *)error |
|---|
| 72 | { |
|---|
| 73 | if (showErrors) |
|---|
| 74 | [super abortUpdateWithError:error]; |
|---|
| 75 | else |
|---|
| 76 | [self abortUpdate]; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | @end |
|---|