Replace SingleApplication with KDSingleApplication

This commit is contained in:
Jonas Kvinge
2023-05-03 23:05:21 +02:00
parent b861703dad
commit 919ff414e6
27 changed files with 703 additions and 1562 deletions

View File

@@ -972,7 +972,6 @@ link_directories(
${SQLITE_LIBRARY_DIRS}
${PROTOBUF_LIBRARY_DIRS}
${SINGLEAPPLICATION_LIBRARY_DIRS}
${SINGLECOREAPPLICATION_LIBRARY_DIRS}
)
if(HAVE_ICU)
@@ -1080,7 +1079,6 @@ target_include_directories(strawberry_lib PUBLIC
${CMAKE_SOURCE_DIR}/ext/libstrawberry-tagreader
${CMAKE_BINARY_DIR}/ext/libstrawberry-tagreader
${SINGLEAPPLICATION_INCLUDE_DIRS}
${SINGLECOREAPPLICATION_INCLUDE_DIRS}
)
target_link_libraries(strawberry_lib PUBLIC
@@ -1092,7 +1090,6 @@ target_link_libraries(strawberry_lib PUBLIC
${QT_LIBRARIES}
${Protobuf_LIBRARIES}
${SINGLEAPPLICATION_LIBRARIES}
${SINGLECOREAPPLICATION_LIBRARIES}
libstrawberry-common
libstrawberry-tagreader
)

View File

@@ -2330,9 +2330,7 @@ void MainWindow::PlaylistEditFinished(const int playlist_id, const QModelIndex &
}
void MainWindow::CommandlineOptionsReceived(const quint32 instanceId, const QByteArray &string_options) {
Q_UNUSED(instanceId);
void MainWindow::CommandlineOptionsReceived(const QByteArray &string_options) {
CommandlineOptions options;
options.Load(string_options);
@@ -2342,9 +2340,10 @@ void MainWindow::CommandlineOptionsReceived(const quint32 instanceId, const QByt
show();
activateWindow();
hidden_ = false;
return;
}
else
CommandlineOptionsReceived(options);
CommandlineOptionsReceived(options);
}

View File

@@ -272,7 +272,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void FocusSearchField();
public slots:
void CommandlineOptionsReceived(const quint32 instanceId, const QByteArray &string_options);
void CommandlineOptionsReceived(const QByteArray &string_options);
void Raise();
private:

View File

@@ -66,8 +66,7 @@
#include "core/logging.h"
#include <singleapplication.h>
#include <singlecoreapplication.h>
#include <kdsingleapplication.h>
#ifdef HAVE_QTSPARKLE
# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
@@ -148,15 +147,16 @@ int main(int argc, char *argv[]) {
{
// Only start a core application now, so we can check if there's another instance without requiring an X server.
// This MUST be done before parsing the commandline options so QTextCodec gets the right system locale for filenames.
SingleCoreApplication core_app(argc, argv, true, SingleCoreApplication::Mode::User | SingleCoreApplication::Mode::ExcludeAppVersion | SingleCoreApplication::Mode::ExcludeAppPath);
QCoreApplication core_app(argc, argv);
KDSingleApplication single_app(QCoreApplication::applicationName());
// Parse commandline options - need to do this before starting the full QApplication, so it works without an X server
if (!options.Parse()) return 1;
logging::SetLevels(options.log_levels());
if (core_app.isSecondary()) {
if (!single_app.isPrimaryInstance()) {
if (options.is_empty()) {
qLog(Info) << "Strawberry is already running - activating existing window (1)";
}
if (!core_app.sendMessage(options.Serialize(), 5000)) {
if (!single_app.sendMessage(options.Serialize())) {
qLog(Error) << "Could not send message to primary instance.";
}
return 0;
@@ -182,14 +182,13 @@ int main(int argc, char *argv[]) {
QGuiApplication::setQuitOnLastWindowClosed(false);
// important: Do not remove this.
// This must also be done as a SingleApplication, in case SingleCoreApplication was compiled with a different appdata.
SingleApplication a(argc, argv, true, SingleApplication::Mode::User | SingleApplication::Mode::ExcludeAppVersion | SingleApplication::Mode::ExcludeAppPath);
if (a.isSecondary()) {
QApplication a(argc, argv);
KDSingleApplication single_app(QCoreApplication::applicationName());
if (!single_app.isPrimaryInstance()) {
if (options.is_empty()) {
qLog(Info) << "Strawberry is already running - activating existing window (2)";
}
if (!a.sendMessage(options.Serialize(), 5000)) {
if (!single_app.sendMessage(options.Serialize())) {
qLog(Error) << "Could not send message to primary instance.";
}
return 0;
@@ -319,9 +318,10 @@ int main(int argc, char *argv[]) {
#ifdef HAVE_DBUS
QObject::connect(&mpris2, &mpris::Mpris2::RaiseMainWindow, &w, &MainWindow::Raise);
#endif
QObject::connect(&a, &SingleApplication::receivedMessage, &w, QOverload<quint32, const QByteArray&>::of(&MainWindow::CommandlineOptionsReceived));
QObject::connect(&single_app, &KDSingleApplication::messageReceived, &w, QOverload<const QByteArray&>::of(&MainWindow::CommandlineOptionsReceived));
int ret = QCoreApplication::exec();
return ret;
}