Skip to content

Commit 91a8fa8

Browse files
committed
[Feature] Added failure only notifications
1 parent 0de8340 commit 91a8fa8

File tree

7 files changed

+329
-20
lines changed

7 files changed

+329
-20
lines changed

resources/English.lproj/MainMenu.xib

Lines changed: 273 additions & 19 deletions
Large diffs are not rendered by default.

src/AppDelegate.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ - (IBAction)showPreferences:(id)sender {
6767
}
6868

6969
- (BOOL)shouldShowNotificationFor:(TravisEvent *)eventData {
70+
if ([[Preferences sharedPreferences] failureOnlyNotificationEnabled]) {
71+
if (eventData.status != TravisEventStatusFailed) {
72+
return FALSE;
73+
}
74+
}
75+
7076
RepositoryFilter *filter;
7177
if ([[Preferences sharedPreferences] firehoseEnabled]) {
7278
filter = [RepositoryFilter filterThatAcceptsAllRepositories];
@@ -94,9 +100,14 @@ - (void)eventFetcher:(TravisEventFetcher *)eventFetcher gotEvent:(TravisEvent *)
94100
#pragma mark - NSUserNotificationCenterDelegate
95101

96102
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
97-
if ([notification activationType] == NSUserNotificationActivationTypeContentsClicked) {
103+
if ([notification activationType] == NSUserNotificationActivationTypeContentsClicked || [notification activationType] == NSUserNotificationActivationTypeActionButtonClicked) {
98104
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[notification userInfo][@"URL"]]];
99105
}
100106
}
101107

108+
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
109+
// Show notifications when the Preferences panel is visible.
110+
return TRUE;
111+
}
112+
102113
@end

src/Preferences.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@
2121
- (BOOL)firehoseEnabled;
2222
- (void)setFirehoseEnabled:(BOOL)firehoseEnabled;
2323

24+
- (BOOL)failureOnlyNotificationEnabled;
25+
- (void)setFailureOnlyNotificationEnabled:(BOOL)failuresOnlyNotificationsEnabled;
26+
2427
@end

src/Preferences.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
static NSString * const kRepositoriesSetting = @"repositories";
1212
static NSString * const kFirehoseSetting = @"firehose";
13+
static NSString * const kFailuresOnlyNotificationsEnabled = @"failuresOnly";
1314

1415
@implementation Preferences
1516

@@ -66,4 +67,15 @@ - (void)setFirehoseEnabled:(BOOL)firehoseEnabled {
6667
[userDefaults synchronize];
6768
}
6869

70+
- (BOOL)failureOnlyNotificationEnabled {
71+
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
72+
return [userDefaults boolForKey:kFailuresOnlyNotificationsEnabled];
73+
}
74+
75+
- (void)setFailureOnlyNotificationEnabled:(BOOL)failureOnlyNotificationEnabled {
76+
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
77+
[userDefaults setBool:failureOnlyNotificationEnabled forKey:kFailuresOnlyNotificationsEnabled];
78+
[userDefaults synchronize];
79+
}
80+
6981
@end

src/PreferencesController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
@property (assign) IBOutlet NSPanel *preferencesPanel;
1919
@property (weak) IBOutlet NSButtonCell *firehoseEnabledButtonCell;
2020
@property (weak) IBOutlet NSButtonCell *firehoseDisabledButtonCell;
21+
@property (weak) IBOutlet NSButtonCell *failureOnlyNotificationEnabledButtonCell;
22+
@property (weak) IBOutlet NSButtonCell *failureOnlyNotificationDisabledButtonCell;
2123

2224
- (IBAction)addRepository:(id)sender;
2325
- (IBAction)removeRepository:(id)sender;
2426
- (IBAction)enableFirehose:(id)sender;
2527
- (IBAction)disableFirehose:(id)sender;
28+
- (IBAction)enableFailureOnlyNotification:(id)sender;
29+
- (IBAction)disableFailureOnlyNotification:(id)sender;
2630
- (IBAction)close:(id)sender;
2731

2832
@end

src/PreferencesController.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ - (IBAction)disableFirehose:(id)sender {
5656
[[self preferences] setFirehoseEnabled:NO];
5757
}
5858

59+
- (IBAction)enableFailureOnlyNotification:(id)sender {
60+
[[self preferences] setFailureOnlyNotificationEnabled:YES];
61+
}
62+
63+
- (IBAction)disableFailureOnlyNotification:(id)sender {
64+
[[self preferences] setFailureOnlyNotificationEnabled:NO];
65+
}
66+
5967
#pragma mark - NSWindowDelegate
6068

6169
- (void)windowDidBecomeKey:(NSNotification *)notification {
@@ -66,6 +74,13 @@ - (void)windowDidBecomeKey:(NSNotification *)notification {
6674
[[self firehoseEnabledButtonCell] setObjectValue:@(NO)];
6775
[[self firehoseDisabledButtonCell] setObjectValue:@(YES)];
6876
}
77+
if ([[self preferences] failureOnlyNotificationEnabled]) {
78+
[[self failureOnlyNotificationEnabledButtonCell] setObjectValue:@(YES)];
79+
[[self failureOnlyNotificationDisabledButtonCell] setObjectValue:@(NO)];
80+
} else {
81+
[[self failureOnlyNotificationEnabledButtonCell] setObjectValue:@(NO)];
82+
[[self failureOnlyNotificationDisabledButtonCell] setObjectValue:@(YES)];
83+
}
6984
}
7085

7186
#pragma mark - NSTableViewDataSource

test/PreferencesControllerTests.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ - (void)testDisableFirehoseSetting {
4141
[verify(_preferences) setFirehoseEnabled:NO];
4242
}
4343

44+
- (void)testEnableFailureOnlyNotificationSetting {
45+
[_preferencesController enableFailureOnlyNotification:nil];
46+
[verify(_preferences) setFailureOnlyNotificationEnabled:YES];
47+
}
48+
49+
- (void)testDisableFailureOnlyNotificationSetting {
50+
[_preferencesController disableFailureOnlyNotification:nil];
51+
[verify(_preferences) setFailureOnlyNotificationEnabled:NO];
52+
}
53+
4454
@end

0 commit comments

Comments
 (0)