From f030b378f07ed01d003c6cbc47d4461cbf84a976 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Mon, 20 Sep 2021 14:41:02 +0200 Subject: 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 } -- cgit v1.2.1 From 7d366c7e837a7ba45c0cfc9261ffbeb607055e3d Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Mon, 20 Sep 2021 14:56:31 +0200 Subject: Use QByteArray instead of QString Co-authored-by: Hennadii Chernyshchyk --- singleapplication_p.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index 6b4aa51..7c87973 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -147,7 +147,7 @@ void SingleApplicationPrivate::genBlockServerName() #ifdef Q_OS_WIN appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); #else - QString appImagePath = qEnvironmentVariable( "APPIMAGE" ); + const QByteArray appImagePath = qgetenv( "APPIMAGE" ); if ( appImagePath.isEmpty() ) { // Not running as AppImage: use path to executable file appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); -- cgit v1.2.1 From a30128bef2f2b7d8026e447724e06826273461ea Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Mon, 20 Sep 2021 15:16:20 +0200 Subject: Compile fix Co-authored-by: Hennadii Chernyshchyk --- singleapplication_p.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index 7c87973..d0e3e8d 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -153,7 +153,7 @@ void SingleApplicationPrivate::genBlockServerName() appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); } else { // Running as AppImage: Use absolute path to AppImage file - appData.addData( appImagePath.toUtf8() ); + appData.addData( appImagePath ); } #endif } -- cgit v1.2.1 From 6aa2d348e54ca6c6268e1fb55b0d623fd565b13c Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 20 Sep 2021 16:22:02 +0300 Subject: Style and explanation improvements --- singleapplication_p.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index d0e3e8d..bce1c49 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -147,12 +147,12 @@ void SingleApplicationPrivate::genBlockServerName() #ifdef Q_OS_WIN appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); #else + // If the application is running as an AppImage then the APPIMAGE env var should be used + // instead of applicationPath() as each instance is launched with its own executable path const QByteArray appImagePath = qgetenv( "APPIMAGE" ); - if ( appImagePath.isEmpty() ) { - // Not running as AppImage: use path to executable file + 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 + } else { // Running as AppImage: Use absolute path to AppImage file appData.addData( appImagePath ); } #endif -- cgit v1.2.1 From a8aa298aa140e32ec5d9de0293587538a5d9d984 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 20 Sep 2021 16:25:15 +0300 Subject: v3.3.1 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7359727..4368d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Changelog If by accident I have forgotten to credit someone in the CHANGELOG, email me and I will fix it. +__3.3.1__ +--------- + +* Added support for _AppImage_ dynamic executable paths. - _Michael Klein_ + __3.3.0__ --------- -- cgit v1.2.1 From cc96fea921f9467aecaecad03bb823a60142b46f Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 20 Sep 2021 16:32:42 +0300 Subject: Update singleapplication_p.cpp --- singleapplication_p.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index bce1c49..4568573 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -146,7 +146,7 @@ void SingleApplicationPrivate::genBlockServerName() if( ! (options & SingleApplication::Mode::ExcludeAppPath) ){ #ifdef Q_OS_WIN appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); -#else +#elseif defined(Q_OS_LINUX) // If the application is running as an AppImage then the APPIMAGE env var should be used // instead of applicationPath() as each instance is launched with its own executable path const QByteArray appImagePath = qgetenv( "APPIMAGE" ); @@ -154,7 +154,9 @@ void SingleApplicationPrivate::genBlockServerName() appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); } else { // Running as AppImage: Use absolute path to AppImage file appData.addData( appImagePath ); - } + }; +#else + appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); #endif } -- cgit v1.2.1 From bca0b770eef70a5eb467f6104a5fc7c033871375 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 20 Sep 2021 16:37:01 +0300 Subject: Update singleapplication_p.cpp Co-authored-by: Hennadii Chernyshchyk --- singleapplication_p.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index 4568573..ce84d3c 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -144,7 +144,7 @@ void SingleApplicationPrivate::genBlockServerName() } if( ! (options & SingleApplication::Mode::ExcludeAppPath) ){ -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); #elseif defined(Q_OS_LINUX) // If the application is running as an AppImage then the APPIMAGE env var should be used -- cgit v1.2.1 From 9856adebd40e01e4f4190e98d61929377dc2d4b6 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 20 Sep 2021 16:38:28 +0300 Subject: Update singleapplication_p.cpp --- singleapplication_p.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index ce84d3c..1a061f2 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -146,7 +146,7 @@ void SingleApplicationPrivate::genBlockServerName() if( ! (options & SingleApplication::Mode::ExcludeAppPath) ){ #if defined(Q_OS_WIN) appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); -#elseif defined(Q_OS_LINUX) +#elif defined(Q_OS_LINUX) // If the application is running as an AppImage then the APPIMAGE env var should be used // instead of applicationPath() as each instance is launched with its own executable path const QByteArray appImagePath = qgetenv( "APPIMAGE" ); -- cgit v1.2.1