mirror of https://github.com/procxx/kepka.git
Added theme change event handler to touchbar.
This commit is contained in:
parent
f1e3d2f513
commit
2c1e3cd094
|
@ -19,6 +19,7 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "observer_peer.h"
|
#include "observer_peer.h"
|
||||||
#include "styles/style_media_player.h"
|
#include "styles/style_media_player.h"
|
||||||
|
#include "window/themes/window_theme.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "ui/empty_userpic.h"
|
#include "ui/empty_userpic.h"
|
||||||
|
|
||||||
|
@ -63,10 +64,14 @@ NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size = kIdealIc
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsCurrentSongExists() {
|
inline bool CurrentSongExists() {
|
||||||
return Media::Player::instance()->current(kSongType).audio() != nullptr;
|
return Media::Player::instance()->current(kSongType).audio() != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool UseEmptyUserpic(PeerData *peer) {
|
||||||
|
return (peer && (peer->useEmptyUserpic() || peer->isSelf()));
|
||||||
|
}
|
||||||
|
|
||||||
NSString *FormatTime(int time) {
|
NSString *FormatTime(int time) {
|
||||||
const auto seconds = time % 60;
|
const auto seconds = time % 60;
|
||||||
const auto minutes = (time / 60) % 60;
|
const auto minutes = (time / 60) % 60;
|
||||||
|
@ -100,7 +105,7 @@ NSString *FormatTime(int time) {
|
||||||
- (id) init:(int)num;
|
- (id) init:(int)num;
|
||||||
- (NSImage *) getPinImage;
|
- (NSImage *) getPinImage;
|
||||||
- (void)buttonActionPin:(NSButton *)sender;
|
- (void)buttonActionPin:(NSButton *)sender;
|
||||||
- (void)updatePinnedDialog;
|
- (void)updateUserpic;
|
||||||
|
|
||||||
@end // @interface PinnedDialogButton
|
@end // @interface PinnedDialogButton
|
||||||
|
|
||||||
|
@ -131,6 +136,16 @@ NSString *FormatTime(int time) {
|
||||||
[button sizeToFit];
|
[button sizeToFit];
|
||||||
self.view = button;
|
self.view = button;
|
||||||
|
|
||||||
|
using Update = const Window::Theme::BackgroundUpdate;
|
||||||
|
base::ObservableViewer(
|
||||||
|
*Window::Theme::Background()
|
||||||
|
) | rpl::filter([=](const Update &update) {
|
||||||
|
return update.paletteChanged()
|
||||||
|
&& (_number <= kSavedMessagesId || UseEmptyUserpic(_peer));
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
|
[self updateUserpic];
|
||||||
|
}, _lifetime);
|
||||||
|
|
||||||
if (num <= kSavedMessagesId) {
|
if (num <= kSavedMessagesId) {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +154,7 @@ NSString *FormatTime(int time) {
|
||||||
Auth().downloaderTaskFinished()
|
Auth().downloaderTaskFinished()
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (isWaitingUserpicLoad) {
|
if (isWaitingUserpicLoad) {
|
||||||
[self updatePinnedDialog];
|
[self updateUserpic];
|
||||||
}
|
}
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
|
||||||
|
@ -161,11 +176,11 @@ NSString *FormatTime(int time) {
|
||||||
Notify::PeerUpdate::Flag::PhotoChanged
|
Notify::PeerUpdate::Flag::PhotoChanged
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
isWaitingUserpicLoad = true;
|
isWaitingUserpicLoad = true;
|
||||||
[self updatePinnedDialog];
|
[self updateUserpic];
|
||||||
}, _userpicChangedLifetime);
|
}, _userpicChangedLifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updatePinnedDialog {
|
- (void) updateUserpic {
|
||||||
NSButton *button = self.view;
|
NSButton *button = self.view;
|
||||||
button.image = [self getPinImage];
|
button.image = [self getPinImage];
|
||||||
}
|
}
|
||||||
|
@ -407,7 +422,7 @@ NSString *FormatTime(int time) {
|
||||||
if (type == Platform::TouchBarType::Main) {
|
if (type == Platform::TouchBarType::Main) {
|
||||||
[_parentView setTouchBar:_touchBarMain];
|
[_parentView setTouchBar:_touchBarMain];
|
||||||
} else if (type == Platform::TouchBarType::AudioPlayer) {
|
} else if (type == Platform::TouchBarType::AudioPlayer) {
|
||||||
if (!IsCurrentSongExists()
|
if (!CurrentSongExists()
|
||||||
|| Media::Player::instance()->getActiveType() != kSongType) {
|
|| Media::Player::instance()->getActiveType() != kSongType) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -429,7 +444,7 @@ NSString *FormatTime(int time) {
|
||||||
if (button.number == kArchiveId) {
|
if (button.number == kArchiveId) {
|
||||||
NSCustomTouchBarItem *item = [_touchBarMain itemForIdentifier:kPinnedPanelItemIdentifier];
|
NSCustomTouchBarItem *item = [_touchBarMain itemForIdentifier:kPinnedPanelItemIdentifier];
|
||||||
NSStackView *stack = item.view;
|
NSStackView *stack = item.view;
|
||||||
[button updatePinnedDialog];
|
[button updateUserpic];
|
||||||
if (hide && !button.isDeletedFromView) {
|
if (hide && !button.isDeletedFromView) {
|
||||||
button.isDeletedFromView = true;
|
button.isDeletedFromView = true;
|
||||||
[stack removeView:button.view];
|
[stack removeView:button.view];
|
||||||
|
@ -471,7 +486,7 @@ NSString *FormatTime(int time) {
|
||||||
const auto pinned = order.at(num - 1);
|
const auto pinned = order.at(num - 1);
|
||||||
if (const auto history = pinned.history()) {
|
if (const auto history = pinned.history()) {
|
||||||
button.peer = history->peer;
|
button.peer = history->peer;
|
||||||
[button updatePinnedDialog];
|
[button updateUserpic];
|
||||||
if (history->peer->id == Auth().userPeerId()) {
|
if (history->peer->id == Auth().userPeerId()) {
|
||||||
isSelfPeerPinned = true;
|
isSelfPeerPinned = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue