From b08263159e2151609138542593dcfdaf5ce05eb5 Mon Sep 17 00:00:00 2001 From: Dzmitry Neviadomski Date: Fri, 19 Feb 2021 01:02:10 +0300 Subject: [PATCH] Show Now Playing bar only when needed. Fixes #101 Fixes #105 --- Application/AppController.h | 10 +-- Application/AppController.m | 89 +++++++++---------- Base.lproj/MainMenu.xib | 20 ++--- Cog.xcodeproj/project.pbxproj | 16 ---- .../PlaybackStatusToHiddenTransformer.swift | 19 ++-- Window/NowPlayingBarController.h | 19 ---- Window/NowPlayingBarController.m | 30 ------- Window/NowPlayingBarController.xib | 34 ------- Window/NowPlayingBarView.h | 16 ---- Window/NowPlayingBarView.m | 87 ------------------ 10 files changed, 69 insertions(+), 271 deletions(-) delete mode 100644 Window/NowPlayingBarController.h delete mode 100644 Window/NowPlayingBarController.m delete mode 100644 Window/NowPlayingBarController.xib delete mode 100644 Window/NowPlayingBarView.h delete mode 100644 Window/NowPlayingBarView.m diff --git a/Application/AppController.h b/Application/AppController.h index 275b7295e..7425f249c 100644 --- a/Application/AppController.h +++ b/Application/AppController.h @@ -2,8 +2,6 @@ #import -#import "NowPlayingBarController.h" - @class FileTreeViewController; @class PlaybackController; @class PlaylistController; @@ -47,8 +45,6 @@ IBOutlet NSWindowController *spotlightWindowController; IBOutlet FileTreeViewController *fileTreeViewController; - - NowPlayingBarController *nowPlaying; AppleRemote *remote; BOOL remoteButtonHeld; /* true as long as the user holds the left,right,plus or minus on the remote control */ @@ -60,6 +56,9 @@ BOOL miniMode; } +@property (strong) IBOutlet NSButton *nowPlayingBar; +@property (nonatomic) BOOL isNowPlayingHidden; + - (IBAction)openURL:(id)sender; - (IBAction)openFiles:(id)sender; @@ -98,9 +97,6 @@ - (void)nodeExpanded:(NSNotification*)notification; - (void)nodeCollapsed:(NSNotification*)notification; -- (void)windowDidEnterFullScreen:(NSNotification *)notification; -- (void)windowDidExitFullScreen:(NSNotification *)notification; - - (IBAction)toggleMiniMode:(id)sender; - (IBAction)toggleToolbarStyle:(id)sender; diff --git a/Application/AppController.m b/Application/AppController.m index 6ad2e4dfb..03f7e592f 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -22,6 +22,16 @@ #import #import "Shortcuts.h" +void* kAppControllerContext = &kAppControllerContext; + + +@interface AppController () + +@property (nonatomic) BOOL isNowPlayingForceShown; + +@end + + @implementation AppController { BOOL _isFullToolbarStyle; } @@ -223,6 +233,23 @@ [outlineView expandItem:pn]; } } + + [self addObserver:self + forKeyPath:@"playbackController.playbackStatus" + options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew + context:kAppControllerContext]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context { + if ([keyPath isEqualToString:@"playbackController.playbackStatus"]) { + NSValueTransformer *transformer = + [NSValueTransformer valueTransformerForName:@"PlaybackStatusToHiddenTransformer"]; + NSNumber *value = [transformer transformedValue:@(playbackController.playbackStatus)]; + self.isNowPlayingHidden = value.boolValue; + } } - (void)nodeExpanded:(NSNotification*)notification @@ -437,56 +464,13 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification { DLog(@"Entering fullscreen"); - if (nil == nowPlaying) - { - nowPlaying = [[NowPlayingBarController alloc] init]; - - NSView *contentView = [mainWindow contentView]; - NSRect contentRect = [contentView frame]; - const NSSize windowSize = [contentView convertSize:[mainWindow frame].size fromView: nil]; - - [contentView addSubview: [nowPlaying view]]; - [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { - [context setDuration:0.25]; - NSRect nowPlayingFrame = [[self->nowPlaying view] frame]; - nowPlayingFrame.size.width = windowSize.width; - [[self->nowPlaying view] setFrame: nowPlayingFrame]; - [[self->nowPlaying view] setFrameOrigin: NSMakePoint(0.0, NSMaxY(contentRect) - nowPlayingFrame.size.height)]; - - NSRect mainViewFrame = [self->mainView frame]; - mainViewFrame.size.height -= nowPlayingFrame.size.height; - [[self->mainView animator] setFrame:mainViewFrame]; - - } completionHandler:^{ - - }]; - - - - [[nowPlaying text] bind:@"value" toObject:currentEntryController withKeyPath:@"content.display" options:nil]; - } + self.isNowPlayingForceShown = YES; } - (void)windowDidExitFullScreen:(NSNotification *)notification { DLog(@"Exiting fullscreen"); - if (nowPlaying) - { - NSRect nowPlayingFrame = [[nowPlaying view] frame]; - NSRect mainViewFrame = [mainView frame]; - mainViewFrame.size.height += nowPlayingFrame.size.height; - //[mainView setFrame:mainViewFrame]; - // [mainView setFrameOrigin:NSMakePoint(0.0, 0.0)]; - - [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { - [context setDuration:0.25]; - [[self->mainView animator] setFrame:mainViewFrame]; - - } completionHandler:^{ - [[self->nowPlaying view] removeFromSuperview]; - self->nowPlaying = nil; - }]; - } + self.isNowPlayingForceShown = NO; } - (void)clickPlay @@ -580,6 +564,8 @@ miniWindow.toolbarStyle = style; } + [self.nowPlayingBar setHidden:full]; + NSWindowTitleVisibility visibility = full ? NSWindowTitleVisible : NSWindowTitleHidden; mainWindow.titleVisibility = visibility; miniWindow.titleVisibility = visibility; @@ -588,4 +574,17 @@ [miniWindow setContentSize:NSMakeSize(miniWindow.frame.size.width, 0)]; } +- (BOOL)isNowPlayingHidden { + if (_isNowPlayingForceShown) { + return NO; + } + return _isNowPlayingHidden; +} + +- (void)setIsNowPlayingForceShown:(BOOL)isNowPlayingForceShown { + [self willChangeValueForKey:@"isNowPlayingHidden"]; + _isNowPlayingForceShown = isNowPlayingForceShown; + [self didChangeValueForKey:@"isNowPlayingHidden"]; +} + @end diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index e367bd946..cce4cee10 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -19,7 +19,7 @@ - + @@ -35,11 +35,7 @@ - - - PlaybackStatusToHiddenTransformer - - + @@ -585,7 +581,7 @@ - +