Other: fix bug in login screen <-> main window transition. [skip ci]

Other: fixed bug with split mode toggle. [skip ci]

Other: fix QML warnings. [skip ci]

Other: fix showMainWindow gRPC event binding. [skip ci].

QML Fixes [skip ci]

Other: wait for EventStreamReader thread to finish on exit.

Other: made BridgeMonitor generic, as ProcessMonitor. [skip ci]
This commit is contained in:
Xavier Michelon
2022-08-11 11:27:05 +02:00
committed by Jakub
parent 4ed9625959
commit ed904c2bdd
25 changed files with 149 additions and 125 deletions

View File

@ -108,6 +108,7 @@ add_library(bridgepp
bridgepp/GRPC/GRPCUtils.cpp bridgepp/GRPC/GRPCUtils.h
${PROTO_CPP_FILE} ${PROTO_H_FILE} ${GRPC_CPP_FILE} ${GRPC_H_FILE}
bridgepp/Log/Log.h bridgepp/Log/Log.cpp
bridgepp/ProcessMonitor.cpp bridgepp/ProcessMonitor.h
bridgepp/User/User.cpp bridgepp/User/User.h
bridgepp/Worker/Worker.h bridgepp/Worker/Overseer.h bridgepp/Worker/Overseer.cpp
)

View File

@ -16,14 +16,15 @@
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#ifndef BRIDGE_GUI_TESTER_BRIDGE_UTILS_H
#define BRIDGE_GUI_TESTER_BRIDGE_UTILS_H
#ifndef BRIDGE_PP_TESTER_BRIDGE_UTILS_H
#define BRIDGE_PP_TESTER_BRIDGE_UTILS_H
#include <bridgepp/User/User.h>
namespace bridgepp {
namespace bridgepp
{
QString userConfigDir(); ///< Get the path of the user configuration folder.
@ -34,8 +35,8 @@ QString randomFirstName(); ///< Get a random first name from a pre-determined li
QString randomLastName(); ///< Get a random first name from a pre-determined list.
SPUser randomUser(); ///< Get a random user.
} // namespace
#endif // BRIDGE_GUI_TESTER_BRIDGE_UTILS_H
#endif // BRIDGE_PP_TESTER_BRIDGE_UTILS_H

View File

@ -16,8 +16,8 @@
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#ifndef BRIDGE_GUI_TESTER_EVENT_FACTORY_H
#define BRIDGE_GUI_TESTER_EVENT_FACTORY_H
#ifndef BRIDGE_PP_EVENT_FACTORY_H
#define BRIDGE_PP_EVENT_FACTORY_H
#include "bridge.grpc.pb.h"
@ -85,4 +85,4 @@ SPStreamEvent newUserChangedEvent(QString const &userID); ///< Create a new User
} // namespace bridgepp
#endif //BRIDGE_GUI_TESTER_EVENT_FACTORY_H
#endif //BRIDGE_PP_EVENT_FACTORY_H

View File

@ -16,8 +16,8 @@
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#ifndef BRIDGE_GUI_RPC_CLIENT_H
#define BRIDGE_GUI_RPC_CLIENT_H
#ifndef BRIDGE_PP_RPC_CLIENT_H
#define BRIDGE_PP_RPC_CLIENT_H
#include "../User/User.h"
@ -233,4 +233,4 @@ private: // data members.
}
#endif // BRIDGE_GUI_RPC_CLIENT_H
#endif // BRIDGE_PP_RPC_CLIENT_H

View File

@ -16,8 +16,8 @@
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#ifndef BRIDGE_GUI_GRPC_UTILS_H
#define BRIDGE_GUI_GRPC_UTILS_H
#ifndef BRIDGE_PP_GRPC_UTILS_H
#define BRIDGE_PP_GRPC_UTILS_H
#include "../User/User.h"
@ -42,4 +42,4 @@ SPUser userFromGRPC(grpc::User const &grpcUser); ///< Create a bridgepp::User fr
}
#endif // BRIDGE_GUI_GRPC_UTILS_H
#endif // BRIDGE_PP_GRPC_UTILS_H

View File

@ -0,0 +1,89 @@
// Copyright (c) 2022 Proton AG
//
// This file is part of Proton Mail Bridge.
//
// Proton Mail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Proton Mail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#include "ProcessMonitor.h"
#include "Exception/Exception.h"
namespace bridgepp
{
//****************************************************************************************************************************************************
/// \param[in] exePath The path of the executable.
/// \param[in] parent The parent object of the worker.
//****************************************************************************************************************************************************
ProcessMonitor::ProcessMonitor(QString const &exePath, QStringList const &args, QObject *parent)
: Worker(parent)
, exePath_(exePath)
, args_(args)
{
QFileInfo fileInfo(exePath);
if (!fileInfo.exists())
throw Exception(QString("Could not locate %1 executable.").arg(fileInfo.baseName()));
if ((!fileInfo.isFile()) || (!fileInfo.isExecutable()))
throw Exception(QString("Invalid %1 executable").arg(fileInfo.baseName()));
}
//****************************************************************************************************************************************************
//
//****************************************************************************************************************************************************
void ProcessMonitor::run()
{
try
{
emit started();
QProcess p;
p.start(exePath_, args_);
p.waitForStarted();
status_.running = true;
status_.pid = p.processId();
while (!p.waitForFinished(100))
{
// we discard output from bridge, it's logged to file on bridge side.
p.readAllStandardError();
p.readAllStandardOutput();
}
status_.running = false;
status_.returnCode = p.exitCode();
emit processExited(status_.returnCode);
emit finished();
}
catch (Exception const &e)
{
emit error(e.qwhat());
}
}
//****************************************************************************************************************************************************
/// \return status of the monitored process
//****************************************************************************************************************************************************
const ProcessMonitor::MonitorStatus &ProcessMonitor::getStatus()
{
return status_;
}
} // namespace bridgepp

View File

@ -0,0 +1,67 @@
// Copyright (c) 2022 Proton AG
//
// This file is part of Proton Mail Bridge.
//
// Proton Mail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Proton Mail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#ifndef BRIDGE_PP_PROCESS_MONITOR_H
#define BRIDGE_PP_PROCESS_MONITOR_H
#include "Worker/Worker.h"
namespace bridgepp
{
//**********************************************************************************************************************
/// \brief Process launcher and monitor class.
//**********************************************************************************************************************
class ProcessMonitor : public Worker
{
Q_OBJECT
public: // static member functions
struct MonitorStatus
{
bool running = false;
int returnCode = 0;
qint64 pid = 0;
};
public: // member functions.
ProcessMonitor(QString const &exePath, QStringList const &args, QObject *parent); ///< Default constructor.
ProcessMonitor(ProcessMonitor const &) = delete; ///< Disabled copy-constructor.
ProcessMonitor(ProcessMonitor &&) = delete; ///< Disabled assignment copy-constructor.
~ProcessMonitor() override = default; ///< Destructor.
ProcessMonitor &operator=(ProcessMonitor const &) = delete; ///< Disabled assignment operator.
ProcessMonitor &operator=(ProcessMonitor &&) = delete; ///< Disabled move assignment operator.
void run() override; ///< Run the worker.
MonitorStatus const &getStatus();
signals:
void processExited(int code); ///< Slot for the exiting of the process.
private: // data members
QString const exePath_; ///< The path to the executable.
QStringList args_; ///< arguments to be passed to the brigde.
MonitorStatus status_; ///< Status of the monitoring.
};
}
#endif //BRIDGE_PP_PROCESS_MONITOR_H

View File

@ -16,8 +16,8 @@
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#ifndef BRIDGE_GUI_USER_H
#define BRIDGE_GUI_USER_H
#ifndef BRIDGE_PP_USER_H
#define BRIDGE_PP_USER_H
namespace bridgepp
@ -127,4 +127,4 @@ private: // data members.
} // namespace bridgepp
#endif // BRIDGE_GUI_USER_H
#endif // BRIDGE_PP_USER_H

View File

@ -108,6 +108,26 @@ bool Overseer::isFinished() const
}
//****************************************************************************************************************************************************
/// \param timeoutMs The timeout after which the function should return false if the event stream reader is not finished. if -1 one, the function
/// never times out.
/// \return false if and only if the timeout delay was reached.
//****************************************************************************************************************************************************
bool Overseer::wait(qint32 timeoutMs) const
{
QElapsedTimer timer;
timer.start();
while (!this->isFinished()) {
if ((timeoutMs >= 0) && (timer.elapsed() > timeoutMs))
return false;
QThread::msleep(10);
}
return true;
}
//****************************************************************************************************************************************************
/// \return The worker.
//****************************************************************************************************************************************************

View File

@ -41,6 +41,7 @@ public: // member functions.
Overseer &operator=(Overseer const &) = delete; ///< Disabled assignment operator.
Overseer &operator=(Overseer &&) = delete; ///< Disabled move assignment operator.
bool isFinished() const; ///< Check if the worker is finished.
bool wait(qint32 timeoutMs) const; ///< Wait for the worker to finish.
Worker *worker() const; ///< Return worker.
public slots: