Skip to content

Commit 9b25b7f

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 9b25b7f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/lib/Session.cpp

+29-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,40 @@ 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 (const QString &envLine : environmentVars)
343+
flatpakArgs << QStringLiteral("--env=%1").arg(envLine);
344+
345+
QStringList whitelist;
346+
whitelist
347+
<< QLatin1String("TERM") << QLatin1String("PATH")
348+
<< QLatin1String("EDITOR") << QLatin1String("PS1")
349+
<< QLatin1String("DISPLAY") << QLatin1String("WAYLAND_DISPLAY");
350+
for (const QString &envName : whitelist) {
351+
const QString value = qEnvironmentVariable(qPrintable(envName));
352+
if (!value.isEmpty())
353+
flatpakArgs << QStringLiteral("--env=%1=%2").arg(envName).arg(value);
354+
}
355+
356+
flatpakArgs << exec;
357+
exec = QLatin1String("/usr/bin/flatpak-spawn");
358+
arguments = flatpakArgs;
359+
}
360+
333361
/* if we do all the checking if this shell exists then we use it ;)
334362
* Dont know about the arguments though.. maybe youll need some more checking im not sure
335363
* However this works on Arch and FreeBSD now.
336364
*/
337365
int result = _shellProcess->start(exec,
338366
arguments,
339-
_environment << backgroundColorHint,
367+
environmentVars,
340368
windowId(),
341369
_addToUtmp);
342370

0 commit comments

Comments
 (0)