Add Sparkle automatic updater.
[enjoyable.git] / Sparkle.framework / Versions / A / Headers / SUUpdater.h
1 //
2 // SUUpdater.h
3 // Sparkle
4 //
5 // Created by Andy Matuschak on 1/4/06.
6 // Copyright 2006 Andy Matuschak. All rights reserved.
7 //
8
9 #ifndef SUUPDATER_H
10 #define SUUPDATER_H
11
12 #import "SUVersionComparisonProtocol.h"
13 #import "SUVersionDisplayProtocol.h"
14
15 @class SUUpdateDriver, SUAppcastItem, SUHost, SUAppcast;
16
17 @interface SUUpdater : NSObject
18 {
19 @private
20 NSTimer *checkTimer;
21 SUUpdateDriver *driver;
22
23 NSString *customUserAgentString;
24 SUHost *host;
25 IBOutlet id delegate;
26 }
27
28 + (SUUpdater *)sharedUpdater;
29 + (SUUpdater *)updaterForBundle:(NSBundle *)bundle;
30 - (id)initForBundle:(NSBundle *)bundle;
31
32 - (NSBundle *)hostBundle;
33
34 - (void)setDelegate:(id)delegate;
35 - (id)delegate;
36
37 - (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyChecks;
38 - (BOOL)automaticallyChecksForUpdates;
39
40 - (void)setUpdateCheckInterval:(NSTimeInterval)interval;
41 - (NSTimeInterval)updateCheckInterval;
42
43 - (void)setFeedURL:(NSURL *)feedURL;
44 - (NSURL *)feedURL; // *** MUST BE CALLED ON MAIN THREAD ***
45
46 - (void)setUserAgentString:(NSString *)userAgent;
47 - (NSString *)userAgentString;
48
49 - (void)setSendsSystemProfile:(BOOL)sendsSystemProfile;
50 - (BOOL)sendsSystemProfile;
51
52 - (void)setAutomaticallyDownloadsUpdates:(BOOL)automaticallyDownloadsUpdates;
53 - (BOOL)automaticallyDownloadsUpdates;
54
55 // This IBAction is meant for a main menu item. Hook up any menu item to this action,
56 // and Sparkle will check for updates and report back its findings verbosely.
57 - (IBAction)checkForUpdates:(id)sender;
58
59 // This kicks off an update meant to be programmatically initiated. That is, it will display no UI unless it actually finds an update,
60 // in which case it proceeds as usual. If the fully automated updating is turned on, however, this will invoke that behavior, and if an
61 // update is found, it will be downloaded and prepped for installation.
62 - (void)checkForUpdatesInBackground;
63
64 // Date of last update check. Returns nil if no check has been performed.
65 - (NSDate*)lastUpdateCheckDate;
66
67 // This begins a "probing" check for updates which will not actually offer to update to that version. The delegate methods, though,
68 // (up to updater:didFindValidUpdate: and updaterDidNotFindUpdate:), are called, so you can use that information in your UI.
69 - (void)checkForUpdateInformation;
70
71 // Call this to appropriately schedule or cancel the update checking timer according to the preferences for time interval and automatic checks. This call does not change the date of the next check, but only the internal NSTimer.
72 - (void)resetUpdateCycle;
73
74 - (BOOL)updateInProgress;
75
76 @end
77
78
79 // -----------------------------------------------------------------------------
80 // SUUpdater Delegate:
81 // -----------------------------------------------------------------------------
82
83 @interface NSObject (SUUpdaterDelegateInformalProtocol)
84
85 // Use this to keep Sparkle from popping up e.g. while your setup assistant is showing:
86 - (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle;
87
88 // This method allows you to add extra parameters to the appcast URL, potentially based on whether or not Sparkle will also be sending along the system profile. This method should return an array of dictionaries with keys: "key", "value", "displayKey", "displayValue", the latter two being specifically for display to the user.
89 - (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile;
90
91 // Override this to dynamically specify the entire URL.
92 - (NSString*)feedURLStringForUpdater:(SUUpdater*)updater;
93
94 // Use this to override the default behavior for Sparkle prompting the user about automatic update checks.
95 - (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SUUpdater *)bundle;
96
97 // Implement this if you want to do some special handling with the appcast once it finishes loading.
98 - (void)updater:(SUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast;
99
100 // If you're using special logic or extensions in your appcast, implement this to use your own logic for finding
101 // a valid update, if any, in the given appcast.
102 - (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)bundle;
103
104 // Sent when a valid update is found by the update driver.
105 - (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update;
106
107 // Sent when a valid update is not found.
108 - (void)updaterDidNotFindUpdate:(SUUpdater *)update;
109
110 // Sent immediately before installing the specified update.
111 - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update;
112
113 // Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue.
114 // This is not called if the user didn't relaunch on the previous update, in that case it will immediately
115 // restart.
116 - (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation;
117
118 // Some apps *can not* be relaunched in certain circumstances. They can use this method
119 // to prevent a relaunch "hard":
120 - (BOOL)updaterShouldRelaunchApplication:(SUUpdater *)updater;
121
122 // Called immediately before relaunching.
123 - (void)updaterWillRelaunchApplication:(SUUpdater *)updater;
124
125 // This method allows you to provide a custom version comparator.
126 // If you don't implement this method or return nil, the standard version comparator will be used.
127 - (id <SUVersionComparison>)versionComparatorForUpdater:(SUUpdater *)updater;
128
129 // This method allows you to provide a custom version comparator.
130 // If you don't implement this method or return nil, the standard version displayer will be used.
131 - (id <SUVersionDisplay>)versionDisplayerForUpdater:(SUUpdater *)updater;
132
133 // Returns the path which is used to relaunch the client after the update is installed. By default, the path of the host bundle.
134 - (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater;
135
136 // Called before and after, respectively, an updater shows a modal alert window, to give the host
137 // the opportunity to hide attached windows etc. that may get in the way:
138 -(void) updaterWillShowModalAlert:(SUUpdater *)updater;
139 -(void) updaterDidShowModalAlert:(SUUpdater *)updater;
140
141 @end
142
143
144 // -----------------------------------------------------------------------------
145 // Constants:
146 // -----------------------------------------------------------------------------
147
148 // Define some minimum intervals to avoid DOS-like checking attacks. These are in seconds.
149 #if defined(DEBUG) && DEBUG && 0
150 #define SU_MIN_CHECK_INTERVAL 60
151 #else
152 #define SU_MIN_CHECK_INTERVAL 60*60
153 #endif
154
155 #if defined(DEBUG) && DEBUG && 0
156 #define SU_DEFAULT_CHECK_INTERVAL 60
157 #else
158 #define SU_DEFAULT_CHECK_INTERVAL 60*60*24
159 #endif
160
161 #endif