mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-03 22:56:49 +00:00
feat(src/app/App): supports single instance
This commit is contained in:
parent
15b5093b9b
commit
52cba384b9
6 changed files with 22 additions and 27 deletions
|
|
@ -62,7 +62,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG -DQT_DECLARAT
|
|||
# Define packages, libs, sources, headers, resources and languages.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
set(QT5_PACKAGES Core Gui Quick Widgets QuickControls2 Svg LinguistTools)
|
||||
set(QT5_PACKAGES Core Gui Quick Widgets QuickControls2 Svg LinguistTools Network)
|
||||
|
||||
find_package(Linphone REQUIRED)
|
||||
find_package(LinphoneCxx REQUIRED)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ inline bool installLocale (App &app, QTranslator &translator, const QLocale &loc
|
|||
return translator.load(locale, LANGUAGES_PATH) && app.installTranslator(&translator);
|
||||
}
|
||||
|
||||
App::App (int &argc, char **argv) : QApplication(argc, argv) {
|
||||
App::App (int &argc, char *argv[]) : SingleApplication(argc, argv) {
|
||||
setApplicationVersion("4.0");
|
||||
setWindowIcon(QIcon(WINDOW_ICON_PATH));
|
||||
|
||||
|
|
|
|||
|
|
@ -25,16 +25,17 @@
|
|||
|
||||
#include "../components/notifier/Notifier.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickWindow>
|
||||
|
||||
#include "../externals/single-application/SingleApplication.hpp"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
class DefaultTranslator;
|
||||
|
||||
class App : public QApplication {
|
||||
class App : public SingleApplication {
|
||||
Q_OBJECT;
|
||||
|
||||
Q_PROPERTY(QString configLocale READ getConfigLocale WRITE setConfigLocale NOTIFY configLocaleChanged);
|
||||
|
|
@ -42,7 +43,7 @@ class App : public QApplication {
|
|||
Q_PROPERTY(QVariantList availableLocales READ getAvailableLocales CONSTANT);
|
||||
|
||||
public:
|
||||
App (int &argc, char **argv);
|
||||
App (int &argc, char *argv[]);
|
||||
~App ();
|
||||
|
||||
void initContentApp ();
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ SingleApplicationPrivate::~SingleApplicationPrivate () {
|
|||
delete socket;
|
||||
}
|
||||
memory->lock();
|
||||
InstancesInfo *inst = (InstancesInfo *)memory->data();
|
||||
InstancesInfo *inst = static_cast<InstancesInfo *>(memory->data());
|
||||
if (server != nullptr) {
|
||||
server->close();
|
||||
delete server;
|
||||
|
|
@ -78,19 +78,19 @@ SingleApplicationPrivate::~SingleApplicationPrivate () {
|
|||
void SingleApplicationPrivate::genBlockServerName (int timeout) {
|
||||
QCryptographicHash appData(QCryptographicHash::Sha256);
|
||||
appData.addData("SingleApplication", 17);
|
||||
appData.addData(SingleApplication::app_t::applicationName().toUtf8());
|
||||
appData.addData(SingleApplication::app_t::organizationName().toUtf8());
|
||||
appData.addData(SingleApplication::app_t::organizationDomain().toUtf8());
|
||||
appData.addData(QApplication::applicationName().toUtf8());
|
||||
appData.addData(QApplication::organizationName().toUtf8());
|
||||
appData.addData(QApplication::organizationDomain().toUtf8());
|
||||
|
||||
if (!(options & SingleApplication::Mode::ExcludeAppVersion)) {
|
||||
appData.addData(SingleApplication::app_t::applicationVersion().toUtf8());
|
||||
appData.addData(QApplication::applicationVersion().toUtf8());
|
||||
}
|
||||
|
||||
if (!(options & SingleApplication::Mode::ExcludeAppPath)) {
|
||||
#ifdef Q_OS_WIN
|
||||
appData.addData(SingleApplication::app_t::applicationFilePath().toLower().toUtf8());
|
||||
appData.addData(QApplication::applicationFilePath().toLower().toUtf8());
|
||||
#else
|
||||
appData.addData(SingleApplication::app_t::applicationFilePath().toUtf8());
|
||||
appData.addData(QApplication::applicationFilePath().toUtf8());
|
||||
#endif // ifdef Q_OS_WIN
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ void SingleApplicationPrivate::startPrimary (bool resetMemory) {
|
|||
|
||||
// Reset the number of connections
|
||||
memory->lock();
|
||||
InstancesInfo *inst = (InstancesInfo *)memory->data();
|
||||
InstancesInfo *inst = static_cast<InstancesInfo *>(memory->data());
|
||||
|
||||
if (resetMemory) {
|
||||
inst->primary = true;
|
||||
|
|
@ -207,7 +207,7 @@ void SingleApplicationPrivate::connectToPrimary (int msecs, char connectionType)
|
|||
QByteArray initMsg = blockServerName.toLatin1();
|
||||
|
||||
initMsg.append(connectionType);
|
||||
initMsg.append((const char *)&instanceNumber, sizeof(quint32));
|
||||
initMsg.append(reinterpret_cast<const char *>(&instanceNumber), sizeof(quint32));
|
||||
initMsg.append(QByteArray::number(qChecksum(initMsg.constData(), initMsg.length()), 256));
|
||||
|
||||
socket->write(initMsg);
|
||||
|
|
@ -283,7 +283,7 @@ void SingleApplicationPrivate::slotConnectionEstablished () {
|
|||
initMsg += connectionType;
|
||||
tmp = nextConnSocket->read(sizeof(quint32));
|
||||
const char *data = tmp.constData();
|
||||
instanceId = (quint32) * data;
|
||||
instanceId = static_cast<quint32>(*data);
|
||||
initMsg += tmp;
|
||||
// Verify the checksum of the initMsg
|
||||
QByteArray checksum = QByteArray::number(
|
||||
|
|
@ -356,7 +356,7 @@ void SingleApplicationPrivate::slotClientConnectionClosed (QLocalSocket *closedS
|
|||
* @param {bool} allowSecondaryInstances
|
||||
*/
|
||||
SingleApplication::SingleApplication (int &argc, char *argv[], bool allowSecondary, Options options, int timeout)
|
||||
: app_t(argc, argv), d_ptr(new SingleApplicationPrivate(this)) {
|
||||
: QApplication(argc, argv), d_ptr(new SingleApplicationPrivate(this)) {
|
||||
Q_D(SingleApplication);
|
||||
|
||||
// Store the current mode of the program
|
||||
|
|
@ -384,7 +384,7 @@ SingleApplication::SingleApplication (int &argc, char *argv[], bool allowSeconda
|
|||
// Attempt to attach to the memory segment
|
||||
if (d->memory->attach()) {
|
||||
d->memory->lock();
|
||||
InstancesInfo *inst = (InstancesInfo *)d->memory->data();
|
||||
InstancesInfo *inst = static_cast<InstancesInfo *>(d->memory->data());
|
||||
|
||||
if (!inst->primary) {
|
||||
d->startPrimary(false);
|
||||
|
|
|
|||
|
|
@ -25,15 +25,10 @@
|
|||
#ifndef SINGLE_APPLICATION_H
|
||||
#define SINGLE_APPLICATION_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QtCore/QtGlobal>
|
||||
#include <QtNetwork/QLocalSocket>
|
||||
|
||||
#ifndef QAPPLICATION_CLASS
|
||||
#define QAPPLICATION_CLASS QCoreApplication
|
||||
#endif // ifndef QAPPLICATION_CLASS
|
||||
|
||||
#include QT_STRINGIFY(QAPPLICATION_CLASS)
|
||||
|
||||
// =============================================================================
|
||||
|
||||
class SingleApplicationPrivate;
|
||||
|
|
@ -43,11 +38,9 @@ class SingleApplicationPrivate;
|
|||
* Application
|
||||
* @see QCoreApplication
|
||||
*/
|
||||
class SingleApplication : public QAPPLICATION_CLASS {
|
||||
class SingleApplication : public QApplication {
|
||||
Q_OBJECT
|
||||
|
||||
typedef QAPPLICATION_CLASS app_t;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Mode of operation of SingleApplication.
|
||||
|
|
@ -90,7 +83,7 @@ public:
|
|||
* @see See the corresponding QAPPLICATION_CLASS constructor for reference
|
||||
*/
|
||||
explicit SingleApplication (int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 100);
|
||||
~SingleApplication ();
|
||||
virtual ~SingleApplication ();
|
||||
|
||||
/**
|
||||
* @brief Returns if the instance is the primary instance
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "app/App.hpp"
|
||||
#include "app/Logger.hpp"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue