+- (IBAction)toggleActivity:(id)sender {
+ BOOL sendRealEvents = !self.jsController.sendingRealEvents;
+ self.jsController.sendingRealEvents = sendRealEvents;
+ activeButton.image = [NSImage imageNamed:sendRealEvents ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"];
+ activeMenuItem.state = sendRealEvents;
+
+ if (sendRealEvents) {
+ [NSWorkspace.sharedWorkspace.notificationCenter
+ addObserver:self
+ selector:@selector(didSwitchApplication:)
+ name:NSWorkspaceDidActivateApplicationNotification
+ object:nil];
+ NSLog(@"Listening for application changes.");
+ } else {
+ [NSWorkspace.sharedWorkspace.notificationCenter
+ removeObserver:self
+ name:NSWorkspaceDidActivateApplicationNotification
+ object:nil];
+ NSLog(@"Ignoring application changes.");
+ }