Fixes for Audio Player in touchbar.

- Removed unused Platform::SetTouchBar.
 - Added rpl::event_stream in Media Player Instance for handle closing player.
 - Fixed hiding of touchbar when last track is ended.
 - Fixed display of time when last track is ended.
 - Slightly refactored.
This commit is contained in:
23rd 2019-05-02 13:00:05 +03:00 committed by John Preston
parent 2b8e76a060
commit 9059b2e617
8 changed files with 27 additions and 41 deletions

View File

@ -490,6 +490,7 @@ bool HandleEvent(not_null<QShortcutEvent*> event) {
void ToggleMediaShortcuts(bool toggled) {
Data.toggleMedia(toggled);
Platform::SetWatchingMediaKeys(toggled);
Media::Player::instance()->playerWidgetToggledNotify(toggled);
}
void ToggleSupportShortcuts(bool toggled) {

View File

@ -146,6 +146,14 @@ public:
rpl::producer<> playlistChanges(AudioMsgId::Type type) const;
void playerWidgetToggledNotify(bool toggled) {
_playerWidgetToggled.fire_copy({toggled});
}
rpl::producer<bool> playerWidgetToggled() const {
return _playerWidgetToggled.events();
}
void documentLoadProgress(DocumentData *document);
void handleLogout();
@ -251,6 +259,7 @@ private:
base::Observable<AudioMsgId::Type> _trackChangedNotifier;
base::Observable<AudioMsgId::Type> _repeatChangedNotifier;
rpl::event_stream<bool> _playerWidgetToggled;
rpl::lifetime _lifetime;
};

View File

@ -167,7 +167,6 @@ Widget::Widget(QWidget *parent) : RpWidget(parent)
});
setType(AudioMsgId::Type::Song);
_playPause->finishTransform();
Platform::SetTouchBar(Platform::TouchBarType::AudioPlayer);
}
void Widget::updateVolumeToggleIcon() {
@ -192,7 +191,6 @@ void Widget::setCloseCallback(Fn<void()> callback) {
}
void Widget::stopAndClose() {
Platform::SetTouchBar(Platform::TouchBarType::None);
_voiceIsActive = false;
if (_type == AudioMsgId::Type::Voice) {
const auto songData = instance()->current(AudioMsgId::Type::Song);

View File

@ -406,10 +406,6 @@ void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCal
void OpenSystemSettingsForPermission(PermissionType type) {
}
void SetTouchBar(TouchBarType type) {
// TouchBar is Mac only feature.
}
bool OpenSystemSettings(SystemSettingsType type) {
if (type == SystemSettingsType::Audio) {
auto options = std::vector<QString>();

View File

@ -225,10 +225,6 @@ void SetApplicationIcon(const QIcon &icon) {
[image release];
}
void SetTouchBar(TouchBarType type) {
}
void InitOnTopPanel(QWidget *panel) {
Expects(!panel->windowHandle());

View File

@ -283,6 +283,15 @@ auto lifetime = rpl::lifetime();
[self createTouchBar];
[self setTouchBar:TouchBarType::Main];
Media::Player::instance()->playerWidgetToggled(
) | rpl::start_with_next([=](bool toggled) {
if (!toggled) {
[self setTouchBar:TouchBarType::Main];
} else {
[self setTouchBar:TouchBarType::AudioPlayer];
}
}, lifetime);
return self;
}
@ -361,18 +370,12 @@ auto lifetime = rpl::lifetime();
}
- (void)handlePropertyChange:(Media::Player::TrackState)property {
// #TODO: fix hiding of touch bar when last track is ended.
if (property.state == Media::Player::State::Stopped) {
[self setTouchBar:TouchBarType::Main];
return;
} else if (property.state == Media::Player::State::StoppedAtEnd) {
[self setTouchBar:TouchBarType::AudioPlayer];
} else {
[self setTouchBar:TouchBarType::AudioPlayer];
}
self.position = property.position < 0 ? 0 : property.position;
self.duration = property.length;
if (Media::Player::IsStoppedOrStopping(property.state)) {
self.position = 0;
self.duration = 0;
}
[self updateTouchBarTimeItems];
NSButton *playButton = self.touchbarItems[play][@"view"];
if (property.state == Media::Player::State::Playing) {
@ -395,7 +398,7 @@ auto lifetime = rpl::lifetime();
NSString *stime = hours > 0 ? [NSString stringWithFormat:@"%d:", hours] : @"";
stime = (stime.length > 0 || minutes > 9) ?
[NSString stringWithFormat:@"%@%02d:", stime, minutes] :
[NSString stringWithFormat:@"%d:", minutes];
[NSString stringWithFormat:@"%02d:", minutes];
stime = [NSString stringWithFormat:@"%@%02d", stime, seconds];
return stime;
@ -422,24 +425,12 @@ auto lifetime = rpl::lifetime();
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:(int)ceil(size.width * 1.5)];
constant:(int)ceil(size.width) * 1.2];
[field addConstraint:con];
[self.touchbarItems[identifier] setObject:con forKey:@"constrain"];
}
}
- (void)updateTouchBarTimeItemConstrains {
[self removeConstraintForIdentifier:currentPosition];
if (self.duration <= 0) {
[self applyConstraintFromString:[self formatTime:self.position]
forIdentifier:currentPosition];
} else {
NSString *durFormat = [self formatTime:self.duration];
[self applyConstraintFromString:durFormat forIdentifier:currentPosition];
}
}
- (void)updateTouchBarTimeItems {
NSSlider *seekSlider = self.touchbarItems[seekBar][@"view"];
NSTextField *curPosItem = self.touchbarItems[currentPosition][@"view"];
@ -460,7 +451,8 @@ auto lifetime = rpl::lifetime();
timeToString(self.position),
timeToString(self.duration)];
[self updateTouchBarTimeItemConstrains];
[self removeConstraintForIdentifier:currentPosition];
[self applyConstraintFromString:curPosItem.stringValue forIdentifier:currentPosition];
}
- (NSString *)getIdentifierFromView:(id)view {

View File

@ -45,8 +45,6 @@ void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCal
void OpenSystemSettingsForPermission(PermissionType type);
bool OpenSystemSettings(SystemSettingsType type);
void SetTouchBar(TouchBarType type);
[[nodiscard]] QString SystemLanguage();
[[nodiscard]] QString SystemCountry();

View File

@ -646,10 +646,6 @@ void OpenSystemSettingsForPermission(PermissionType type) {
}
}
void SetTouchBar(TouchBarType type) {
// TouchBar is Mac only feature.
}
bool OpenSystemSettings(SystemSettingsType type) {
if (type == SystemSettingsType::Audio) {
crl::on_main([] {