Skip to content

Commit d76013f

Browse files
authored
Introduce some exit codes (flameshot-org#3321) (flameshot-org#4121)
* Reuse FlameshotDaemon::call in copyToClipboard * Introduce some exit codes (flameshot-org#3321)
1 parent c2d60c2 commit d76013f

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

data/man/man1/flameshot.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ cursor by default.
292292
Shows help for \fBflameshot screen\fR subcommand.
293293
.
294294
.\"----------------------------------------------------------------------------
295+
.SH RETURN VALUE
296+
Returns 0 on normal exit, 2 on screenshot aborted, 3 on dbus connection lost, 130 on SIGINT received, 143 on SIGTERM received.
297+
.
298+
.\"----------------------------------------------------------------------------
295299
.SH SEE ALSO
296300
.PP
297301
You may also find more detailed online documentation on upstream project homepage.

src/core/flameshot.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ class UploadHistory;
1919
class QHotkey;
2020
#endif
2121

22+
enum ErrCode : uint8_t
23+
{
24+
E_OK = 0,
25+
E_GENERAL,
26+
E_ABORTED,
27+
E_DBUSCONN,
28+
E_SIG_BASE = 128,
29+
E_SIGINT = E_SIG_BASE + 2,
30+
E_SIGTERM = E_SIG_BASE + 15,
31+
};
32+
2233
class Flameshot : public QObject
2334
{
2435
Q_OBJECT

src/core/flameshotdaemon.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@ void FlameshotDaemon::copyToClipboard(const QString& text,
182182
#else
183183
auto m = createMethodCall(QStringLiteral("attachTextToClipboard"));
184184
m << text << notification;
185-
186-
QDBusConnection sessionBus = QDBusConnection::sessionBus();
187-
checkDBusConnection(sessionBus);
188-
sessionBus.call(m);
185+
call(m);
189186
#endif
190187
}
191188

@@ -283,7 +280,7 @@ void FlameshotDaemon::quitIfIdle()
283280
return;
284281
}
285282
if (!m_hostingClipboard && m_widgets.isEmpty()) {
286-
qApp->exit(0);
283+
qApp->exit(E_OK);
287284
}
288285
}
289286

@@ -443,7 +440,7 @@ void FlameshotDaemon::checkDBusConnection(const QDBusConnection& connection)
443440
{
444441
if (!connection.isConnected()) {
445442
AbstractLogger::error() << tr("Unable to connect via DBus");
446-
qApp->exit(1);
443+
qApp->exit(E_DBUSCONN);
447444
}
448445
}
449446

src/core/signaldaemon.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "signaldaemon.h"
2+
#include "flameshot.h"
23
#include <QApplication>
34
#include <QSocketNotifier>
45
#include <csignal>
@@ -45,7 +46,7 @@ void SignalDaemon::handleSigTerm()
4546
char tmp = 0;
4647
::read(sigtermFd[1], &tmp, sizeof(tmp));
4748

48-
QApplication::quit();
49+
QApplication::exit(E_SIGTERM);
4950
snTerm->setEnabled(true);
5051
}
5152

@@ -56,7 +57,7 @@ void SignalDaemon::handleSigInt()
5657
char tmp = 0;
5758
::read(sigintFd[1], &tmp, sizeof(tmp));
5859

59-
QApplication::quit();
60+
QApplication::exit(E_SIGINT);
6061

6162
snInt->setEnabled(true);
6263
}

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int requestCaptureAndWait(const CaptureRequest& req)
7474
#else
7575
// if this instance is not daemon, make sure it exit after caputre finish
7676
if (FlameshotDaemon::instance() == nullptr && !Flameshot::instance()->haveExternalWidget()) {
77-
qApp->exit(0);
77+
qApp->exit(E_OK);
7878
}
7979
#endif
8080
});
@@ -85,7 +85,7 @@ int requestCaptureAndWait(const CaptureRequest& req)
8585
: AbstractLogger::Target::Default &
8686
~AbstractLogger::Target::Notification);
8787
AbstractLogger::info(logTarget) << "Screenshot aborted.";
88-
qApp->exit(1);
88+
qApp->exit(E_ABORTED);
8989
});
9090
return qApp->exec();
9191
}

0 commit comments

Comments
 (0)