Skip to content

Commit

Permalink
Switch to KDSingleApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
deepbluev7 committed Nov 20, 2023
1 parent 6f52686 commit 8ea03e4
Show file tree
Hide file tree
Showing 36 changed files with 69 additions and 2,844 deletions.
1 change: 1 addition & 0 deletions .ci/macos/build.sh
Expand Up @@ -20,6 +20,7 @@ cmake -GNinja -S. -Bbuild \
-DHUNTER_ENABLED=ON -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DHUNTER_CONFIGURATION_TYPES=RelWithDebInfo \
-DUSE_BUNDLED_OPENSSL=ON \
-DUSE_BUNDLED_KDSINGLEAPPLICATION=ON \
-DQt6_DIR=${QT_BASEPATH}/lib/cmake \
-DCI_BUILD=ON
cmake --build build
Expand Down
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Expand Up @@ -25,7 +25,7 @@ build-clazy:
- export CMAKE_BUILD_PARALLEL_LEVEL=$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l)
- cmake -GNinja -H. -Bbuild
-DCMAKE_INSTALL_PREFIX=.deps/usr
-DHUNTER_ENABLED=OFF -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON -DUSE_BUNDLED_MTXCLIENT=ON -DUSE_BUNDLED_COEURL=ON -DUSE_BUNDLED_OLM=ON -DUSE_BUNDLED_QTKEYCHAIN=ON
-DHUNTER_ENABLED=OFF -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON -DUSE_BUNDLED_MTXCLIENT=ON -DUSE_BUNDLED_COEURL=ON -DUSE_BUNDLED_OLM=ON -DUSE_BUNDLED_QTKEYCHAIN=ON -DUSE_BUNDLED_KDSINGLEAPPLICATION=ON
-DVOIP=OFF
-DCMAKE_BUILD_TYPE=Release
-DCI_BUILD=ON -DFETCHCONTENT_QUIET=OFF -DCMAKE_CXX_COMPILER=clazy
Expand Down Expand Up @@ -62,7 +62,7 @@ build-clazy:
- cmake -GNinja -H. -Bbuild
-DCMAKE_INSTALL_PREFIX=.deps/usr
-DHUNTER_ROOT="../.hunter"
-DHUNTER_ENABLED=ON -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON -DUSE_BUNDLED_LMDB=OFF -DUSE_BUNDLED_QTKEYCHAIN=OFF
-DHUNTER_ENABLED=ON -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON -DUSE_BUNDLED_LMDB=OFF -DUSE_BUNDLED_QTKEYCHAIN=OFF -DUSE_BUNDLED_KDSINGLEAPPLICATION=ON
-DVOIP=OFF
-DCMAKE_BUILD_TYPE=Release -DHUNTER_CONFIGURATION_TYPES=Release
-DCI_BUILD=ON -DFETCHCONTENT_QUIET=OFF
Expand Down Expand Up @@ -128,7 +128,7 @@ build-tw:
- export PATH="/usr/lib64/ccache:${PATH}"
- cmake -GNinja -H. -Bbuild
-DCMAKE_INSTALL_PREFIX=.deps/usr
-DUSE_BUNDLED_MTXCLIENT=ON -DUSE_BUNDLED_COEURL=ON -DUSE_BUNDLED_LMDBXX=ON
-DUSE_BUNDLED_MTXCLIENT=ON -DUSE_BUNDLED_COEURL=ON -DUSE_BUNDLED_LMDBXX=ON -DUSE_BUNDLED_KDSINGLEAPPLICATION=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_FLAGS="-Wno-error=array-bounds"
-DCI_BUILD=ON -DFETCHCONTENT_QUIET=OFF
Expand Down Expand Up @@ -283,7 +283,7 @@ build-flatpak:
- cmake -GNinja -H. -Bbuild
-DCMAKE_INSTALL_PREFIX=/usr
-DHUNTER_ROOT=".hunter"
-DHUNTER_ENABLED=ON -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON -DUSE_BUNDLED_LMDB=OFF -DUSE_BUNDLED_QTKEYCHAIN=OFF -DUSE_BUNDLED_LIBEVENT=OFF
-DHUNTER_ENABLED=ON -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON -DUSE_BUNDLED_LMDB=OFF -DUSE_BUNDLED_QTKEYCHAIN=OFF -DUSE_BUNDLED_LIBEVENT=OFF -DUSE_BUNDLED_KDSINGLEAPPLICATION=ON
-DVOIP=OFF -DMAN=OFF
-DCMAKE_BUILD_TYPE=Release -DHUNTER_CONFIGURATION_TYPES=Release
-DCI_BUILD=ON -DFETCHCONTENT_QUIET=OFF
Expand Down
32 changes: 21 additions & 11 deletions CMakeLists.txt
Expand Up @@ -63,6 +63,7 @@ option(USE_BUNDLED_COEURL "Use a bundled version of the Curl wrapper"
option(USE_BUNDLED_LIBEVENT "Use the bundled version of libevent." ${HUNTER_ENABLED})
option(USE_BUNDLED_LIBCURL "Use the bundled version of libcurl." ${HUNTER_ENABLED})
option(USE_BUNDLED_RE2 "Use the bundled version of re2." ${HUNTER_ENABLED})
option(USE_BUNDLED_KDSINGLEAPPLICATION "Use the bundled version of KDSingleApplication." ${HUNTER_ENABLED})
option(USE_BUNDLED_CPPHTTPLIB "Use the bundled version of cpp-httplib." ON)
option(USE_BUNDLED_BLURHASH "Use the bundled version of blurhash." ON)

Expand Down Expand Up @@ -251,17 +252,26 @@ if(USE_BUNDLED_QTKEYCHAIN)
GIT_REPOSITORY https://github.com/frankosterfeld/qtkeychain.git
GIT_TAG v0.14.0
)
if(BUILD_SHARED_LIBS)
set(QTKEYCHAIN_STATIC OFF CACHE INTERNAL "")
else()
set(QTKEYCHAIN_STATIC ON CACHE INTERNAL "")
endif()
set(BUILD_TEST_APPLICATION OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(qt6keychain)
else()
find_package(Qt6Keychain REQUIRED)
endif()

if(USE_BUNDLED_KDSINGLEAPPLICATION)
include(FetchContent)
set(KDSingleApplication_QT6 ON CACHE BOOL INTERNAL)
set(KDSingleApplication_EXAMPLES OFF CACHE BOOL INTERNAL)
FetchContent_Declare(
kdsingleapplication
GIT_REPOSITORY https://github.com/KDAB/KDSingleApplication.git
GIT_TAG v1.0.0
)
FetchContent_MakeAvailable(kdsingleapplication)
else()
find_package(KDSingleApplication-qt6 REQUIRED)
endif()

if(Qt6Widgets_FOUND)
if(Qt6Widgets_VERSION VERSION_LESS 6.5.0)
message(STATUS "Qt version ${Qt6Widgets_VERSION}")
Expand Down Expand Up @@ -613,10 +623,6 @@ if(X11 AND NOT WIN32 AND NOT APPLE AND NOT HAIKU)
pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb xcb-ewmh)
endif()

# single instance functionality
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
add_subdirectory(third_party/SingleApplication-3.3.2/)

feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)

# this must be defined here to make the moc work properly
Expand Down Expand Up @@ -867,6 +873,9 @@ endif()
if(USE_BUNDLED_QTKEYCHAIN)
target_include_directories(nheko PRIVATE ${qt6keychain_SOURCE_DIR} ${qt6keychain_BINARY_DIR})
endif()
if(USE_BUNDLED_KDSINGLEAPPLICATION)
target_include_directories(nheko PRIVATE ${kdsingleapplication_SOURCE_DIR} ${kdsingleapplication_BINARY_DIR})
endif()

if(NOT JSON_ImplicitConversions)
set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
Expand All @@ -888,10 +897,11 @@ target_link_libraries(nheko PRIVATE
Qt::QmlPrivate
Qt::QuickControls2
qt6keychain
KDAB::kdsingleapplication
nlohmann_json::nlohmann_json
lmdbxx::lmdbxx
liblmdb::lmdb
SingleApplication::SingleApplication)
liblmdb::lmdb)


if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
target_precompile_headers(nheko
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -251,6 +251,7 @@ KDE has similar plugins, that can extend the supported image types even more.
- [libnice](https://gitlab.freedesktop.org/libnice/libnice)
- XCB, XCB-EWMH: For screensharing support on X11 and setting window roles. Can be disabled with `-DSCREENSHARE_X11=OFF`.
- [qtkeychain](https://github.com/frankosterfeld/qtkeychain) (You need at least version 0.12 for proper Gnome Keychain support. The bundled version requires libsecret, unless you pass `-DLIBSECRET_SUPPORT=OFF`.)
- [KDSingleApplication](https://github.com/KDAB/KDSingleApplication) (1.0 or greater with Qt6 support)
- A compiler that supports C++ 20:
- Clang 16 (Only clazy 16 is tested in CI)
- GCC 11 (tested on Gitlab CI)
Expand All @@ -276,6 +277,7 @@ The bundle flags are currently:
- USE_BUNDLED_COEURL
- USE_BUNDLED_LIBCURL
- USE_BUNDLED_LIBEVENT
- USE_BUNDLED_KDSINGLEAPPLICATION

A note on bundled OpenSSL: You need to explicitly enable it and it will not be using your system certificate directory by default, if you enable it. You need to override that at runtime with the SSL_CERT_FILE variable. On Windows it will still be using your system certificates though, since it loads them from the system store instead of the OpenSSL directory.

Expand Down Expand Up @@ -442,7 +444,6 @@ Here are some screen shots to get a feel for the UI, but things will probably ch

### Third party

- [Single Application for Qt](https://github.com/itay-grudev/SingleApplication)
- [Fluent Icons](https://github.com/microsoft/fluentui-system-icons)

[Matrix]:https://matrix.org
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -45,7 +45,7 @@ build_script:
# Build nheko
- cmake -G "Visual Studio 17 2022" -A x64 -H. -Bbuild
-DHUNTER_ROOT="C:\hunter"
-DHUNTER_ENABLED=ON -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON
-DHUNTER_ENABLED=ON -DBUILD_SHARED_LIBS=OFF -DUSE_BUNDLED_OPENSSL=ON -DUSE_BUNDLED_KDSINGLEAPPLICATION=ON
-DCMAKE_BUILD_TYPE=Release -DHUNTER_CONFIGURATION_TYPES=Release

- cmake --build build --config Release
Expand Down
11 changes: 9 additions & 2 deletions im.nheko.Nheko.yaml
Expand Up @@ -16,8 +16,6 @@ finish-args:
- --talk-name=org.freedesktop.secrets
- --talk-name=org.freedesktop.StatusNotifierItem
- --talk-name=org.kde.*
# needed for SingleApplication to work
- --allow=per-app-dev-shm
cleanup:
- /include
- /lib/pkgconfig
Expand Down Expand Up @@ -159,6 +157,15 @@ modules:
- sha256: d69f9deb6a75e2580465c6c4c5111b89c4dc2fa94e3a85fcd2ffcd9a143d9273
type: archive
url: https://github.com/nlohmann/json/archive/v3.11.2.tar.gz
- config-opts:
- -DKDSingleApplication_EXAMPLES=OFF
- -DKDSingleApplication_QT6=ON
buildsystem: cmake
name: kdsingleapplication
sources:
- sha256: c92355dc10f3ebd39363458458fb5bdd9662e080cf77d91f0437763c4d936520
type: archive
url: https://github.com/KDAB/KDSingleApplication/releases/download/v1.0.0/kdsingleapplication-1.0.0.tar.gz
- buildsystem: simple
build-commands:
- make static
Expand Down
55 changes: 31 additions & 24 deletions src/main.cpp
Expand Up @@ -20,14 +20,15 @@
#include <QStandardPaths>
#include <QTranslator>

#include <kdsingleapplication.h>

#include "Cache.h"
#include "ChatPage.h"
#include "Logging.h"
#include "MainWindow.h"
#include "MatrixClient.h"
#include "Utils.h"
#include "config/nheko.h"
#include "singleapplication.h"

#if defined(Q_OS_MAC)
#include "emoji/MacHelper.h"
Expand Down Expand Up @@ -196,14 +197,11 @@ main(int argc, char *argv[])
}
}

SingleApplication app(argc,
argv,
true,
SingleApplication::Mode::User | SingleApplication::Mode::ExcludeAppPath |
SingleApplication::Mode::ExcludeAppVersion |
SingleApplication::Mode::SecondaryNotification,
100,
userdata == QLatin1String("default") ? QLatin1String("") : userdata);
QApplication app(argc, argv);

KDSingleApplication singleapp(
QStringLiteral("im.nheko.nheko-%1")
.arg(userdata == QLatin1String("default") ? QLatin1String("") : userdata));

QCommandLineParser parser;
parser.addHelpOption();
Expand Down Expand Up @@ -249,11 +247,19 @@ main(int argc, char *argv[])

// This check needs to happen _after_ process(), so that we actually print help for --help when
// Nheko is already running.
if (app.isSecondary()) {
std::cout << "Sending Matrix URL to main application: " << matrixUri.toStdString()
<< std::endl;
if (!singleapp.isPrimaryInstance()) {
std::cout << "Activating main app (instead of opening it a second time)." << std::endl;
// open uri in main instance
app.sendMessage(matrixUri.toUtf8());
// TODO(Nico): Send also an activation token.
singleapp.sendMessage("activate");

if (!matrixUri.isEmpty()) {
std::cout << "Sending Matrix URL to main application: " << matrixUri.toStdString()
<< std::endl;
// open uri in main instance
singleapp.sendMessage(matrixUri.toUtf8());
}

return 0;
}

Expand Down Expand Up @@ -384,27 +390,28 @@ main(int argc, char *argv[])
nhlog::net()->debug("bye");
}
});
QObject::connect(&app, &SingleApplication::instanceStarted, &w, [&w]() {
w.show();
w.raise();
w.requestActivate();
});

// It seems like handling the message in a blocking manner is a no-go. I have no idea how to
// fix that, so just use a queued connection for now... (ASAN does not cooperate and just
// hides the crash D:)
QObject::connect(
&app,
&SingleApplication::receivedMessage,
&singleapp,
&KDSingleApplication::messageReceived,
ChatPage::instance(),
[&](quint32, QByteArray message) {
QString m = QString::fromUtf8(message);
ChatPage::instance()->handleMatrixUri(m);
[&](QByteArray message) {
if (message.isEmpty() || message.startsWith("activate")) {
w.show();
w.raise();
w.requestActivate();
} else {
QString m = QString::fromUtf8(message);
ChatPage::instance()->handleMatrixUri(m);
}
},
Qt::QueuedConnection);

QMetaObject::Connection uriConnection;
if (app.isPrimary() && !matrixUri.isEmpty()) {
if (singleapp.isPrimaryInstance() && !matrixUri.isEmpty()) {
uriConnection = QObject::connect(ChatPage::instance(),
&ChatPage::contentLoaded,
ChatPage::instance(),
Expand Down
1 change: 0 additions & 1 deletion third_party/SingleApplication-3.3.2/.github/FUNDING.yml

This file was deleted.

87 changes: 0 additions & 87 deletions third_party/SingleApplication-3.3.2/.github/workflows/build.yml

This file was deleted.

16 changes: 0 additions & 16 deletions third_party/SingleApplication-3.3.2/.gitignore

This file was deleted.

0 comments on commit 8ea03e4

Please sign in to comment.