2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Added Dock menu for macOS.

This commit is contained in:
23rd
2021-05-22 20:43:36 +03:00
parent 2599ae45d6
commit 63febef3ed
3 changed files with 91 additions and 4 deletions

View File

@@ -35,14 +35,53 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <IOKit/hidsystem/ev_keymap.h>
#include <SPMediaKeyTap.h>
using Platform::Q2NSString;
using Platform::NS2QString;
namespace {
constexpr auto kIgnoreActivationTimeoutMs = 500;
NSMenuItem *CreateMenuItem(
QString title,
rpl::lifetime &lifetime,
Fn<void()> callback,
bool enabled = true) {
id block = [^{
Core::Sandbox::Instance().customEnterFromEventLoop(callback);
} copy];
NSMenuItem *item = [[NSMenuItem alloc]
initWithTitle:Q2NSString(title)
action:@selector(invoke)
keyEquivalent:@""];
[item setTarget:block];
[item setEnabled:enabled];
lifetime.add([=] {
[block release];
});
return [item autorelease];
}
} // namespace
using Platform::Q2NSString;
using Platform::NS2QString;
@interface RpMenu : NSMenu {
}
- (rpl::lifetime &) lifetime;
@end // @interface Menu
@implementation RpMenu {
rpl::lifetime _lifetime;
}
- (rpl::lifetime &) lifetime {
return _lifetime;
}
@end // @implementation Menu
@interface qVisualize : NSObject {
}
@@ -103,6 +142,8 @@ using Platform::NS2QString;
- (void) ignoreApplicationActivationRightNow;
- (NSMenu *) applicationDockMenu:(NSApplication *)sender;
@end // @interface ApplicationDelegate
ApplicationDelegate *_sharedDelegate = nil;
@@ -207,6 +248,46 @@ ApplicationDelegate *_sharedDelegate = nil;
_ignoreActivationStop.callOnce(kIgnoreActivationTimeoutMs);
}
- (NSMenu *) applicationDockMenu:(NSApplication *)sender {
RpMenu* dockMenu = [[[RpMenu alloc] initWithTitle: @""] autorelease];
[dockMenu setAutoenablesItems:false];
auto notifyCallback = [] {
auto &settings = Core::App().settings();
settings.setDesktopNotify(!settings.desktopNotify());
};
[dockMenu addItem:CreateMenuItem(
Core::App().settings().desktopNotify()
? tr::lng_disable_notifications_from_tray(tr::now)
: tr::lng_enable_notifications_from_tray(tr::now),
[dockMenu lifetime],
std::move(notifyCallback))];
using namespace Media::Player;
const auto state = instance()->getState(instance()->getActiveType());
if (!IsStoppedOrStopping(state.state)) {
[dockMenu addItem:[NSMenuItem separatorItem]];
[dockMenu addItem:CreateMenuItem(
tr::lng_mac_menu_player_previous(tr::now),
[dockMenu lifetime],
[] { instance()->previous(); },
instance()->previousAvailable(instance()->getActiveType()))];
[dockMenu addItem:CreateMenuItem(
IsPausedOrPausing(state.state)
? tr::lng_mac_menu_player_resume(tr::now)
: tr::lng_mac_menu_player_pause(tr::now),
[dockMenu lifetime],
[] { instance()->playPause(); })];
[dockMenu addItem:CreateMenuItem(
tr::lng_mac_menu_player_next(tr::now),
[dockMenu lifetime],
[] { instance()->next(); },
instance()->nextAvailable(instance()->getActiveType()))];
}
return dockMenu;
}
@end // @implementation ApplicationDelegate
namespace Platform {