feat(GODT-2748): log calls that cause main window to show, with reason.

This commit is contained in:
Xavier Michelon
2023-06-29 16:52:33 +02:00
parent 6fb11d69f9
commit a91d9762db
18 changed files with 164 additions and 101 deletions

View File

@ -33,7 +33,7 @@ using namespace bridgepp;
/// \brief handle notification of attempt to re-open the application.
//****************************************************************************************************************************************************
void applicationShouldHandleReopen(id, SEL) {
app().backend().showMainWindow();
app().backend().showMainWindow("macOS applicationShouldHandleReopen notification");
}

View File

@ -116,6 +116,46 @@ bool QMLBackend::isInternetOn() const {
return isInternetOn_;
}
//****************************************************************************************************************************************************
/// \param[in] reason The reason for the request.
//****************************************************************************************************************************************************
void QMLBackend::showMainWindow(QString const&reason) {
app().log().debug(QString("main window show requested: %1").arg(reason));
emit showMainWindow();
}
//****************************************************************************************************************************************************
/// \param[in] reason The reason for the request.
//****************************************************************************************************************************************************
void QMLBackend::showHelp(QString const&reason) {
app().log().debug(QString("main window show requested (help page): %1").arg(reason));
emit showHelp();
}
//****************************************************************************************************************************************************
/// \param[in] reason The reason for the request.
//****************************************************************************************************************************************************
void QMLBackend::showSettings(QString const&reason) {
app().log().debug(QString("main window show requested (settings page): %1").arg(reason));
emit showSettings();
}
//****************************************************************************************************************************************************
/// \param[in] userID The userID.
/// \param[in] forceShowWindow Should the window be force to display.
/// \param[in] reason The reason for the request.
//****************************************************************************************************************************************************
void QMLBackend::selectUser(QString const &userID, bool forceShowWindow, QString const &reason) {
if (forceShowWindow) {
app().log().debug(QString("main window show requested (user page): %1").arg(reason));
}
emit selectUser(userID, forceShowWindow);
}
//****************************************************************************************************************************************************
/// \return The build year as a string (e.g. 2023)
//****************************************************************************************************************************************************
@ -1116,7 +1156,7 @@ void QMLBackend::connectGrpcEvents() {
connect(client, &GRPCClient::reportBugFinished, this, &QMLBackend::reportBugFinished);
connect(client, &GRPCClient::reportBugSuccess, this, &QMLBackend::bugReportSendSuccess);
connect(client, &GRPCClient::reportBugError, this, &QMLBackend::bugReportSendError);
connect(client, &GRPCClient::showMainWindow, this, &QMLBackend::showMainWindow);
connect(client, &GRPCClient::showMainWindow, [&]() { this->showMainWindow("gRPC showMainWindow event"); });
// cache events
connect(client, &GRPCClient::diskCacheUnavailable, this, &QMLBackend::diskCacheUnavailable);

View File

@ -46,6 +46,10 @@ public: // member functions.
bool waitForEventStreamReaderToFinish(qint32 timeoutMs); ///< Wait for the event stream reader to finish.
UserList const& users() const; ///< Return the list of users
bool isInternetOn() const; ///< Check if bridge considers internet as on.
void showMainWindow(QString const &reason); ///< Show the main window.
void showHelp(QString const &reason); ///< Show the help page.
void showSettings(QString const &reason); ///< Show the settings page.
void selectUser(QString const &userID, bool forceShowWindow, QString const &reason); ///< Select the user and display its account details (or login screen).
// invokable methods can be called from QML. They generally return a value, which slots cannot do.
Q_INVOKABLE static QString buildYear(); ///< Return the application build year.

View File

@ -34,7 +34,7 @@ QColor const warnColor(255, 153, 0); ///< The warn state color.
QColor const updateColor(35, 158, 206); ///< The warn state color.
QColor const greyColor(112, 109, 107); ///< The grey color.
qint64 const iconRefreshTimerIntervalMs = 1000; ///< The interval for the refresh timer when switching DPI / screen config, in milliseconds.
qint64 const iconRefreshDurationSecs = 10; ///< The total number of seconds during wich we periodically refresh the icon after a DPI change.
qint64 const iconRefreshDurationSecs = 10; ///< The total number of seconds during which we periodically refresh the icon after a DPI change.
//****************************************************************************************************************************************************
@ -184,10 +184,12 @@ TrayIcon::TrayIcon()
this->setContextMenu(menu_.get());
connect(menu_.get(), &QMenu::aboutToShow, this, &TrayIcon::onMenuAboutToShow);
connect(this, &TrayIcon::selectUser, &app().backend(), &QMLBackend::selectUser);
connect(this, &TrayIcon::selectUser, &app().backend(), [](QString const& userID, bool forceShowWindow) {
app().backend().selectUser(userID, forceShowWindow);
});
connect(this, &TrayIcon::activated, this, &TrayIcon::onActivated);
// some OSes/Desktop managers will automatically show main window when clicked, but not all, so we do it manually.
connect(this, &TrayIcon::messageClicked, &app().backend(), &QMLBackend::showMainWindow);
connect(this, &TrayIcon::messageClicked, []() { app().backend().showMainWindow("tray icon popup notification clicked"); });
this->show();
// TrayIcon does not expose its screen, so we connect relevant screen events to our DPI change handler.
@ -226,7 +228,7 @@ void TrayIcon::onUserClicked() {
throw Exception("Could not retrieve context menu's selected user.");
}
emit selectUser(userID, true);
app().backend().selectUser(userID, true, "tray menu user clicked");
} catch (Exception const &e) {
app().log().error(e.qwhat());
}
@ -238,7 +240,7 @@ void TrayIcon::onUserClicked() {
//****************************************************************************************************************************************************
void TrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) {
if ((QSystemTrayIcon::Trigger == reason) && !onMacOS()) {
app().backend().showMainWindow();
app().backend().showMainWindow("tray icon activated");
}
}
@ -346,7 +348,7 @@ void TrayIcon::refreshContextMenu() {
bool const internetOn = app().backend().isInternetOn();
menu_->clear();
menu_->addAction(statusIcon_, stateString_, &app().backend(), &QMLBackend::showMainWindow);
menu_->addAction(statusIcon_, stateString_, []() {app().backend().showMainWindow("tray menu status clicked");});
menu_->addSeparator();
QKeySequence noShortcut;
UserList const &users = app().backend().users();
@ -370,11 +372,15 @@ void TrayIcon::refreshContextMenu() {
menu_->addSeparator();
}
menu_->addAction(tr("&Open Bridge"), onMac ? QKeySequence("Ctrl+O") : noShortcut, &app().backend(), &QMLBackend::showMainWindow);
menu_->addAction(tr("&Help"), onMac ? QKeySequence("Ctrl+F1") : noShortcut, &app().backend(), &QMLBackend::showHelp);
menu_->addAction(tr("&Settings"), onMac ? QKeySequence("Ctrl+,") : noShortcut, &app().backend(), &QMLBackend::showSettings);
menu_->addAction(tr("&Open Bridge"), onMac ? QKeySequence("Ctrl+O") : noShortcut, []() {
app().backend().showMainWindow("tray menu 'open bridge' clicked");
});
menu_->addAction(tr("&Help"), onMac ? QKeySequence("Ctrl+F1") : noShortcut, []() {
app().backend().showHelp("tray menu 'Help' clicked");
});
menu_->addAction(tr("&Settings"), onMac ? QKeySequence("Ctrl+,") : noShortcut, []() {
app().backend().showHelp("tray menu 'Settings' clicked");
});
menu_->addSeparator();
menu_->addAction(tr("&Quit Bridge"), onMac ? QKeySequence("Ctrl+Q") : noShortcut, &app().backend(), &QMLBackend::quit);
}

View File

@ -213,7 +213,7 @@ void focusOtherInstance() {
if (!client.connectToServer(5000, sc.port, &error)) {
throw Exception("Could not connect to bridge focus service for a raise call.", error);
}
if (!client.raise().ok()) {
if (!client.raise("focusOtherInstance").ok()) {
throw Exception(QString("The raise call to the bridge focus service failed."));
}
}