Make the handling of charging changes more sane:
authorPeter Hosey
Tue May 05 00:50:25 2009 -0700 (2009-05-05)
changeset 4205f3398597ecdd
parent 4204 2564276c9d5c
child 4206 3d99d21e344a
Make the handling of charging changes more sane:
1. Allow multiple notifications for the same power source (namely, the AC adapter) if the charging state changes.
2. We now use coalesce notifications on the title of the notification, so the AC-adapter notification only appears once, with the charging or not-charging notification replacing the previous not-charging or charging notification. Consecutive notifications with the same charging state remain suppressed.
Extras/HardwareGrowler/AppController.m
Extras/HardwareGrowler/PowerNotifier.c
     1.1 --- a/Extras/HardwareGrowler/AppController.m	Tue May 05 00:40:54 2009 -0700
     1.2 +++ b/Extras/HardwareGrowler/AppController.m	Tue May 05 00:50:25 2009 -0700
     1.3 @@ -582,7 +582,8 @@
     1.4  									   iconData:(NSData *)imageData
     1.5  									   priority:0
     1.6  									   isSticky:NO
     1.7 -								   clickContext:nil];
     1.8 +								   clickContext:nil
     1.9 +									 identifier:title];
    1.10  }
    1.11  
    1.12  static void powerCallback(void *refcon, io_service_t service, natural_t messageType, void *messageArgument) {
     2.1 --- a/Extras/HardwareGrowler/PowerNotifier.c	Tue May 05 00:40:54 2009 -0700
     2.2 +++ b/Extras/HardwareGrowler/PowerNotifier.c	Tue May 05 00:50:25 2009 -0700
     2.3 @@ -17,6 +17,8 @@
     2.4  
     2.5  static CFRunLoopSourceRef powerNotifierRunLoopSource = NULL;
     2.6  static HGPowerSource lastPowerSource;
     2.7 +static CFBooleanRef lastChargingState;
     2.8 +static int lastBatteryTime = -1;
     2.9  
    2.10  static bool stringsAreEqual(CFStringRef a, CFStringRef b)
    2.11  {
    2.12 @@ -95,9 +97,11 @@
    2.13  			hgPowerSource = HGUPSPower;
    2.14  		}
    2.15  
    2.16 -		//Avoid sending notifications on the same power source multiple times
    2.17 -		if (lastPowerSource != hgPowerSource) {
    2.18 +		//Avoid sending notifications on the same power source multiple times, unless the charging state or presence/absence of a time estimate has changed.
    2.19 +		if (lastPowerSource != hgPowerSource || lastChargingState != charging || (lastBatteryTime == -1) != (batteryTime == -1)) {
    2.20  			lastPowerSource = hgPowerSource;
    2.21 +			lastChargingState = charging;
    2.22 +			lastBatteryTime = batteryTime;
    2.23  			AppController_powerSwitched(hgPowerSource, charging, batteryTime, percentageCapacity);
    2.24  		}
    2.25  	}