improved status bar menu and notifications

camera off notification now includes which camera
device status now (re)enumerated when menu is opened
This commit is contained in:
Patrick Wardle 2023-11-07 17:48:37 -10:00
parent e2396db29c
commit 0c2436afcf
3 changed files with 29 additions and 57 deletions

View File

@ -89,15 +89,6 @@ extern os_log_t logHandle;
//per device events //per device events
self.deviceEvents = [NSMutableDictionary dictionary]; self.deviceEvents = [NSMutableDictionary dictionary];
//enumerate active devices
// then update status menu (on main thread)
dispatch_async(dispatch_get_main_queue(), ^{
//update status menu
[((AppDelegate*)[[NSApplication sharedApplication] delegate]).statusBarItemController setActiveDevices:[self enumerateActiveDevices]];
});
//find built-in mic //find built-in mic
self.builtInMic = [self findBuiltInMic]; self.builtInMic = [self findBuiltInMic];
@ -241,21 +232,6 @@ extern os_log_t logHandle;
return; return;
} }
//(re)enumerate active devices
// delayed need as device deactiavation
// then update status menu (on main thread)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
//update on on main thread
dispatch_async(dispatch_get_main_queue(), ^{
//update status menu
[((AppDelegate*)[[NSApplication sharedApplication] delegate]).statusBarItemController setActiveDevices:[self enumerateActiveDevices]];
});
}); //dispatch for delay
} }
}]; }];
@ -314,21 +290,6 @@ extern os_log_t logHandle;
//save //save
self.lastCameraClient = pid; self.lastCameraClient = pid;
//(re)enumerate active devices
// delayed need as device deactiavation
// then update status menu (on main thread)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
//update on on main thread
dispatch_async(dispatch_get_main_queue(), ^{
//update status menu
[((AppDelegate*)[[NSApplication sharedApplication] delegate]).statusBarItemController setActiveDevices:[self enumerateActiveDevices]];
});
}); //dispatch for delay
} }
}]; }];
@ -495,20 +456,6 @@ extern os_log_t logHandle;
}//sync }//sync
//(re)enumerate active devices
// delayed need as device deactiavation
// then update status menu (on main thread)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
//update on on main thread
dispatch_async(dispatch_get_main_queue(), ^{
//update status menu
[((AppDelegate*)[[NSApplication sharedApplication] delegate]).statusBarItemController setActiveDevices:[self enumerateActiveDevices]];
});
}); //dispatch for delay
}]; }];
} }
@ -914,7 +861,7 @@ bail:
} }
//camera on? //camera on?
// macOS 13.3, use this as trigger // macOS 13.3+, use this as trigger
// older version send event via log monitor // older version send event via log monitor
if (@available(macOS 13.3, *)) { if (@available(macOS 13.3, *)) {
@ -965,7 +912,7 @@ bail:
//init event //init event
// process (client) and device are nil // process (client) and device are nil
event = [[Event alloc] init:nil device:nil deviceType:Device_Camera state:NSControlStateValueOff]; event = [[Event alloc] init:nil device:device deviceType:Device_Camera state:NSControlStateValueOff];
//handle event //handle event
[self handleEvent:event]; [self handleEvent:event];

View File

@ -10,7 +10,7 @@
@import Cocoa; @import Cocoa;
@interface StatusBarItem : NSObject <NSPopoverDelegate> @interface StatusBarItem : NSObject <NSPopoverDelegate, NSMenuDelegate>
{ {
} }

View File

@ -89,6 +89,9 @@ enum menuItems
//set menu //set menu
self.statusItem.menu = menu; self.statusItem.menu = menu;
//set delegate
self.statusItem.menu.delegate = self;
//set action handler for all menu items //set action handler for all menu items
for(int i=toggle; i<end; i++) for(int i=toggle; i<end; i++)
{ {
@ -445,4 +448,26 @@ bail:
return; return;
} }
//menu delegate method
// menu will open: update active devices
-(void)menuWillOpen:(NSMenu *)menu
{
//av monitor
AVMonitor* avMonitor = nil;
//status bar item controller
StatusBarItem* statusBarItemController = nil;
//grab
avMonitor = ((AppDelegate*)[[NSApplication sharedApplication] delegate]).avMonitor;
//grab
statusBarItemController = ((AppDelegate*)[[NSApplication sharedApplication] delegate]).statusBarItemController;
//enumerate and update
[statusBarItemController setActiveDevices:[avMonitor enumerateActiveDevices]];
return;
}
@end @end