mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Removed using of hardcoded numbers of tray menu actions.
This commit is contained in:
parent
2a86ce596d
commit
6bb7e2c2eb
2 changed files with 26 additions and 21 deletions
|
@ -153,24 +153,39 @@ void MainWindow::createTrayIconMenu() {
|
|||
});
|
||||
#endif // else for Q_OS_WIN
|
||||
|
||||
auto notificationActionText = Core::App().settings().desktopNotify()
|
||||
? tr::lng_disable_notifications_from_tray(tr::now)
|
||||
: tr::lng_enable_notifications_from_tray(tr::now);
|
||||
|
||||
trayIconMenu->addAction(tr::lng_minimize_to_tray(tr::now), [=] {
|
||||
const auto minimizeAction = trayIconMenu->addAction(QString(), [=] {
|
||||
if (_activeForTrayIconAction) {
|
||||
minimizeToTray();
|
||||
} else {
|
||||
showFromTrayMenu();
|
||||
}
|
||||
});
|
||||
trayIconMenu->addAction(notificationActionText, [=] {
|
||||
const auto notificationAction = trayIconMenu->addAction(QString(), [=] {
|
||||
toggleDisplayNotifyFromTray();
|
||||
});
|
||||
trayIconMenu->addAction(tr::lng_quit_from_tray(tr::now), [=] {
|
||||
quitFromTray();
|
||||
});
|
||||
|
||||
_updateTrayMenuTextActions.events(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (!trayIconMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
_activeForTrayIconAction = isActiveForTrayMenu();
|
||||
minimizeAction->setText(_activeForTrayIconAction
|
||||
? tr::lng_minimize_to_tray(tr::now)
|
||||
: tr::lng_open_from_tray(tr::now));
|
||||
|
||||
auto notificationActionText = Core::App().settings().desktopNotify()
|
||||
? tr::lng_disable_notifications_from_tray(tr::now)
|
||||
: tr::lng_enable_notifications_from_tray(tr::now);
|
||||
notificationAction->setText(notificationActionText);
|
||||
}, lifetime());
|
||||
|
||||
_updateTrayMenuTextActions.fire({});
|
||||
|
||||
initTrayMenuHook();
|
||||
}
|
||||
|
||||
|
@ -678,22 +693,10 @@ bool MainWindow::eventFilter(QObject *object, QEvent *e) {
|
|||
}
|
||||
|
||||
void MainWindow::updateTrayMenu() {
|
||||
if (!trayIconMenu) return;
|
||||
|
||||
auto actions = trayIconMenu->actions();
|
||||
const auto active = isActiveForTrayMenu();
|
||||
if (_activeForTrayIconAction != active) {
|
||||
_activeForTrayIconAction = active;
|
||||
const auto toggleAction = actions.at(0);
|
||||
toggleAction->setText(_activeForTrayIconAction
|
||||
? tr::lng_minimize_to_tray(tr::now)
|
||||
: tr::lng_open_from_tray(tr::now));
|
||||
if (!trayIconMenu) {
|
||||
return;
|
||||
}
|
||||
auto notificationAction = actions.at(1);
|
||||
auto notificationActionText = Core::App().settings().desktopNotify()
|
||||
? tr::lng_disable_notifications_from_tray(tr::now)
|
||||
: tr::lng_enable_notifications_from_tray(tr::now);
|
||||
notificationAction->setText(notificationActionText);
|
||||
_updateTrayMenuTextActions.fire({});
|
||||
|
||||
psTrayMenuUpdated();
|
||||
}
|
||||
|
|
|
@ -162,6 +162,8 @@ private:
|
|||
|
||||
object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr };
|
||||
|
||||
rpl::event_stream<> _updateTrayMenuTextActions;
|
||||
|
||||
};
|
||||
|
||||
namespace App {
|
||||
|
|
Loading…
Add table
Reference in a new issue