From f030b378f07ed01d003c6cbc47d4461cbf84a976 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Mon, 20 Sep 2021 14:41:02 +0200 Subject: [PATCH] Use AppImage path for hash when running as AppImage. When an application is launched as AppImage, each instance is launched from its own FUSE-mounted filesystem, so each instance has its own executable path. The AppImage runtime sets the environment variable APPIMAGE to the absolute path to the .AppImage file, so we can use the content of this variable instead of QApplication::applicationFilePath() when set. Closes #77, #137 --- singleapplication_p.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index 1339728..6b4aa51 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -147,7 +147,14 @@ void SingleApplicationPrivate::genBlockServerName() #ifdef Q_OS_WIN appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); #else - appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); + QString appImagePath = qEnvironmentVariable( "APPIMAGE" ); + if ( appImagePath.isEmpty() ) { + // Not running as AppImage: use path to executable file + appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); + } else { + // Running as AppImage: Use absolute path to AppImage file + appData.addData( appImagePath.toUtf8() ); + } #endif }