Skip to content

Commit 79b5e03

Browse files
committed
Run shell on the Flatpak host
When Terminal is running on Flatpak we need to access the host system, otherwise the app is pretty useless. Closes: #36
1 parent 7d7d7a5 commit 79b5e03

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/lib/Session.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <QDir>
3636
#include <QFile>
3737
#include <QRegExp>
38+
#include <QStandardPaths>
3839
#include <QStringList>
3940
#include <QFile>
4041
#include <QtDebug>
@@ -330,13 +331,37 @@ void Session::run()
330331
// the background color is deemed dark or not
331332
QString backgroundColorHint = _hasDarkBackground ? "COLORFGBG=15;0" : "COLORFGBG=0;15";
332333

334+
QStringList environmentVars = _environment;
335+
environmentVars.append(backgroundColorHint);
336+
337+
// If we are running on Flatpak, we should have access to the host
338+
if (!QStandardPaths::locate(QStandardPaths::RuntimeLocation, QLatin1String("flatpak-info")).isEmpty()) {
339+
QStringList flatpakArgs;
340+
flatpakArgs << QLatin1String("--host") << QLatin1String("--watch-bus");
341+
342+
for (auto env : environmentVars)
343+
flatpakArgs << QStringLiteral("--env=%1").arg(env);
344+
345+
const QStringList whitelist = QStringList()
346+
<< QLatin1String("TERM") << QLatin1String("PATH")
347+
<< QLatin1String("DISPLAY") << QLatin1String("WAYLAND_DISPLAY");
348+
for (auto env : QProcessEnvironment::systemEnvironment().toStringList()) {
349+
if (whitelist.contains(env.split(QLatin1Char('=')).first()))
350+
flatpakArgs << QStringLiteral("--env=%1").arg(env);
351+
}
352+
353+
flatpakArgs << exec;
354+
exec = QLatin1String("/usr/bin/flatpak-spawn");
355+
arguments = flatpakArgs;
356+
}
357+
333358
/* if we do all the checking if this shell exists then we use it ;)
334359
* Dont know about the arguments though.. maybe youll need some more checking im not sure
335360
* However this works on Arch and FreeBSD now.
336361
*/
337362
int result = _shellProcess->start(exec,
338363
arguments,
339-
_environment << backgroundColorHint,
364+
environmentVars,
340365
windowId(),
341366
_addToUtmp);
342367

0 commit comments

Comments
 (0)