Skip to content

Commit 0ccec75

Browse files
committed
Fix passing stdout data
1 parent b91eca4 commit 0ccec75

File tree

6 files changed

+10
-32
lines changed

6 files changed

+10
-32
lines changed

src/app/applicationexceptionhandler.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010

1111
void logException(const char *what)
1212
{
13-
if ( canUseStandardOutput() ) {
14-
QFile f;
15-
f.open(stderr, QIODevice::WriteOnly);
16-
f.write(what ? what : "Unknown exception");
17-
f.write("\n");
18-
f.close();
19-
}
13+
QFile f;
14+
f.open(stderr, QIODevice::WriteOnly);
15+
f.write(what ? what : "Unknown exception");
16+
f.write("\n");
17+
f.close();
2018

2119
log( QString("Exception: ") + what, LogError );
2220
}

src/app/clipboardserver.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ ClipboardServer::ClipboardServer(QApplication *app, const QString &sessionName)
9191
qApp->setLayoutDirection(QLocale().textDirection());
9292
} else {
9393
App::installTranslator();
94-
if ( canUseStandardOutput() ) {
95-
log( tr("CopyQ server is already running."), LogWarning );
96-
}
94+
log( tr("CopyQ server is already running."), LogWarning );
9795
exit(0);
9896
return;
9997
}

src/common/log.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ void logAlways(const QByteArray &msgText, const LogLevel level)
220220
const bool writtenToLogFile = writeLogFile(msg);
221221

222222
// Log to file and if needed to stderr.
223-
if ( (!writtenToLogFile || level <= LogWarning || hasLogLevel(LogDebug))
224-
&& canUseStandardOutput() )
225-
{
223+
if ( !writtenToLogFile || level <= LogWarning || hasLogLevel(LogDebug) ) {
226224
QFile ferr;
227225
ferr.open(stderr, QIODevice::WriteOnly);
228226
const auto simpleMsg = createSimpleLogMessage(msgText, level);
@@ -328,9 +326,3 @@ QByteArray &logLabel()
328326
static QByteArray label;
329327
return label;
330328
}
331-
332-
bool canUseStandardOutput()
333-
{
334-
static const bool useOutput = qEnvironmentVariableIsEmpty("COPYQ_NO_OUTPUT");
335-
return useOutput;
336-
}

src/common/log.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,3 @@ void log(const QByteArray &text, LogLevel level = LogNote);
3636
void setLogLabel(const QByteArray &name);
3737

3838
QByteArray &logLabel();
39-
40-
/// True if stdout and stderr can be used.
41-
bool canUseStandardOutput();

src/main.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int evaluate(
5454
const bool hasUncaughtException = result.isError() || scriptable.hasUncaughtException();
5555

5656
const auto output = scriptable.fromString(result.toString());
57-
if ( !output.isEmpty() && canUseStandardOutput() ) {
57+
if ( !output.isEmpty() ) {
5858
QFile f;
5959
if (hasUncaughtException)
6060
f.open(stderr, QIODevice::WriteOnly);
@@ -126,16 +126,9 @@ int startServer(int argc, char *argv[], QString sessionName)
126126

127127
void startServerInBackground(const QString &applicationPath, QString sessionName)
128128
{
129-
const bool couldUseStandardOutput = canUseStandardOutput();
130-
if (couldUseStandardOutput)
131-
qputenv("COPYQ_NO_OUTPUT", QByteArrayLiteral("1"));
132-
133129
const QStringList arguments{QStringLiteral("-s"), sessionName};
134130
const bool started = QProcess::startDetached(applicationPath, arguments);
135131

136-
if (!couldUseStandardOutput)
137-
qunsetenv("COPYQ_NO_OUTPUT");
138-
139132
if (!started)
140133
log("Failed to start the server", LogError);
141134
}

src/scriptable/scriptable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,7 +3442,7 @@ void Scriptable::print(const QByteArray &message)
34423442
{
34433443
if (m_action) {
34443444
m_action->appendOutput(message);
3445-
} else if ( canUseStandardOutput() ) {
3445+
} else {
34463446
QFile f;
34473447
f.open(stdout, QIODevice::WriteOnly);
34483448
f.write(message);
@@ -3453,7 +3453,7 @@ void Scriptable::printError(const QByteArray &message)
34533453
{
34543454
if (m_action) {
34553455
m_action->appendErrorOutput(message);
3456-
} else if ( canUseStandardOutput() ) {
3456+
} else {
34573457
QFile f;
34583458
f.open(stderr, QIODevice::WriteOnly);
34593459
f.write(message);

0 commit comments

Comments
 (0)