mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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
|
#endif // else for Q_OS_WIN
|
||||||
|
|
||||||
auto notificationActionText = Core::App().settings().desktopNotify()
|
const auto minimizeAction = trayIconMenu->addAction(QString(), [=] {
|
||||||
? 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), [=] {
|
|
||||||
if (_activeForTrayIconAction) {
|
if (_activeForTrayIconAction) {
|
||||||
minimizeToTray();
|
minimizeToTray();
|
||||||
} else {
|
} else {
|
||||||
showFromTrayMenu();
|
showFromTrayMenu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
trayIconMenu->addAction(notificationActionText, [=] {
|
const auto notificationAction = trayIconMenu->addAction(QString(), [=] {
|
||||||
toggleDisplayNotifyFromTray();
|
toggleDisplayNotifyFromTray();
|
||||||
});
|
});
|
||||||
trayIconMenu->addAction(tr::lng_quit_from_tray(tr::now), [=] {
|
trayIconMenu->addAction(tr::lng_quit_from_tray(tr::now), [=] {
|
||||||
quitFromTray();
|
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();
|
initTrayMenuHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,22 +693,10 @@ bool MainWindow::eventFilter(QObject *object, QEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateTrayMenu() {
|
void MainWindow::updateTrayMenu() {
|
||||||
if (!trayIconMenu) return;
|
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));
|
|
||||||
}
|
}
|
||||||
auto notificationAction = actions.at(1);
|
_updateTrayMenuTextActions.fire({});
|
||||||
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);
|
|
||||||
|
|
||||||
psTrayMenuUpdated();
|
psTrayMenuUpdated();
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,8 @@ private:
|
||||||
|
|
||||||
object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr };
|
object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr };
|
||||||
|
|
||||||
|
rpl::event_stream<> _updateTrayMenuTextActions;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace App {
|
namespace App {
|
||||||
|
|
Loading…
Add table
Reference in a new issue