diff --git a/src/slic3r/GUI/InstanceCheck.cpp b/src/slic3r/GUI/InstanceCheck.cpp index 100fd5c53..552b891c5 100644 --- a/src/slic3r/GUI/InstanceCheck.cpp +++ b/src/slic3r/GUI/InstanceCheck.cpp @@ -252,14 +252,20 @@ namespace instance_check_internal bool instance_check(int argc, char** argv, bool app_config_single_instance) { -#ifndef _WIN32 - boost::system::error_code ec; -#endif - std::size_t hashed_path = + std::size_t hashed_path; #ifdef _WIN32 - std::hash{}(boost::filesystem::system_complete(argv[0]).string()); + hashed_path = std::hash{}(boost::filesystem::system_complete(argv[0]).string()); #else - std::hash{}(boost::filesystem::canonical(boost::filesystem::system_complete(argv[0]), ec).string()); + boost::system::error_code ec; +#ifdef __linux + // If executed by an AppImage, start the AppImage, not the main process. + // see https://docs.appimage.org/packaging-guide/environment-variables.html#id2 + const char *appimage_binary = std::getenv("APPIMAGE"); + if (appimage_binary) + hashed_path = std::hash{}(boost::filesystem::canonical(boost::filesystem::system_complete(appimage_binary, ec).string()); + if (ec.value() > 0) +#endif // __linux + hashed_path = std::hash{}(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?) ec.clear(); // Compose path with boost canonical of folder and filename @@ -269,7 +275,7 @@ bool instance_check(int argc, char** argv, bool app_config_single_instance) hashed_path = std::hash{}(boost::filesystem::system_complete(argv[0]).string()); } } -#endif // win32 +#endif // _WIN32 std::string lock_name = std::to_string(hashed_path); GUI::wxGetApp().set_instance_hash(hashed_path);