Upstream Flathub patches (#7728)

This commit is contained in:
louib 2022-04-04 19:04:18 -04:00 committed by GitHub
parent 31db3c325d
commit 7cd824ae1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 169 additions and 20 deletions

View file

@ -28,6 +28,7 @@
#include <QJsonObject>
#include <QMessageBox>
#include <QProcessEnvironment>
#include <QRegularExpression>
#include <QSettings>
#include <QStandardPaths>
@ -214,12 +215,20 @@ QString NativeMessageInstaller::getNativeMessagePath(SupportedBrowsers browser)
basePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
}
return QStringLiteral("%1/%2_%3.json").arg(basePath, HOST_NAME, getBrowserName(browser));
#elif defined(KEEPASSXC_DIST_FLATPAK)
// Flatpak sandboxes do not have access to the XDG_DATA_HOME and XDG_CONFIG_HOME variables
// defined in the host, so we must hardcode them here.
if (browser == SupportedBrowsers::TOR_BROWSER) {
basePath = QDir::homePath() + "/.local/share";
} else if (browser == SupportedBrowsers::FIREFOX) {
basePath = QDir::homePath();
} else {
basePath = QDir::homePath() + "/.config";
}
#elif defined(Q_OS_LINUX)
if (browser == SupportedBrowsers::TOR_BROWSER) {
// Tor Browser launcher stores its config in ~/.local/share/...
basePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
} else if (browser == SupportedBrowsers::FIREFOX) {
// Firefox stores its config in ~/
basePath = QDir::homePath();
} else {
basePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
@ -234,6 +243,34 @@ QString NativeMessageInstaller::getNativeMessagePath(SupportedBrowsers browser)
return QStringLiteral("%1%2/%3.json").arg(basePath, getTargetPath(browser), HOST_NAME);
}
#ifdef KEEPASSXC_DIST_FLATPAK
/** Constructs a host accessible proxy path for use with flatpak
*
* @return path Path to host accessible wrapper script (org.keepassxc.KeePassXC)
*/
QString constructFlatpakPath()
{
// Find and extract the host flatpak data directory (in /var)
QString path;
QSettings settings("/.flatpak-info", QSettings::IniFormat);
settings.beginGroup("Instance");
QString appPath = settings.value("app-path").toString();
QRegularExpression re("^((?:/[\\.\\w-]*)+)+/app");
QRegularExpressionMatch match = re.match(appPath);
if (match.hasMatch()) {
// Construct a proxy path that should work with all flatpak installations
path = match.captured(1) + "/exports/bin/" + "org.keepassxc.KeePassXC";
} else {
// Fallback to the most common and default flatpak installation path
path = "/var/lib/flatpak/exports/bin/org.keepassxc.KeePassXC";
}
settings.endGroup();
return path;
}
#endif
/**
* Gets the path to keepassxc-proxy binary
*
@ -247,8 +284,10 @@ QString NativeMessageInstaller::getProxyPath() const
}
QString path;
#ifdef KEEPASSXC_DIST_APPIMAGE
#if defined(KEEPASSXC_DIST_APPIMAGE)
path = QProcessEnvironment::systemEnvironment().value("APPIMAGE");
#elif defined(KEEPASSXC_DIST_FLATPAK)
path = constructFlatpakPath();
#else
path = QCoreApplication::applicationDirPath() + QStringLiteral("/keepassxc-proxy");
#ifdef Q_OS_WIN