[sparkleplus commit] r107 - in trunk: . Test Application

2 views
Skip to first unread message

codesite...@google.com

unread,
Jan 4, 2008, 4:06:50 PM1/4/08
to spark...@googlegroups.com
Author: atomicbird
Date: Fri Jan 4 13:06:12 2008
New Revision: 107

Modified:
trunk/SUConstants.h
trunk/SUConstants.m
trunk/SUUpdater.h
trunk/SUUpdater.m
trunk/Test Application/Test Application-Info.plist

Log:
Add optional wait-for-idle-time feature, thanks to code from Paul Kim.

With this feature developers can optionally configure Sparkle so that it
will not present update notification dialogs unless the user has been idle
for a configurable number of seconds.

The test application's Info.plist demonstrates the minimum necessary to
activate this-- adding SUDelayAlertUntilSystemIdle with a true value.
Default idle times are at least 300 seconds idle time before notifying the
user, and a "force" threshold of 3600 seconds after which notifications are
shown regardless of idle time. These times can also be configured-- see
code for details.

By default this feature is not active, so the default Sparkle behavior is
not changed.


Modified: trunk/SUConstants.h
==============================================================================
--- trunk/SUConstants.h (original)
+++ trunk/SUConstants.h Fri Jan 4 13:06:12 2008
@@ -21,3 +21,7 @@
extern NSString *SUPublicDSAKeyKey;
extern NSString *SUAutomaticallyUpdateKey;
extern NSString *SUAllowsAutomaticUpdatesKey;
+
+extern NSString *SUDelayAlertUntilSystemIdle;
+extern NSString *SUAlertIdleDelay;
+extern NSString *SUForceAlertThreshold;

Modified: trunk/SUConstants.m
==============================================================================
--- trunk/SUConstants.m (original)
+++ trunk/SUConstants.m Fri Jan 4 13:06:12 2008
@@ -20,4 +20,8 @@
NSString *SUExpectsDSASignatureKey = @"SUExpectsDSASignature";
NSString *SUPublicDSAKeyKey = @"SUPublicDSAKey";
NSString *SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate";
-NSString *SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates";
\ No newline at end of file
+NSString *SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates";
+
+NSString *SUDelayAlertUntilSystemIdle = @"SUDelayAlertUntilSystemIdle";
+NSString *SUAlertIdleDelay = @"SUAlertIdleDelay";
+NSString *SUForceAlertThreshold = @"SUForceAlertThreshold";

Modified: trunk/SUUpdater.h
==============================================================================
--- trunk/SUUpdater.h (original)
+++ trunk/SUUpdater.h Fri Jan 4 13:06:12 2008
@@ -43,6 +43,8 @@
IBOutlet NSButton *profileMoreInfoButton;
IBOutlet NSTextField *checkForUpdatesText;
BOOL moreInfoVisible;
+
+ NSTimer *idleAlertTimer;
}

// This IBAction is meant for a main menu item. Hook up any menu item
to this action,

Modified: trunk/SUUpdater.m
==============================================================================
--- trunk/SUUpdater.m (original)
+++ trunk/SUUpdater.m Fri Jan 4 13:06:12 2008
@@ -491,8 +491,80 @@
}
}

+CG_EXTERN CFTimeInterval CGEventSourceSecondsSinceLastEventType(
CGEventSourceStateID source, CGEventType eventType ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
+
+#define DEFAULT_ALERT_IDLE_DELAY 300
+#define DEFAULT_FORCE_ALERT_THRESHOLD 3600
+
- (void)showUpdatePanel
{
+ NSNumber *delayAlerts;
+
+ delayAlerts = [[NSUserDefaults standardUserDefaults] objectForKey:SUDelayAlertUntilSystemIdle];
+ if (delayAlerts == nil)
+ {
+ delayAlerts = SUInfoValueForKey(SUDelayAlertUntilSystemIdle);
+ }
+
+ // If not done in response to a user action (menu item) and the
function exists (10.4+)... The whole point of
+ // this code is to not bug the user with the alert unless they've
been idle. Makes it less likely it will
+ // disturb them while they are typing or somesuch.
+ if ([delayAlerts boolValue] && !verbose &&
(CGEventSourceSecondsSinceLastEventType != NULL))
+ {
+ NSDate *lastCheck = [[NSUserDefaults standardUserDefaults] objectForKey:SULastCheckTimeKey];
+ NSNumber *value;
+ NSTimeInterval forceThreshold;
+
+ value = [[NSUserDefaults standardUserDefaults] objectForKey:SUForceAlertThreshold];
+ if (value == nil)
+ {
+ value = SUInfoValueForKey(SUForceAlertThreshold);
+ }
+ if (value != nil)
+ {
+ forceThreshold = [value doubleValue];
+ }
+ else
+ {
+ forceThreshold = DEFAULT_FORCE_ALERT_THRESHOLD;
+ }
+
+ // After the threshold, we force display of the panel.
+ if ([[NSDate date] timeIntervalSinceDate:lastCheck] < forceThreshold)
+ {
+ CFTimeInterval idleTime, idleLimit;
+
+ value = [[NSUserDefaults standardUserDefaults] objectForKey:SUAlertIdleDelay];
+ if (value == nil)
+ {
+ value = SUInfoValueForKey(SUAlertIdleDelay);
+ }
+ if (value != nil)
+ {
+ idleLimit = [value doubleValue];
+ }
+ else
+ {
+ idleLimit = DEFAULT_ALERT_IDLE_DELAY;
+ }
+
+ idleTime =
CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);
+
+ if (idleTime < idleLimit)
+ {
+ // Not idle for long enough. Set a timer and check back later
+ idleAlertTimer = [NSTimer
scheduledTimerWithTimeInterval:(idleLimit - idleTime) target:self
selector:@selector(showUpdatePanel) userInfo:nil repeats:NO];
+ return;
+ }
+ }
+ }
+ if (idleAlertTimer != nil)
+ {
+ // Cancel the timer to prevent a double-alert in the case where the
user does a manual check in the interim.
+ [idleAlertTimer invalidate];
+ idleAlertTimer = nil;
+ }
+
updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem];
[updateAlert setDelegate:self];
[updateAlert showWindow:self];

Modified: trunk/Test Application/Test Application-Info.plist
==============================================================================
--- trunk/Test Application/Test Application-Info.plist (original)
+++ trunk/Test Application/Test Application-Info.plist Fri Jan 4
13:06:12 2008
@@ -24,5 +24,7 @@
<string>NSApplication</string>
<key>SUFeedURL</key>
<string>http://sparkleplus.googlecode.com/svn/trunk/sparkletestcast.xml</string>
+ <key>SUDelayAlertUntilSystemIdle</key>
+ <true/>
</dict>
</plist>

Reply all
Reply to author
Forward
0 new messages