mirror of https://github.com/procxx/kepka.git
Refactored code for lifetimes in touchbar.
This commit is contained in:
parent
71f6dd85c2
commit
7dff10f6fd
|
@ -35,7 +35,9 @@ static NSTouchBarItemIdentifier _Nullable previousItem = [NSString stringWithFor
|
||||||
static NSTouchBarItemIdentifier _Nullable closePlayer = [NSString stringWithFormat:@"%@.closePlayer", BASE_ID];
|
static NSTouchBarItemIdentifier _Nullable closePlayer = [NSString stringWithFormat:@"%@.closePlayer", BASE_ID];
|
||||||
static NSTouchBarItemIdentifier _Nullable currentPosition = [NSString stringWithFormat:@"%@.currentPosition", BASE_ID];
|
static NSTouchBarItemIdentifier _Nullable currentPosition = [NSString stringWithFormat:@"%@.currentPosition", BASE_ID];
|
||||||
|
|
||||||
@interface TouchBar : NSTouchBar
|
@interface TouchBar : NSTouchBar {
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
}
|
||||||
@property TouchBarType touchBarType;
|
@property TouchBarType touchBarType;
|
||||||
@property TouchBarType touchBarTypeBeforeLock;
|
@property TouchBarType touchBarTypeBeforeLock;
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ constexpr auto kArchiveId = -1;
|
||||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
|
|
||||||
@interface PinnedDialogButton : NSCustomTouchBarItem {
|
@interface PinnedDialogButton : NSCustomTouchBarItem {
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
rpl::lifetime userpicChangedLifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property(nonatomic, assign) int number;
|
@property(nonatomic, assign) int number;
|
||||||
|
@ -59,8 +61,6 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
|
|
||||||
@implementation PinnedDialogButton : NSCustomTouchBarItem
|
@implementation PinnedDialogButton : NSCustomTouchBarItem
|
||||||
|
|
||||||
auto lifetime = rpl::lifetime();
|
|
||||||
|
|
||||||
- (id) init:(int)num {
|
- (id) init:(int)num {
|
||||||
if (num == kSavedMessagesId) {
|
if (num == kSavedMessagesId) {
|
||||||
self = [super initWithIdentifier:savedMessages];
|
self = [super initWithIdentifier:savedMessages];
|
||||||
|
@ -90,27 +90,36 @@ auto lifetime = rpl::lifetime();
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.peer) {
|
|
||||||
Notify::PeerUpdateViewer(
|
|
||||||
self.peer,
|
|
||||||
Notify::PeerUpdate::Flag::PhotoChanged
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
self.waiting = true;
|
|
||||||
[self updatePinnedDialog];
|
|
||||||
}, lifetime);
|
|
||||||
}
|
|
||||||
|
|
||||||
base::ObservableViewer(
|
base::ObservableViewer(
|
||||||
Auth().downloaderTaskFinished()
|
Auth().downloaderTaskFinished()
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (self.waiting) {
|
if (self.waiting) {
|
||||||
[self updatePinnedDialog];
|
[self updatePinnedDialog];
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, self->lifetime);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setter of peer.
|
||||||
|
- (void) setPeer:(PeerData *)newPeer {
|
||||||
|
if (_peer == newPeer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_peer = newPeer;
|
||||||
|
self->userpicChangedLifetime.destroy();
|
||||||
|
if (!_peer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Notify::PeerUpdateViewer(
|
||||||
|
_peer,
|
||||||
|
Notify::PeerUpdate::Flag::PhotoChanged
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
self.waiting = true;
|
||||||
|
[self updatePinnedDialog];
|
||||||
|
}, self->userpicChangedLifetime);
|
||||||
|
}
|
||||||
|
|
||||||
- (void) updatePinnedDialog {
|
- (void) updatePinnedDialog {
|
||||||
NSButton *button = self.view;
|
NSButton *button = self.view;
|
||||||
button.image = [self getPinImage];
|
button.image = [self getPinImage];
|
||||||
|
@ -229,7 +238,7 @@ auto lifetime = rpl::lifetime();
|
||||||
} else {
|
} else {
|
||||||
[self setTouchBar:TouchBarType::AudioPlayer];
|
[self setTouchBar:TouchBarType::AudioPlayer];
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, self->lifetime);
|
||||||
|
|
||||||
Core::App().passcodeLockChanges(
|
Core::App().passcodeLockChanges(
|
||||||
) | rpl::start_with_next([=](bool locked) {
|
) | rpl::start_with_next([=](bool locked) {
|
||||||
|
@ -239,19 +248,19 @@ auto lifetime = rpl::lifetime();
|
||||||
} else {
|
} else {
|
||||||
[self setTouchBar:self.touchBarTypeBeforeLock];
|
[self setTouchBar:self.touchBarTypeBeforeLock];
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, self->lifetime);
|
||||||
|
|
||||||
Auth().data().pinnedDialogsOrderUpdated(
|
Auth().data().pinnedDialogsOrderUpdated(
|
||||||
) | rpl::start_with_next([self] {
|
) | rpl::start_with_next([self] {
|
||||||
[self updatePinnedButtons];
|
[self updatePinnedButtons];
|
||||||
}, lifetime);
|
}, self->lifetime);
|
||||||
|
|
||||||
Auth().data().chatsListChanges(
|
Auth().data().chatsListChanges(
|
||||||
) | rpl::filter([](Data::Folder *folder) {
|
) | rpl::filter([](Data::Folder *folder) {
|
||||||
return folder && folder->chatsList();
|
return folder && folder->chatsList();
|
||||||
}) | rpl::start_with_next([=](Data::Folder *folder) {
|
}) | rpl::start_with_next([=](Data::Folder *folder) {
|
||||||
[self toggleArchiveButton:folder->chatsList()->empty()];
|
[self toggleArchiveButton:folder->chatsList()->empty()];
|
||||||
}, lifetime);
|
}, self->lifetime);
|
||||||
|
|
||||||
[self updatePinnedButtons];
|
[self updatePinnedButtons];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue