3131#import " SCSettings.h"
3232#import < ServiceManagement/ServiceManagement.h>
3333#import " SCXPCClient.h"
34- #import " SCConstants.h"
35- #import " version-header.h"
34+ #import < Sentry/Sentry.h>
3635
3736@interface AppController () {}
3837
@@ -50,15 +49,7 @@ - (AppController*) init {
5049 if (self = [super init ]) {
5150
5251 defaults_ = [NSUserDefaults standardUserDefaults ];
53- settings_ = [SCSettings sharedSettings ];
54-
5552 [defaults_ registerDefaults: SCConstants.defaultUserDefaults];
56-
57- // go copy over any preferences from legacy setting locations
58- // (we won't clear any old data yet - we leave that to the daemon)
59- if ([SCUtilities legacySettingsFound ]) {
60- [SCUtilities copyLegacySettingsToDefaults ];
61- }
6253
6354 self.addingBlock = false ;
6455
@@ -122,6 +113,7 @@ - (IBAction)addBlock:(id)sender {
122113 if ([self blockIsRunning ]) {
123114 // This method shouldn't be getting called, a block is on so the Start button should be disabled.
124115 NSError * err = [SCErr errorWithCode: 104 ];
116+ [SCSentry captureError: err];
125117 [NSApp presentError: err];
126118 return ;
127119 }
@@ -130,7 +122,7 @@ - (IBAction)addBlock:(id)sender {
130122 // this should definitely not be happening. Exit.
131123
132124 NSError * err = [SCErr errorWithCode: 101 ];
133-
125+ [SCSentry captureError: err];
134126 [NSApp presentError: err];
135127
136128 return ;
@@ -171,7 +163,7 @@ - (void)refreshUserInterface {
171163 // already refreshing the UI, no need to wait and do it again
172164 return ;
173165 }
174-
166+
175167 BOOL blockWasOn = blockIsOn;
176168 blockIsOn = [self blockIsRunning ];
177169
@@ -254,6 +246,7 @@ - (void)refreshUserInterface {
254246}
255247
256248- (void )handleConfigurationChangedNotification {
249+ [SCSentry addBreadcrumb: @" Received configuration changed notification" category: @" app" ];
257250 // if our configuration changed, we should assume the settings may have changed
258251 [[SCSettings sharedSettings ] reloadSettings ];
259252 // and our interface may need to change to match!
@@ -275,6 +268,7 @@ - (void)closeTimerWindow {
275268}
276269
277270- (IBAction )openPreferences : (id )sender {
271+ [SCSentry addBreadcrumb: @" Opening preferences window" category: @" app" ];
278272 if (preferencesWindowController_ == nil ) {
279273 NSViewController * generalViewController = [[PreferencesGeneralViewController alloc ] init ];
280274 NSViewController * advancedViewController = [[PreferencesAdvancedViewController alloc ] init ];
@@ -286,6 +280,7 @@ - (IBAction)openPreferences:(id)sender {
286280}
287281
288282- (IBAction )showGetStartedWindow : (id )sender {
283+ [SCSentry addBreadcrumb: @" Showing \" Get Started\" window" category: @" app" ];
289284 if (!getStartedWindowController) {
290285 getStartedWindowController = [[NSWindowController alloc ] initWithWindowNibName: @" FirstTime" ];
291286 }
@@ -304,6 +299,15 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification {
304299- (void )applicationDidFinishLaunching : (NSNotification *)aNotification {
305300 [NSApplication sharedApplication ].delegate = self;
306301
302+ [SCSentry startSentry: @" org.eyebeam.SelfControl" ];
303+
304+ settings_ = [SCSettings sharedSettings ];
305+ // go copy over any preferences from legacy setting locations
306+ // (we won't clear any old data yet - we leave that to the daemon)
307+ if ([SCUtilities legacySettingsFound ]) {
308+ [SCUtilities copyLegacySettingsToDefaults ];
309+ }
310+
307311 // start up our daemon XPC
308312 self.xpc = [SCXPCClient new ];
309313 [self .xpc connectToHelperTool ];
@@ -324,8 +328,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
324328 if (error == nil ) {
325329 if ([SELFCONTROL_VERSION_STRING compare: daemonVersion options: NSNumericSearch] == NSOrderedDescending) {
326330 NSLog (@" Daemon version of %@ is out of date (current version is %@ )." , daemonVersion, SELFCONTROL_VERSION_STRING);
331+ [SCSentry addBreadcrumb: @" Detected out-of-date daemon" category: @" app" ];
327332 [self reinstallDaemon ];
328333 } else {
334+ [SCSentry addBreadcrumb: @" Detected up-to-date daemon" category: @" app" ];
329335 NSLog (@" Daemon version of %@ is up-to-date!" , daemonVersion);
330336 }
331337 } else {
@@ -370,10 +376,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
370376
371377 [self refreshUserInterface ];
372378
373- NSOperatingSystemVersion minRequiredVersion = (NSOperatingSystemVersion ){10 ,8 ,0 }; // Mountain Lion
374- NSString * minRequiredVersionString = @" 10.8 (Mountain Lion )" ;
379+ NSOperatingSystemVersion minRequiredVersion = (NSOperatingSystemVersion ){10 ,10 ,0 }; // Mountain Lion
380+ NSString * minRequiredVersionString = @" 10.10 (Yosemite )" ;
375381 if (![[NSProcessInfo processInfo ] isOperatingSystemAtLeastVersion: minRequiredVersion]) {
376382 NSLog (@" ERROR: Unsupported version for SelfControl" );
383+ [SCSentry captureMessage: @" Unsupported operating system version" ];
377384 NSAlert * unsupportedVersionAlert = [[NSAlert alloc ] init ];
378385 [unsupportedVersionAlert setMessageText: NSLocalizedString(@" Unsupported version" , nil )];
379386 [unsupportedVersionAlert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@" This version of SelfControl only supports Mac OS X version %@ or higher. To download a version for older operating systems, please go to www.selfcontrolapp.com" , nil ), minRequiredVersionString]];
@@ -388,9 +395,11 @@ - (void)applicationWillTerminate:(NSNotification *)notification {
388395
389396- (void )reinstallDaemon {
390397 NSLog (@" Attempting to reinstall daemon..." );
398+ [SCSentry addBreadcrumb: @" Reinstalling daemon" category: @" app" ];
391399 [self .xpc installDaemon: ^(NSError * _Nonnull error) {
392400 if (error == nil ) {
393401 NSLog (@" Reinstalled daemon successfully!" );
402+ [SCSentry addBreadcrumb: @" Daemon reinstalled successfully" category: @" app" ];
394403
395404 NSLog (@" Retrying helper tool connection..." );
396405 [self .xpc performSelectorOnMainThread: @selector (connectToHelperTool ) withObject: nil waitUntilDone: YES ];
@@ -406,6 +415,7 @@ - (BOOL)blockIsRunning {
406415}
407416
408417- (IBAction )showDomainList : (id )sender {
418+ [SCSentry addBreadcrumb: @" Showing domain list" category: @" app" ];
409419 if ([self blockIsRunning ] || self.addingBlock ) {
410420 NSAlert * blockInProgressAlert = [[NSAlert alloc ] init ];
411421 [blockInProgressAlert setMessageText: NSLocalizedString(@" Block in progress" , @" Block in progress error title" )];
@@ -474,7 +484,7 @@ - (void)addToBlockList:(NSString*)host lock:(NSLock*)lock {
474484 [self refreshUserInterface ];
475485
476486 NSError * err = [SCErr errorWithCode: 102 ];
477-
487+ [SCSentry captureError: err];
478488 [NSApp presentError: err];
479489
480490 return ;
@@ -518,7 +528,7 @@ - (void)extendBlockTime:(NSInteger)minutesToAdd lock:(NSLock*)lock {
518528 [self refreshUserInterface ];
519529
520530 NSError * err = [SCErr errorWithCode: 103 ];
521-
531+ [SCSentry captureError: err];
522532 [NSApp presentError: err];
523533
524534 return ;
@@ -555,6 +565,7 @@ - (void)setDomainListWindowController:(id)newController {
555565}
556566
557567- (void )installBlock {
568+ [SCSentry addBreadcrumb: @" App running installBlock method" category: @" app" ];
558569 @autoreleasepool {
559570 self.addingBlock = true ;
560571 [self refreshUserInterface ];
@@ -567,6 +578,7 @@ - (void)installBlock {
567578 [self refreshUserInterface ];
568579 return ;
569580 } else {
581+ [SCSentry addBreadcrumb: @" Daemon installed successfully (en route to installing block)" category: @" app" ];
570582 // helper tool installed successfully, let's prepare to start the block!
571583 // for legacy reasons, BlockDuration is in minutes, so convert it to seconds before passing it through]
572584 // sanity check duration (must be above zero)
@@ -590,14 +602,17 @@ - (void)installBlock {
590602 @" EvaluateCommonSubdomains" : [self ->defaults_ valueForKey: @" EvaluateCommonSubdomains" ],
591603 @" IncludeLinkedDomains" : [self ->defaults_ valueForKey: @" IncludeLinkedDomains" ],
592604 @" BlockSoundShouldPlay" : [self ->defaults_ valueForKey: @" BlockSoundShouldPlay" ],
593- @" BlockSound" : [self ->defaults_ valueForKey: @" BlockSound" ]
605+ @" BlockSound" : [self ->defaults_ valueForKey: @" BlockSound" ],
606+ @" EnableErrorReporting" : [self ->defaults_ valueForKey: @" EnableErrorReporting" ]
594607 }
595608 reply: ^(NSError * _Nonnull error) {
596609 NSLog (@" WOO started block with error %@ " , error);
597610 if (error != nil ) {
598611 [NSApp performSelectorOnMainThread: @selector (presentError: )
599612 withObject: error
600613 waitUntilDone: YES ];
614+ } else {
615+ [SCSentry addBreadcrumb: @" Block started successfully" category: @" app" ];
601616 }
602617
603618 // get the new settings
@@ -613,10 +628,11 @@ - (void)installBlock {
613628}
614629
615630- (void )updateActiveBlocklist : (NSLock *)lockToUse {
616- NSLog (@" updateActiveBlocklist" );
617631 if (![lockToUse tryLock ]) {
618632 return ;
619633 }
634+
635+ [SCSentry addBreadcrumb: @" App running updateActiveBlocklist method" category: @" app" ];
620636
621637 // we're about to launch a helper tool which will read settings, so make sure the ones on disk are valid
622638 [settings_ synchronizeSettings ];
@@ -627,14 +643,14 @@ - (void)updateActiveBlocklist:(NSLock*)lockToUse {
627643 [self .xpc updateBlocklistWithControllingUID: getuid ()
628644 newBlocklist: [self ->defaults_ arrayForKey: @" Blocklist" ]
629645 reply: ^(NSError * _Nonnull error) {
630- NSLog (@" WOO updated block with error %@ " , error);
631-
632646 [self ->timerWindowController_ performSelectorOnMainThread: @selector (closeAddSheet: ) withObject: self waitUntilDone: YES ];
633647
634648 if (error != nil ) {
635649 [NSApp performSelectorOnMainThread: @selector (presentError: )
636650 withObject: error
637651 waitUntilDone: YES ];
652+ } else {
653+ [SCSentry addBreadcrumb: @" Blocklist updated successfully" category: @" app" ];
638654 }
639655
640656 [lockToUse unlock ];
@@ -653,10 +669,10 @@ - (void)setDefaultsBlockDurationOnMainThread:(NSNumber*)newBlockDuration {
653669}
654670
655671- (void )updateBlockEndDate : (NSLock *)lockToUse minutesToAdd : (NSInteger )minutesToAdd {
656- NSLog (@" updateBlockEndDate" );
657672 if (![lockToUse tryLock ]) {
658673 return ;
659674 }
675+ [SCSentry addBreadcrumb: @" App running updateBlockEndDate method" category: @" app" ];
660676
661677 minutesToAdd = MAX (minutesToAdd, 0 ); // make sure there's no funny business with negative minutes
662678 NSDate * oldBlockEndDate = [settings_ valueForKey: @" BlockEndDate" ];
@@ -678,8 +694,6 @@ - (void)updateBlockEndDate:(NSLock*)lockToUse minutesToAdd:(NSInteger)minutesToA
678694 [self .xpc updateBlockEndDateWithControllingUID: getuid ()
679695 newEndDate: newBlockEndDate
680696 reply: ^(NSError * _Nonnull error) {
681- NSLog (@" WOO updated block end date with error %@ " , error);
682-
683697 [self ->timerWindowController_ performSelectorOnMainThread: @selector (closeAddSheet: ) withObject: self waitUntilDone: YES ];
684698 // let the timer know it needs to recalculate
685699 [self ->timerWindowController_ performSelectorOnMainThread: @selector (blockEndDateUpdated )
@@ -690,6 +704,8 @@ - (void)updateBlockEndDate:(NSLock*)lockToUse minutesToAdd:(NSInteger)minutesToA
690704 [NSApp performSelectorOnMainThread: @selector (presentError: )
691705 withObject: error
692706 waitUntilDone: YES ];
707+ } else {
708+ [SCSentry addBreadcrumb: @" App extended block duration successfully" category: @" app" ];
693709 }
694710
695711 [lockToUse unlock ];
@@ -721,10 +737,13 @@ - (IBAction)save:(id)sender {
721737
722738 if (errDescription) {
723739 NSError * displayErr = [SCErr errorWithCode: 105 subDescription: errDescription];
740+ [SCSentry captureError: displayErr];
724741 NSBeep ();
725742 [NSApp presentError: displayErr];
726743 return ;
727- }
744+ } else {
745+ [SCSentry addBreadcrumb: @" Saved blocklist to file" category: @" app" ];
746+ }
728747 }
729748}
730749
@@ -741,6 +760,7 @@ - (IBAction)open:(id)sender {
741760 if (settingsFromFile != nil ) {
742761 [defaults_ setObject: settingsFromFile[@" Blocklist" ] forKey: @" Blocklist" ];
743762 [defaults_ setObject: settingsFromFile[@" BlockAsWhitelist" ] forKey: @" BlockAsWhitelist" ];
763+ [SCSentry addBreadcrumb: @" Opened blocklist from file" category: @" app" ];
744764 } else {
745765 NSLog (@" WARNING: Could not read a valid blocklist from file - ignoring." );
746766 }
@@ -782,6 +802,7 @@ - (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)filename
782802}
783803
784804- (IBAction )openFAQ : (id )sender {
805+ [SCSentry addBreadcrumb: @" Opened SelfControl FAQ" category: @" app" ];
785806 NSURL *url=[NSURL URLWithString: @" https://github.com/SelfControlApp/selfcontrol/wiki/FAQ#q-selfcontrols-timer-is-at-0000-and-i-cant-start-a-new-block-and-im-freaking-out" ];
786807 [[NSWorkspace sharedWorkspace ] openURL: url];
787808}
0 commit comments