diff --git a/src/lib/Session.cpp b/src/lib/Session.cpp index 49168b3..f993925 100644 --- a/src/lib/Session.cpp +++ b/src/lib/Session.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -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);