Finally fixing the single instance for AppImage

This commit is contained in:
Vojtech Bubnik 2021-01-11 11:41:22 +01:00
parent a900b7767b
commit d46a756b98

View File

@ -260,10 +260,21 @@ bool instance_check(int argc, char** argv, bool app_config_single_instance)
#ifdef __linux #ifdef __linux
// If executed by an AppImage, start the AppImage, not the main process. // If executed by an AppImage, start the AppImage, not the main process.
// see https://docs.appimage.org/packaging-guide/environment-variables.html#id2 // see https://docs.appimage.org/packaging-guide/environment-variables.html#id2
const char *appimage_binary = std::getenv("APPIMAGE"); const char *appimage_env = std::getenv("APPIMAGE");
if (appimage_binary) bool appimage_env_valid = false;
hashed_path = std::hash<std::string>{}(boost::filesystem::canonical(boost::filesystem::system_complete(appimage_binary, ec).string())); if (appimage_env) {
if (ec.value() > 0) try {
auto appimage_path = boost::filesystem::canonical(boost::filesystem::path(appimage_env));
if (boost::filesystem::exists(appimage_path)) {
hashed_path = std::hash<std::string>{}(appimage_path.string());
appimage_env_valid = true;
}
} catch (std::exception &) {
}
if (! appimage_env_valid)
BOOST_LOG_TRIVIAL(error) << "APPIMAGE environment variable was set, but it does not point to a valid file: " << appimage_env;
}
if (! appimage_env_valid)
#endif // __linux #endif // __linux
hashed_path = std::hash<std::string>{}(boost::filesystem::canonical(boost::filesystem::system_complete(argv[0]), ec).string()); hashed_path = std::hash<std::string>{}(boost::filesystem::canonical(boost::filesystem::system_complete(argv[0]), ec).string());
if (ec.value() > 0) { // canonical was not able to find the executable (can happen with appimage on some systems. Does it fail on Fuse file systems?) if (ec.value() > 0) { // canonical was not able to find the executable (can happen with appimage on some systems. Does it fail on Fuse file systems?)