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

@ -2796,6 +2796,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_mac_menu_show" = "Show Telegram"; "lng_mac_menu_show" = "Show Telegram";
"lng_mac_menu_emoji_and_symbols" = "Emoji & Symbols"; "lng_mac_menu_emoji_and_symbols" = "Emoji & Symbols";
"lng_mac_menu_player_pause" = "Pause";
"lng_mac_menu_player_resume" = "Resume";
"lng_mac_menu_player_next" = "Next";
"lng_mac_menu_player_previous" = "Previous";
"lng_mac_menu_player_stop" = "Stop";
"lng_mac_touchbar_favorite_stickers" = "Favorite stickers"; "lng_mac_touchbar_favorite_stickers" = "Favorite stickers";
// Keys finished // Keys finished

View File

@ -35,14 +35,53 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <IOKit/hidsystem/ev_keymap.h> #include <IOKit/hidsystem/ev_keymap.h>
#include <SPMediaKeyTap.h> #include <SPMediaKeyTap.h>
using Platform::Q2NSString;
using Platform::NS2QString;
namespace { namespace {
constexpr auto kIgnoreActivationTimeoutMs = 500; 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 } // namespace
using Platform::Q2NSString; @interface RpMenu : NSMenu {
using Platform::NS2QString; }
- (rpl::lifetime &) lifetime;
@end // @interface Menu
@implementation RpMenu {
rpl::lifetime _lifetime;
}
- (rpl::lifetime &) lifetime {
return _lifetime;
}
@end // @implementation Menu
@interface qVisualize : NSObject { @interface qVisualize : NSObject {
} }
@ -103,6 +142,8 @@ using Platform::NS2QString;
- (void) ignoreApplicationActivationRightNow; - (void) ignoreApplicationActivationRightNow;
- (NSMenu *) applicationDockMenu:(NSApplication *)sender;
@end // @interface ApplicationDelegate @end // @interface ApplicationDelegate
ApplicationDelegate *_sharedDelegate = nil; ApplicationDelegate *_sharedDelegate = nil;
@ -207,6 +248,46 @@ ApplicationDelegate *_sharedDelegate = nil;
_ignoreActivationStop.callOnce(kIgnoreActivationTimeoutMs); _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 @end // @implementation ApplicationDelegate
namespace Platform { namespace Platform {

View File

@ -29,7 +29,7 @@ Go to ***BuildPath*** and run
git clone https://github.com/desktop-app/patches.git git clone https://github.com/desktop-app/patches.git
cd patches cd patches
git checkout f22ccc5 git checkout 8764c08
cd ../ cd ../
git clone https://chromium.googlesource.com/external/gyp git clone https://chromium.googlesource.com/external/gyp
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
@ -58,7 +58,7 @@ Go to ***BuildPath*** and run
git clone https://github.com/desktop-app/patches.git git clone https://github.com/desktop-app/patches.git
cd patches cd patches
git checkout f22ccc5 git checkout 8764c08
cd .. cd ..
git clone https://git.tukaani.org/xz.git git clone https://git.tukaani.org/xz.git