Added support of switching accounts to touchbar.

This commit is contained in:
23rd 2020-06-22 19:11:49 +03:00 committed by John Preston
parent 1248cef86b
commit 2e7a89d9c4

View file

@ -477,24 +477,36 @@ void MainWindow::initTouchBar() {
if (!IsMac10_13OrGreater()) { if (!IsMac10_13OrGreater()) {
return; return;
} }
[NSApplication sharedApplication]
Core::App().domain().activeSessionValue( .automaticCustomizeTouchBarMenuItemEnabled = true;
) | rpl::start_with_next([=](Main::Session *session) { const auto createNewTouchBar = [=](not_null<Main::Session*> session) {
if (session) { if (_private->_touchBar) {
// We need only common pinned dialogs. return;
if (!_private->_touchBar) { }
if (auto view = reinterpret_cast<NSView*>(winId())) { if (auto view = reinterpret_cast<NSView*>(winId())) {
// Create TouchBar. _private->_touchBar = [[TouchBar alloc]
[NSApplication sharedApplication].automaticCustomizeTouchBarMenuItemEnabled = YES; init:view
_private->_touchBar = [[TouchBar alloc] init:view session:session]; session:session];
} }
} };
} else {
const auto destroyCurrentTouchBar = [=] {
if (_private->_touchBar) { if (_private->_touchBar) {
[_private->_touchBar setTouchBar:Platform::TouchBarType::None]; [_private->_touchBar setTouchBar:Platform::TouchBarType::None];
[_private->_touchBar release]; [_private->_touchBar release];
} }
_private->_touchBar = nil; _private->_touchBar = nil;
};
Core::App().domain().activeSessionChanges(
) | rpl::start_with_next([=](Main::Session *session) {
if (session) {
if (_private->_touchBar) {
destroyCurrentTouchBar();
}
createNewTouchBar(session);
} else {
destroyCurrentTouchBar();
} }
}, lifetime()); }, lifetime());
} }