Skip to content
This repository

SUUpdater Notifications #234

Closed
wants to merge 1 commit into from

2 participants

Doug Russell Andy Matuschak
Doug Russell

SUUpdater Notifications for events that might be interesting to more than just the delegate

Andy Matuschak

Thanks for the pull request!

Hm. I am wary of this kind of API. How are you using all these?

Doug Russell

We attach the delegate to the app delegate or some other long lived object so it can handle messages that require a decision

-(BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle;

for example.

We then use the notifications to keep transient objects like preference UI up to date.

Andy Matuschak
Doug Russell

Yes, for the preferences UI case bindings would probably be more correct.

Doug Russell rustle closed this January 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 06, 2012
Doug Russell SUUpdater Notifications for events that might be interesting to more …
…than just the delegate
a10521c
This page is out of date. Refresh to see the latest.
7  SUBasicUpdateDriver.m
@@ -98,6 +98,9 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac
98 98
 {
99 99
 	if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)])
100 100
 		[[updater delegate] updater:updater didFinishLoadingAppcast:ac];
  101
+	
  102
+	NSDictionary *userInfo = (ac != nil) ? @{SUUpdaterAppcastNotificationKey : ac} : nil;
  103
+	[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFinishLoadingAppCastNotification object:updater userInfo:userInfo];
101 104
     
102 105
     SUAppcastItem *item = nil;
103 106
     
@@ -143,6 +146,8 @@ - (void)didFindValidUpdate
143 146
 {
144 147
 	if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
145 148
 		[[updater delegate] updater:updater didFindValidUpdate:updateItem];
  149
+	NSDictionary *userInfo = (updateItem != nil) ? @{SUUpdaterAppcastItemNotificationKey : updateItem} : nil;
  150
+	[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFinishLoadingAppCastNotification object:updater userInfo:userInfo];
146 151
 	[self downloadUpdate];
147 152
 }
148 153
 
@@ -150,6 +155,8 @@ - (void)didNotFindUpdate
150 155
 {
151 156
 	if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
152 157
 		[[updater delegate] updaterDidNotFindUpdate:updater];
  158
+	[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater];
  159
+	
153 160
 	[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]] forKey:NSLocalizedDescriptionKey]]];
154 161
 }
155 162
 
4  SUProbingUpdateDriver.m
@@ -17,6 +17,8 @@ - (void)didFindValidUpdate
17 17
 {
18 18
 	if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
19 19
 		[[updater delegate] updater:updater didFindValidUpdate:updateItem];
  20
+	NSDictionary *userInfo = (updateItem != nil) ? @{SUUpdaterAppcastItemNotificationKey : updateItem} : nil;
  21
+	[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification object:updater userInfo:userInfo];
20 22
 	[self abortUpdate];
21 23
 }
22 24
 
@@ -24,6 +26,8 @@ - (void)didNotFindUpdate
24 26
 {
25 27
 	if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
26 28
 		[[updater delegate] updaterDidNotFindUpdate:updater];
  29
+	[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater];
  30
+	
27 31
 	[self abortUpdate];
28 32
 }
29 33
 
2  SUScheduledUpdateDriver.m
@@ -25,6 +25,8 @@ - (void)didNotFindUpdate
25 25
 {
26 26
 	if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
27 27
 		[[updater delegate] updaterDidNotFindUpdate:updater];
  28
+	[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater];
  29
+	
28 30
 	[self abortUpdate]; // Don't tell the user that no update was found; this was a scheduled update.
29 31
 }
30 32
 
1  SUUIBasedUpdateDriver.m
@@ -50,6 +50,7 @@ - (void)didNotFindUpdate
50 50
 {
51 51
 	if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
52 52
 		[[updater delegate] updaterDidNotFindUpdate:updater];
  53
+	[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater];
53 54
 	
54 55
 	NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up-to-date!", nil) defaultButton:SULocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [host name], [host displayVersion]];
55 56
 	[self showModalAlert:alert];
14  SUUpdater.h
@@ -75,6 +75,20 @@
75 75
 
76 76
 @end
77 77
 
  78
+// -----------------------------------------------------------------------------
  79
+// SUUpdater Notifications for events that might be interesting to more than just the delegate
  80
+// The updater will be the notification object
  81
+// -----------------------------------------------------------------------------
  82
+extern NSString *const SUUpdaterDidFinishLoadingAppCastNotification;
  83
+extern NSString *const SUUpdaterDidFindValidUpdateNotification;
  84
+extern NSString *const SUUpdaterDidNotFindUpdateNotification;
  85
+extern NSString *const SUUpdaterWillInstallUpdateNotification;
  86
+extern NSString *const SUUpdaterWillRelaunchApplicationNotification;
  87
+
  88
+// Key for the SUAppcastItem object in the SUUpdaterDidFindValidUpdateNotification & SUUpdaterWillInstallUpdateNotification userInfos
  89
+extern NSString *const SUUpdaterAppcastItemNotificationKey;
  90
+// Key for the SUAppcast object in the SUUpdaterDidFinishLoadingAppCastNotification userInfo
  91
+extern NSString *const SUUpdaterAppcastNotificationKey;
78 92
 
79 93
 // -----------------------------------------------------------------------------
80 94
 //	SUUpdater Delegate:
7  SUUpdater.m
@@ -19,6 +19,13 @@
19 19
 #import "SULog.h"
20 20
 #include <SystemConfiguration/SystemConfiguration.h>
21 21
 
  22
+NSString *const SUUpdaterDidFinishLoadingAppCastNotification = @"SUUpdaterDidFinishLoadingAppCastNotification";
  23
+NSString *const SUUpdaterDidFindValidUpdateNotification = @"SUUpdaterDidFindValidUpdateNotification";
  24
+NSString *const SUUpdaterDidNotFindUpdateNotification = @"SUUpdaterDidNotFindUpdateNotification";
  25
+NSString *const SUUpdaterWillInstallUpdateNotification = @"SUUpdaterWillInstallUpdateNotification";
  26
+NSString *const SUUpdaterWillRelaunchApplicationNotification = @"SUUpdaterWillRelaunchApplicationNotification";
  27
+NSString *const SUUpdaterAppcastItemNotificationKey = @"SUUpdaterAppcastItemNotificationKey";
  28
+NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotificationKey";
22 29
 
23 30
 @interface SUUpdater (Private)
24 31
 - (id)initForBundle:(NSBundle *)bundle;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.