From 95032a5a1a28ef8dafb923ca720d10f1d753d902 Mon Sep 17 00:00:00 2001 From: Peter Hajas Date: Tue, 10 May 2011 13:11:06 -0400 Subject: [PATCH] Automatically dismiss alerts when you start the application that threw them. --- MNAlertManager.h | 1 + MNAlertManager.m | 21 +++++++++++++++++++++ Tweak.xm | 20 +++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/MNAlertManager.h b/MNAlertManager.h index 22361b9..1c05270 100644 --- a/MNAlertManager.h +++ b/MNAlertManager.h @@ -87,6 +87,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -(void)reloadPreferences; -(void)refreshAll; -(void)removeAllPendingAlertsWithSender:(NSString *)sender; +-(void)removeAllPendingAlertsForBundleIdentifier:(NSString *)bundleID; -(void)takeActionOnAlertWithData:(MNAlertData *)data; -(void)clearPending; -(void)alertShouldGoLaterTimerFired:(id)sender; diff --git a/MNAlertManager.m b/MNAlertManager.m index 88bed23..3630960 100644 --- a/MNAlertManager.m +++ b/MNAlertManager.m @@ -288,6 +288,27 @@ -(void)removeAllPendingAlertsWithSender:(NSString *)sender [self refreshAll]; } +-(void)removeAllPendingAlertsForBundleIdentifier:(NSString *)bundleID +{ + // Loop through all pending alerts, and remove + // all the ones that are from the bundle identifier + NSMutableArray *toRemove = [NSMutableArray array]; + + for (MNAlertData* dataObj in pendingAlerts) + { + if ([dataObj.bundleID isEqualToString:bundleID]) + { + [dismissedAlerts addObject:dataObj]; + [toRemove addObject:dataObj]; + } + } + + [pendingAlerts removeObjectsInArray:toRemove]; + + [self saveOut]; + [self refreshAll]; +} + -(void)refreshAll { [dashboard refresh]; diff --git a/Tweak.xm b/Tweak.xm index a563f98..1c99929 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -544,7 +544,25 @@ PHACInterface *phacinterface; %end -// ---------------------------- +// ------------------------------ +// Hook SBApplication to dismiss +// alerts automatically on launch +// ------------------------------ + +%hook SBApplication + +-(void)launch +{ + [manager removeAllPendingAlertsForBundleIdentifier:[self bundleIdentifier]]; +} + +-(void)activate +{ + [manager removeAllPendingAlertsForBundleIdentifier:[self bundleIdentifier]]; +} + +%end + // Hook AutoFetchRequestPrivate // for getting new mail // ----------------------------