mirror of https://github.com/procxx/kepka.git
Add methods to detect appimage, static binary and forced gtk dialog
This commit is contained in:
parent
422831fa79
commit
7f890122e6
|
@ -194,30 +194,31 @@ bool GenerateDesktopFile(
|
||||||
|
|
||||||
QFile target(targetFile);
|
QFile target(targetFile);
|
||||||
if (target.open(QIODevice::WriteOnly)) {
|
if (target.open(QIODevice::WriteOnly)) {
|
||||||
#ifdef DESKTOP_APP_USE_PACKAGED
|
if (IsStaticBinary() || InAppImage()) {
|
||||||
fileText = fileText.replace(
|
fileText = fileText.replace(
|
||||||
QRegularExpression(
|
QRegularExpression(
|
||||||
qsl("^Exec=(.*) -- %u$"),
|
qsl("^TryExec=.*$"),
|
||||||
QRegularExpression::MultilineOption),
|
QRegularExpression::MultilineOption),
|
||||||
qsl("Exec=\\1")
|
qsl("TryExec=")
|
||||||
+ (args.isEmpty() ? QString() : ' ' + args));
|
+ QFile::encodeName(cExeDir() + cExeName())
|
||||||
#else // DESKTOP_APP_USE_PACKAGED
|
.replace('\\', qsl("\\\\")));
|
||||||
fileText = fileText.replace(
|
fileText = fileText.replace(
|
||||||
QRegularExpression(
|
QRegularExpression(
|
||||||
qsl("^TryExec=.*$"),
|
qsl("^Exec=.*$"),
|
||||||
QRegularExpression::MultilineOption),
|
QRegularExpression::MultilineOption),
|
||||||
qsl("TryExec=")
|
qsl("Exec=")
|
||||||
+ QFile::encodeName(cExeDir() + cExeName())
|
+ EscapeShell(QFile::encodeName(cExeDir() + cExeName()))
|
||||||
.replace('\\', qsl("\\\\")));
|
.replace('\\', qsl("\\\\"))
|
||||||
fileText = fileText.replace(
|
+ (args.isEmpty() ? QString() : ' ' + args));
|
||||||
QRegularExpression(
|
} else {
|
||||||
qsl("^Exec=.*$"),
|
fileText = fileText.replace(
|
||||||
QRegularExpression::MultilineOption),
|
QRegularExpression(
|
||||||
qsl("Exec=")
|
qsl("^Exec=(.*) -- %u$"),
|
||||||
+ EscapeShell(QFile::encodeName(cExeDir() + cExeName()))
|
QRegularExpression::MultilineOption),
|
||||||
.replace('\\', qsl("\\\\"))
|
qsl("Exec=\\1")
|
||||||
+ (args.isEmpty() ? QString() : ' ' + args));
|
+ (args.isEmpty() ? QString() : ' ' + args));
|
||||||
#endif // !DESKTOP_APP_USE_PACKAGED
|
}
|
||||||
|
|
||||||
target.write(fileText.toUtf8());
|
target.write(fileText.toUtf8());
|
||||||
target.close();
|
target.close();
|
||||||
|
|
||||||
|
@ -249,6 +250,27 @@ bool InSnap() {
|
||||||
return Snap;
|
return Snap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InAppImage() {
|
||||||
|
static const auto AppImage = qEnvironmentVariableIsSet("APPIMAGE");
|
||||||
|
return AppImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsStaticBinary() {
|
||||||
|
#ifdef DESKTOP_APP_USE_PACKAGED
|
||||||
|
return false;
|
||||||
|
#else // DESKTOP_APP_USE_PACKAGED
|
||||||
|
return true;
|
||||||
|
#endif // !DESKTOP_APP_USE_PACKAGED
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsGtkFileDialogForced() {
|
||||||
|
#ifdef TDESKTOP_FORCE_GTK_FILE_DIALOG
|
||||||
|
return true;
|
||||||
|
#else // TDESKTOP_FORCE_GTK_FILE_DIALOG
|
||||||
|
return false;
|
||||||
|
#endif // !TDESKTOP_FORCE_GTK_FILE_DIALOG
|
||||||
|
}
|
||||||
|
|
||||||
bool IsXDGDesktopPortalPresent() {
|
bool IsXDGDesktopPortalPresent() {
|
||||||
#ifdef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
#ifdef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||||
static const auto XDGDesktopPortalPresent = false;
|
static const auto XDGDesktopPortalPresent = false;
|
||||||
|
@ -266,7 +288,11 @@ bool UseXDGDesktopPortal() {
|
||||||
const auto envVar = qEnvironmentVariableIsSet("TDESKTOP_USE_PORTAL");
|
const auto envVar = qEnvironmentVariableIsSet("TDESKTOP_USE_PORTAL");
|
||||||
const auto portalPresent = IsXDGDesktopPortalPresent();
|
const auto portalPresent = IsXDGDesktopPortalPresent();
|
||||||
|
|
||||||
return (DesktopEnvironment::IsKDE() || envVar) && portalPresent;
|
return (
|
||||||
|
DesktopEnvironment::IsKDE()
|
||||||
|
|| InSnap()
|
||||||
|
|| envVar
|
||||||
|
) && portalPresent;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
return UsePortal;
|
return UsePortal;
|
||||||
|
@ -288,7 +314,7 @@ QString ProcessNameByPID(const QString &pid) {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CurrentExecutablePath(int argc, char *argv[]) {
|
QString RealExecutablePath(int argc, char *argv[]) {
|
||||||
const auto processName = ProcessNameByPID(qsl("self"));
|
const auto processName = ProcessNameByPID(qsl("self"));
|
||||||
|
|
||||||
// Fallback to the first command line argument.
|
// Fallback to the first command line argument.
|
||||||
|
@ -299,6 +325,25 @@ QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||||
: QString();
|
: QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||||
|
if (InAppImage()) {
|
||||||
|
const auto appimagePath = QString::fromUtf8(qgetenv("APPIMAGE"));
|
||||||
|
const auto appimagePathList = appimagePath.split('/');
|
||||||
|
|
||||||
|
if (qEnvironmentVariableIsSet("ARGV0")
|
||||||
|
&& appimagePathList.size() >= 5
|
||||||
|
&& appimagePathList[1] == qstr("run")
|
||||||
|
&& appimagePathList[2] == qstr("user")
|
||||||
|
&& appimagePathList[4] == qstr("appimagelauncherfs")) {
|
||||||
|
return QString::fromUtf8(qgetenv("ARGV0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return appimagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RealExecutablePath(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
QString AppRuntimeDirectory() {
|
QString AppRuntimeDirectory() {
|
||||||
static const auto RuntimeDirectory = [&] {
|
static const auto RuntimeDirectory = [&] {
|
||||||
auto runtimeDir = QStandardPaths::writableLocation(
|
auto runtimeDir = QStandardPaths::writableLocation(
|
||||||
|
@ -356,6 +401,20 @@ QString GetLauncherBasename() {
|
||||||
.arg(cExeName());
|
.arg(cExeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (InAppImage()) {
|
||||||
|
const auto appimagePath = qsl("file://%1%2")
|
||||||
|
.arg(cExeDir())
|
||||||
|
.arg(cExeName())
|
||||||
|
.toUtf8();
|
||||||
|
|
||||||
|
char md5Hash[33] = { 0 };
|
||||||
|
hashMd5Hex(appimagePath.constData(), appimagePath.size(), md5Hash);
|
||||||
|
|
||||||
|
return qsl("appimagekit_%1-%2")
|
||||||
|
.arg(md5Hash)
|
||||||
|
.arg(AppName.utf16().replace(' ', '_'));
|
||||||
|
}
|
||||||
|
|
||||||
const auto possibleBasenames = std::vector<QString>{
|
const auto possibleBasenames = std::vector<QString>{
|
||||||
qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)),
|
qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)),
|
||||||
qsl("Telegram")
|
qsl("Telegram")
|
||||||
|
@ -564,6 +623,10 @@ namespace Platform {
|
||||||
void start() {
|
void start() {
|
||||||
LOG(("Launcher filename: %1").arg(GetLauncherFilename()));
|
LOG(("Launcher filename: %1").arg(GetLauncherFilename()));
|
||||||
|
|
||||||
|
if (InAppImage()) {
|
||||||
|
qputenv("LIBGL_ALWAYS_INDIRECT", "1");
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TDESKTOP_USE_FONTCONFIG_FALLBACK
|
#ifdef TDESKTOP_USE_FONTCONFIG_FALLBACK
|
||||||
FallbackFontConfig();
|
FallbackFontConfig();
|
||||||
#endif // TDESKTOP_USE_FONTCONFIG_FALLBACK
|
#endif // TDESKTOP_USE_FONTCONFIG_FALLBACK
|
||||||
|
@ -571,21 +634,24 @@ void start() {
|
||||||
qputenv("PULSE_PROP_application.name", AppName.utf8());
|
qputenv("PULSE_PROP_application.name", AppName.utf8());
|
||||||
qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1());
|
qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1());
|
||||||
|
|
||||||
#ifdef TDESKTOP_FORCE_GTK_FILE_DIALOG
|
if(IsStaticBinary()
|
||||||
LOG(("Checking for XDG Desktop Portal..."));
|
|| InAppImage()
|
||||||
// this can give us a chance to use a proper file dialog for current session
|
|| InSnap()
|
||||||
if (IsXDGDesktopPortalPresent()) {
|
|| IsGtkFileDialogForced()) {
|
||||||
LOG(("XDG Desktop Portal is present!"));
|
LOG(("Checking for XDG Desktop Portal..."));
|
||||||
if (UseXDGDesktopPortal()) {
|
// this can give us a chance to use a proper file dialog for current session
|
||||||
LOG(("Usage of XDG Desktop Portal is enabled."));
|
if (IsXDGDesktopPortalPresent()) {
|
||||||
qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal");
|
LOG(("XDG Desktop Portal is present!"));
|
||||||
|
if (UseXDGDesktopPortal()) {
|
||||||
|
LOG(("Usage of XDG Desktop Portal is enabled."));
|
||||||
|
qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal");
|
||||||
|
} else {
|
||||||
|
LOG(("Usage of XDG Desktop Portal is disabled."));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG(("Usage of XDG Desktop Portal is disabled."));
|
LOG(("XDG Desktop Portal is not present :("));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
LOG(("XDG Desktop Portal is not present :("));
|
|
||||||
}
|
}
|
||||||
#endif // TDESKTOP_FORCE_GTK_FILE_DIALOG
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void finish() {
|
void finish() {
|
||||||
|
|
|
@ -22,11 +22,15 @@ inline void SetWatchingMediaKeys(bool watching) {
|
||||||
|
|
||||||
bool InSandbox();
|
bool InSandbox();
|
||||||
bool InSnap();
|
bool InSnap();
|
||||||
|
bool InAppImage();
|
||||||
|
bool IsStaticBinary();
|
||||||
|
bool IsGtkFileDialogForced();
|
||||||
|
|
||||||
bool IsXDGDesktopPortalPresent();
|
bool IsXDGDesktopPortalPresent();
|
||||||
bool UseXDGDesktopPortal();
|
bool UseXDGDesktopPortal();
|
||||||
|
|
||||||
QString ProcessNameByPID(const QString &pid);
|
QString ProcessNameByPID(const QString &pid);
|
||||||
|
QString RealExecutablePath(int argc, char *argv[]);
|
||||||
QString CurrentExecutablePath(int argc, char *argv[]);
|
QString CurrentExecutablePath(int argc, char *argv[]);
|
||||||
|
|
||||||
QString AppRuntimeDirectory();
|
QString AppRuntimeDirectory();
|
||||||
|
|
Loading…
Reference in New Issue