mirror of https://github.com/procxx/kepka.git
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:
parent
2b8e76a060
commit
9059b2e617
|
@ -490,6 +490,7 @@ bool HandleEvent(not_null<QShortcutEvent*> event) {
|
||||||
void ToggleMediaShortcuts(bool toggled) {
|
void ToggleMediaShortcuts(bool toggled) {
|
||||||
Data.toggleMedia(toggled);
|
Data.toggleMedia(toggled);
|
||||||
Platform::SetWatchingMediaKeys(toggled);
|
Platform::SetWatchingMediaKeys(toggled);
|
||||||
|
Media::Player::instance()->playerWidgetToggledNotify(toggled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToggleSupportShortcuts(bool toggled) {
|
void ToggleSupportShortcuts(bool toggled) {
|
||||||
|
|
|
@ -146,6 +146,14 @@ public:
|
||||||
|
|
||||||
rpl::producer<> playlistChanges(AudioMsgId::Type type) const;
|
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 documentLoadProgress(DocumentData *document);
|
||||||
|
|
||||||
void handleLogout();
|
void handleLogout();
|
||||||
|
@ -251,6 +259,7 @@ private:
|
||||||
base::Observable<AudioMsgId::Type> _trackChangedNotifier;
|
base::Observable<AudioMsgId::Type> _trackChangedNotifier;
|
||||||
base::Observable<AudioMsgId::Type> _repeatChangedNotifier;
|
base::Observable<AudioMsgId::Type> _repeatChangedNotifier;
|
||||||
|
|
||||||
|
rpl::event_stream<bool> _playerWidgetToggled;
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -167,7 +167,6 @@ Widget::Widget(QWidget *parent) : RpWidget(parent)
|
||||||
});
|
});
|
||||||
setType(AudioMsgId::Type::Song);
|
setType(AudioMsgId::Type::Song);
|
||||||
_playPause->finishTransform();
|
_playPause->finishTransform();
|
||||||
Platform::SetTouchBar(Platform::TouchBarType::AudioPlayer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::updateVolumeToggleIcon() {
|
void Widget::updateVolumeToggleIcon() {
|
||||||
|
@ -192,7 +191,6 @@ void Widget::setCloseCallback(Fn<void()> callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::stopAndClose() {
|
void Widget::stopAndClose() {
|
||||||
Platform::SetTouchBar(Platform::TouchBarType::None);
|
|
||||||
_voiceIsActive = false;
|
_voiceIsActive = false;
|
||||||
if (_type == AudioMsgId::Type::Voice) {
|
if (_type == AudioMsgId::Type::Voice) {
|
||||||
const auto songData = instance()->current(AudioMsgId::Type::Song);
|
const auto songData = instance()->current(AudioMsgId::Type::Song);
|
||||||
|
|
|
@ -406,10 +406,6 @@ void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCal
|
||||||
void OpenSystemSettingsForPermission(PermissionType type) {
|
void OpenSystemSettingsForPermission(PermissionType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTouchBar(TouchBarType type) {
|
|
||||||
// TouchBar is Mac only feature.
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenSystemSettings(SystemSettingsType type) {
|
bool OpenSystemSettings(SystemSettingsType type) {
|
||||||
if (type == SystemSettingsType::Audio) {
|
if (type == SystemSettingsType::Audio) {
|
||||||
auto options = std::vector<QString>();
|
auto options = std::vector<QString>();
|
||||||
|
|
|
@ -225,10 +225,6 @@ void SetApplicationIcon(const QIcon &icon) {
|
||||||
[image release];
|
[image release];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTouchBar(TouchBarType type) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitOnTopPanel(QWidget *panel) {
|
void InitOnTopPanel(QWidget *panel) {
|
||||||
Expects(!panel->windowHandle());
|
Expects(!panel->windowHandle());
|
||||||
|
|
||||||
|
|
|
@ -283,6 +283,15 @@ auto lifetime = rpl::lifetime();
|
||||||
[self createTouchBar];
|
[self createTouchBar];
|
||||||
[self setTouchBar:TouchBarType::Main];
|
[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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,18 +370,12 @@ auto lifetime = rpl::lifetime();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handlePropertyChange:(Media::Player::TrackState)property {
|
- (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.position = property.position < 0 ? 0 : property.position;
|
||||||
self.duration = property.length;
|
self.duration = property.length;
|
||||||
|
if (Media::Player::IsStoppedOrStopping(property.state)) {
|
||||||
|
self.position = 0;
|
||||||
|
self.duration = 0;
|
||||||
|
}
|
||||||
[self updateTouchBarTimeItems];
|
[self updateTouchBarTimeItems];
|
||||||
NSButton *playButton = self.touchbarItems[play][@"view"];
|
NSButton *playButton = self.touchbarItems[play][@"view"];
|
||||||
if (property.state == Media::Player::State::Playing) {
|
if (property.state == Media::Player::State::Playing) {
|
||||||
|
@ -395,7 +398,7 @@ auto lifetime = rpl::lifetime();
|
||||||
NSString *stime = hours > 0 ? [NSString stringWithFormat:@"%d:", hours] : @"";
|
NSString *stime = hours > 0 ? [NSString stringWithFormat:@"%d:", hours] : @"";
|
||||||
stime = (stime.length > 0 || minutes > 9) ?
|
stime = (stime.length > 0 || minutes > 9) ?
|
||||||
[NSString stringWithFormat:@"%@%02d:", stime, minutes] :
|
[NSString stringWithFormat:@"%@%02d:", stime, minutes] :
|
||||||
[NSString stringWithFormat:@"%d:", minutes];
|
[NSString stringWithFormat:@"%02d:", minutes];
|
||||||
stime = [NSString stringWithFormat:@"%@%02d", stime, seconds];
|
stime = [NSString stringWithFormat:@"%@%02d", stime, seconds];
|
||||||
|
|
||||||
return stime;
|
return stime;
|
||||||
|
@ -422,24 +425,12 @@ auto lifetime = rpl::lifetime();
|
||||||
toItem:nil
|
toItem:nil
|
||||||
attribute:NSLayoutAttributeNotAnAttribute
|
attribute:NSLayoutAttributeNotAnAttribute
|
||||||
multiplier:1.0
|
multiplier:1.0
|
||||||
constant:(int)ceil(size.width * 1.5)];
|
constant:(int)ceil(size.width) * 1.2];
|
||||||
[field addConstraint:con];
|
[field addConstraint:con];
|
||||||
[self.touchbarItems[identifier] setObject:con forKey:@"constrain"];
|
[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 {
|
- (void)updateTouchBarTimeItems {
|
||||||
NSSlider *seekSlider = self.touchbarItems[seekBar][@"view"];
|
NSSlider *seekSlider = self.touchbarItems[seekBar][@"view"];
|
||||||
NSTextField *curPosItem = self.touchbarItems[currentPosition][@"view"];
|
NSTextField *curPosItem = self.touchbarItems[currentPosition][@"view"];
|
||||||
|
@ -460,7 +451,8 @@ auto lifetime = rpl::lifetime();
|
||||||
timeToString(self.position),
|
timeToString(self.position),
|
||||||
timeToString(self.duration)];
|
timeToString(self.duration)];
|
||||||
|
|
||||||
[self updateTouchBarTimeItemConstrains];
|
[self removeConstraintForIdentifier:currentPosition];
|
||||||
|
[self applyConstraintFromString:curPosItem.stringValue forIdentifier:currentPosition];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)getIdentifierFromView:(id)view {
|
- (NSString *)getIdentifierFromView:(id)view {
|
||||||
|
|
|
@ -45,8 +45,6 @@ void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCal
|
||||||
void OpenSystemSettingsForPermission(PermissionType type);
|
void OpenSystemSettingsForPermission(PermissionType type);
|
||||||
bool OpenSystemSettings(SystemSettingsType type);
|
bool OpenSystemSettings(SystemSettingsType type);
|
||||||
|
|
||||||
void SetTouchBar(TouchBarType type);
|
|
||||||
|
|
||||||
[[nodiscard]] QString SystemLanguage();
|
[[nodiscard]] QString SystemLanguage();
|
||||||
[[nodiscard]] QString SystemCountry();
|
[[nodiscard]] QString SystemCountry();
|
||||||
|
|
||||||
|
|
|
@ -646,10 +646,6 @@ void OpenSystemSettingsForPermission(PermissionType type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTouchBar(TouchBarType type) {
|
|
||||||
// TouchBar is Mac only feature.
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenSystemSettings(SystemSettingsType type) {
|
bool OpenSystemSettings(SystemSettingsType type) {
|
||||||
if (type == SystemSettingsType::Audio) {
|
if (type == SystemSettingsType::Audio) {
|
||||||
crl::on_main([] {
|
crl::on_main([] {
|
||||||
|
|
Loading…
Reference in New Issue