Added accounts list to dock menu on macOS.

This commit is contained in:
23rd
2025-12-19 10:18:28 +03:00
committed by John Preston
parent d51dd1cdb5
commit 57b22d2ad2
2 changed files with 39 additions and 0 deletions

View File

@@ -7433,6 +7433,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_mac_menu_player_resume" = "Resume";
"lng_mac_menu_player_next" = "Next";
"lng_mac_menu_player_previous" = "Previous";
"lng_mac_menu_profiles" = "Profiles";
"lng_mac_touchbar_favorite_stickers" = "Favorite stickers";

View File

@@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h"
#include "mainwidget.h"
#include "main/main_account.h"
#include "main/main_domain.h"
#include "main/main_session.h"
#include "data/data_user.h"
#include "calls/calls_instance.h"
#include "core/sandbox.h"
#include "core/application.h"
@@ -223,6 +227,40 @@ ApplicationDelegate *_sharedDelegate = nil;
RpMenu* dockMenu = [[[RpMenu alloc] initWithTitle: @""] autorelease];
[dockMenu setAutoenablesItems:false];
const auto accounts = Core::App().domain().orderedAccounts();
if (accounts.size() > 1) {
[dockMenu addItem:[NSMenuItem separatorItem]];
NSMenuItem *profilesHeader = [[NSMenuItem alloc]
initWithTitle:@"" action:nil keyEquivalent:@""];
NSDictionary *attributes = @{
NSFontAttributeName: [NSFont
menuFontOfSize:[NSFont smallSystemFontSize]],
NSForegroundColorAttributeName: [NSColor secondaryLabelColor]
};
NSAttributedString *attrTitle = [[NSAttributedString alloc]
initWithString:Q2NSString(tr::lng_mac_menu_profiles(tr::now))
attributes:attributes];
[profilesHeader setAttributedTitle:attrTitle];
[attrTitle release];
[profilesHeader setEnabled:NO];
[dockMenu addItem:[profilesHeader autorelease]];
constexpr auto kMaxLength = 30;
for (const auto &account : accounts) {
if (account->sessionExists()) {
auto name = account->session().user()->name();
[dockMenu addItem:CreateMenuItem(
(name.size() > kMaxLength)
? (name.mid(0, kMaxLength) + Ui::kQEllipsis)
: name,
[dockMenu lifetime],
[account] {
Core::App().ensureSeparateWindowFor(account);
})];
}
}
[dockMenu addItem:[NSMenuItem separatorItem]];
}
auto notifyCallback = [] {
auto &settings = Core::App().settings();
settings.setDesktopNotify(!settings.desktopNotify());