Skip to content

Commit

Permalink
Run shell on the Flatpak host
Browse files Browse the repository at this point in the history
When Terminal is running on Flatpak we need to access the host
system, otherwise the app is pretty useless.

Closes: #36
  • Loading branch information
plfiorini committed Apr 26, 2019
1 parent 7d7d7a5 commit 79b5e03
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/lib/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QStandardPaths>
#include <QStringList>
#include <QFile>
#include <QtDebug>
Expand Down Expand Up @@ -330,13 +331,37 @@ void Session::run()
// the background color is deemed dark or not
QString backgroundColorHint = _hasDarkBackground ? "COLORFGBG=15;0" : "COLORFGBG=0;15";

QStringList environmentVars = _environment;
environmentVars.append(backgroundColorHint);

// If we are running on Flatpak, we should have access to the host
if (!QStandardPaths::locate(QStandardPaths::RuntimeLocation, QLatin1String("flatpak-info")).isEmpty()) {
QStringList flatpakArgs;
flatpakArgs << QLatin1String("--host") << QLatin1String("--watch-bus");

for (auto env : environmentVars)
flatpakArgs << QStringLiteral("--env=%1").arg(env);

const QStringList whitelist = QStringList()
<< QLatin1String("TERM") << QLatin1String("PATH")
<< QLatin1String("DISPLAY") << QLatin1String("WAYLAND_DISPLAY");
for (auto env : QProcessEnvironment::systemEnvironment().toStringList()) {
if (whitelist.contains(env.split(QLatin1Char('=')).first()))
flatpakArgs << QStringLiteral("--env=%1").arg(env);
}

flatpakArgs << exec;
exec = QLatin1String("/usr/bin/flatpak-spawn");
arguments = flatpakArgs;
}

/* if we do all the checking if this shell exists then we use it ;)
* Dont know about the arguments though.. maybe youll need some more checking im not sure
* However this works on Arch and FreeBSD now.
*/
int result = _shellProcess->start(exec,
arguments,
_environment << backgroundColorHint,
environmentVars,
windowId(),
_addToUtmp);

Expand Down

0 comments on commit 79b5e03

Please sign in to comment.