Adding option to hide status icon on MacOS. See #95
This commit is contained in:
parent
72f34b401b
commit
4adedbae43
|
@ -24,6 +24,7 @@
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||||
{
|
{
|
||||||
// Setup status icon
|
// Setup status icon
|
||||||
|
if (show_icon) {
|
||||||
myStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
|
myStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
|
||||||
|
|
||||||
NSString *nsIconPath = [NSString stringWithUTF8String:icon_path];
|
NSString *nsIconPath = [NSString stringWithUTF8String:icon_path];
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
[myStatusItem setHighlightMode:YES];
|
[myStatusItem setHighlightMode:YES];
|
||||||
[myStatusItem.button setAction:@selector(statusIconClick:)];
|
[myStatusItem.button setAction:@selector(statusIconClick:)];
|
||||||
[myStatusItem.button setTarget:self];
|
[myStatusItem.button setTarget:self];
|
||||||
|
}
|
||||||
|
|
||||||
// Setup key listener
|
// Setup key listener
|
||||||
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSEventMaskKeyDown | NSEventMaskFlagsChanged | NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown)
|
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSEventMaskKeyDown | NSEventMaskFlagsChanged | NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown)
|
||||||
|
|
|
@ -26,11 +26,12 @@ extern "C" {
|
||||||
|
|
||||||
extern void * context_instance;
|
extern void * context_instance;
|
||||||
extern char * icon_path;
|
extern char * icon_path;
|
||||||
|
extern int32_t show_icon;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the AppDelegate and check for accessibility permissions
|
* Initialize the AppDelegate and check for accessibility permissions
|
||||||
*/
|
*/
|
||||||
int32_t initialize(void * context, const char * icon_path);
|
int32_t initialize(void * context, const char * icon_path, int32_t show_icon);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start the event loop indefinitely. Blocking call.
|
* Start the event loop indefinitely. Blocking call.
|
||||||
|
|
|
@ -33,15 +33,17 @@ extern "C" {
|
||||||
|
|
||||||
void * context_instance;
|
void * context_instance;
|
||||||
char * icon_path;
|
char * icon_path;
|
||||||
|
int32_t show_icon;
|
||||||
AppDelegate * delegate_ptr;
|
AppDelegate * delegate_ptr;
|
||||||
|
|
||||||
KeypressCallback keypress_callback;
|
KeypressCallback keypress_callback;
|
||||||
IconClickCallback icon_click_callback;
|
IconClickCallback icon_click_callback;
|
||||||
ContextMenuClickCallback context_menu_click_callback;
|
ContextMenuClickCallback context_menu_click_callback;
|
||||||
|
|
||||||
int32_t initialize(void * context, const char * _icon_path) {
|
int32_t initialize(void * context, const char * _icon_path, int32_t _show_icon) {
|
||||||
context_instance = context;
|
context_instance = context;
|
||||||
icon_path = strdup(_icon_path);
|
icon_path = strdup(_icon_path);
|
||||||
|
show_icon = _show_icon;
|
||||||
|
|
||||||
AppDelegate *delegate = [[AppDelegate alloc] init];
|
AppDelegate *delegate = [[AppDelegate alloc] init];
|
||||||
delegate_ptr = delegate;
|
delegate_ptr = delegate;
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub struct MacMenuItem {
|
||||||
#[allow(improper_ctypes)]
|
#[allow(improper_ctypes)]
|
||||||
#[link(name="macbridge", kind="static")]
|
#[link(name="macbridge", kind="static")]
|
||||||
extern {
|
extern {
|
||||||
pub fn initialize(s: *const c_void, icon_path: *const c_char);
|
pub fn initialize(s: *const c_void, icon_path: *const c_char, show_icon: i32);
|
||||||
pub fn eventloop();
|
pub fn eventloop();
|
||||||
pub fn headless_eventloop();
|
pub fn headless_eventloop();
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,13 @@ impl MacContext {
|
||||||
register_context_menu_click_callback(context_menu_click_callback);
|
register_context_menu_click_callback(context_menu_click_callback);
|
||||||
|
|
||||||
let status_icon_path = CString::new(status_icon_target.to_str().unwrap_or_default()).unwrap_or_default();
|
let status_icon_path = CString::new(status_icon_target.to_str().unwrap_or_default()).unwrap_or_default();
|
||||||
initialize(context_ptr, status_icon_path.as_ptr());
|
let show_icon = if config.show_icon {
|
||||||
|
1
|
||||||
|
}else{
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
initialize(context_ptr, status_icon_path.as_ptr(), show_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
context
|
context
|
||||||
|
|
Loading…
Reference in New Issue
Block a user