Skip to content

Commit 1f59ef5

Browse files
authored
Kdsingleapplication as SingleApplication alternative (flameshot-org#4032)
* Enable SingleApplication again (compile flag; enabled by default) * Enable SingleApplication again (compile flag; enabled by default) * Add KDSingleApplication as SingleApplication alternative * Cleanup: Removed /external/ subfolder * Update CMakeLists.txt * Remove SingleApplication; enable KDSingleApplication by default
1 parent 5601901 commit 1f59ef5

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

CMakeLists.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ set(RUN_IN_PLACE
8989
option(FLAMESHOT_DEBUG_CAPTURE "Enable mode to make debugging easier" OFF)
9090
option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF)
9191
option(GENERATE_TS "Regenerate translation source files" OFF)
92-
option(USE_SINGLEAPPLICATION "Use SingleApplication library" ON)
92+
option(USE_KDSINGLEAPPLICATION "Use KDSingleApplication library" ON)
9393
option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
9494
option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)
9595
option(DISABLE_UPDATE_CHECKER "Disable check for updates" OFF)
@@ -123,20 +123,18 @@ enable_sanitizers(project_options)
123123

124124
# allow for static analysis options include(cmake/StaticAnalyzers.cmake)
125125

126-
if(USE_SINGLEAPPLICATION)
127-
set(QAPPLICATION_CLASS
128-
QApplication
129-
CACHE STRING "Inheritance class for SingleApplication")
126+
if (USE_KDSINGLEAPPLICATION)
127+
set(KDSingleApplication_EXAMPLES OFF CACHE BOOL "Don't build the examples")
128+
set(KDSingleApplication_STATIC ON CACHE BOOL "Build static versions of the libraries")
130129

131130
FetchContent_Declare(
132-
singleApplication
133-
GIT_REPOSITORY https://github.com/itay-grudev/SingleApplication.git
134-
GIT_TAG v3.5.2
131+
kdsingleApplication
132+
GIT_REPOSITORY https://github.com/KDAB/KDSingleApplication.git
133+
GIT_TAG v1.2.0
135134
)
136-
FetchContent_MakeAvailable(SingleApplication)
135+
FetchContent_MakeAvailable(KDSingleApplication)
137136
endif()
138137

139-
140138
option(BUILD_STATIC_LIBS ON)
141139
option(BUILD_SHARED_LIBS OFF)
142140

src/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,13 @@ target_link_libraries(
214214
QtColorWidgets
215215
)
216216

217-
if (USE_SINGLEAPPLICATION)
218-
message(STATUS "SingleApplication is used!")
219-
add_compile_definitions(USE_SINGLEAPPLICATION=1)
217+
if (USE_KDSINGLEAPPLICATION)
218+
message(STATUS "KDSingleApplication is used!")
219+
add_compile_definitions(USE_KDSINGLEAPPLICATION=1)
220+
220221
target_link_libraries(
221222
flameshot
222-
SingleApplication::SingleApplication
223+
kdsingleapplication
223224
)
224225
endif()
225226

src/main.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
33

4-
#ifdef USE_SINGLEAPPLICATION
5-
#include "singleapplication.h"
4+
#ifdef USE_KDSINGLEAPPLICATION
5+
#include "kdsingleapplication.h"
66
#endif
77

88
#include "abstractlogger.h"
@@ -140,10 +140,16 @@ int main(int argc, char* argv[])
140140

141141
// no arguments, just launch Flameshot
142142
if (argc == 1) {
143-
#ifdef USE_SINGLEAPPLICATION
144-
SingleApplication app(argc, argv);
145-
#else
146143
QApplication app(argc, argv);
144+
145+
#ifdef USE_KDSINGLEAPPLICATION
146+
KDSingleApplication kdsa(QStringLiteral("flameshot"));
147+
148+
if (!kdsa.isPrimaryInstance()) {
149+
// AbstractLogger::warning()
150+
// << QStringLiteral("Closing second Flameshot instance!");
151+
return 0; // Quit
152+
}
147153
#endif
148154

149155
configureApp(true);

0 commit comments

Comments
 (0)