Commit a7536bc7 authored by David Fuhrmann's avatar David Fuhrmann

macosx: Directly apply visibility change for status bar icon

parent a93f5820
......@@ -51,6 +51,8 @@
intf_thread_t *getIntf();
static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
static NSString * VLCConfigurationChangedNotification = @"VLCConfigurationChangedNotification";
/*****************************************************************************
* VLCMain interface
......
......@@ -90,7 +90,7 @@
- (void)awakeFromNib
{
[super awakeFromNib];
[self enableMenuIcon];
[self configurationChanged:nil];
// Set Accessibility Attributes for Image Buttons
[backwardsButton.cell accessibilitySetOverrideValue:_NS("Go to previous track")
......@@ -122,6 +122,11 @@
selector:@selector(updateNowPlayingInfo)
name:VLCInputChangedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(configurationChanged:)
name:VLCConfigurationChangedNotification
object:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
......@@ -140,35 +145,59 @@
}
}
- (void)configurationChanged:(id)obj
{
if (var_InheritBool(getIntf(), "macosx-statusicon"))
[self enableMenuIcon];
else
[self disableStatusItem];
}
/* Enables the Status Bar Item and initializes it's image
* and context menu
*/
- (void)enableMenuIcon
{
if (!var_InheritBool(getIntf(), "macosx-statusicon"))
return;
// Init the status item
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[self.statusItem setHighlightMode:YES];
[self.statusItem setEnabled:YES];
if (!self.statusItem) {
// Init the status item
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[self.statusItem setHighlightMode:YES];
[self.statusItem setEnabled:YES];
// Set the status item image
NSImage *menuIcon = [NSImage imageNamed:@"VLCStatusBarIcon"];
[menuIcon setTemplate:YES];
[self.statusItem setImage:menuIcon];
// Attach pull-down menu
[self.statusItem setMenu:_vlcStatusBarIconMenu];
if (OSX_SIERRA) {
[self.statusItem setBehavior:NSStatusItemBehaviorRemovalAllowed];
[self.statusItem setAutosaveName:@"statusBarItem"];
[self.statusItem addObserver:self forKeyPath:NSStringFromSelector(@selector(isVisible))
options:0 context:NULL];
}
}
// Sync VLC setting with status bar visibility setting (10.12 runtime only)
if ([self.statusItem respondsToSelector:@selector(isVisible)]) {
[self.statusItem setBehavior:NSStatusItemBehaviorRemovalAllowed];
[self.statusItem setAutosaveName:@"statusBarItem"];
if (OSX_SIERRA) {
// Sync VLC setting with status bar visibility setting (10.12 runtime only)
[self.statusItem setVisible:YES];
[self.statusItem addObserver:self forKeyPath:NSStringFromSelector(@selector(isVisible))
options:0 context:NULL];
}
}
// Set the status item image
NSImage *menuIcon = [NSImage imageNamed:@"VLCStatusBarIcon"];
[menuIcon setTemplate:YES];
[self.statusItem setImage:menuIcon];
- (void)disableStatusItem
{
if (!self.statusItem)
return;
// Attach pull-down menu
[self.statusItem setMenu:_vlcStatusBarIconMenu];
// Lets keep alive the object in Sierra, and destroy it in older OS versions
if (OSX_SIERRA) {
self.statusItem.visible = NO;
} else {
[[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];
self.statusItem = nil;
}
}
- (void)dealloc
......
......@@ -1083,6 +1083,7 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
[[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
object: nil
userInfo: nil];
[[NSNotificationCenter defaultCenter] postNotificationName:VLCConfigurationChangedNotification object:nil];
}
- (void)showSettingsForCategory:(id)new_categoryView
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment