Refactored code for lifetimes in touchbar.

This commit is contained in:
23rd 2019-05-10 12:50:47 +03:00 committed by John Preston
parent 71f6dd85c2
commit 7dff10f6fd
2 changed files with 30 additions and 19 deletions

View File

@ -35,7 +35,9 @@ static NSTouchBarItemIdentifier _Nullable previousItem = [NSString stringWithFor
static NSTouchBarItemIdentifier _Nullable closePlayer = [NSString stringWithFormat:@"%@.closePlayer", 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 touchBarTypeBeforeLock;

View File

@ -43,6 +43,8 @@ constexpr auto kArchiveId = -1;
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
@interface PinnedDialogButton : NSCustomTouchBarItem {
rpl::lifetime lifetime;
rpl::lifetime userpicChangedLifetime;
}
@property(nonatomic, assign) int number;
@ -59,8 +61,6 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
@implementation PinnedDialogButton : NSCustomTouchBarItem
auto lifetime = rpl::lifetime();
- (id) init:(int)num {
if (num == kSavedMessagesId) {
self = [super initWithIdentifier:savedMessages];
@ -90,27 +90,36 @@ auto lifetime = rpl::lifetime();
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(
Auth().downloaderTaskFinished()
Auth().downloaderTaskFinished()
) | rpl::start_with_next([=] {
if (self.waiting) {
[self updatePinnedDialog];
}
}, lifetime);
}, self->lifetime);
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 {
NSButton *button = self.view;
button.image = [self getPinImage];
@ -229,7 +238,7 @@ auto lifetime = rpl::lifetime();
} else {
[self setTouchBar:TouchBarType::AudioPlayer];
}
}, lifetime);
}, self->lifetime);
Core::App().passcodeLockChanges(
) | rpl::start_with_next([=](bool locked) {
@ -239,19 +248,19 @@ auto lifetime = rpl::lifetime();
} else {
[self setTouchBar:self.touchBarTypeBeforeLock];
}
}, lifetime);
}, self->lifetime);
Auth().data().pinnedDialogsOrderUpdated(
) | rpl::start_with_next([self] {
[self updatePinnedButtons];
}, lifetime);
}, self->lifetime);
Auth().data().chatsListChanges(
) | rpl::filter([](Data::Folder *folder) {
return folder && folder->chatsList();
}) | rpl::start_with_next([=](Data::Folder *folder) {
[self toggleArchiveButton:folder->chatsList()->empty()];
}, lifetime);
}, self->lifetime);
[self updatePinnedButtons];