diff options
author | Vojtech Bubnik <bubnikv@gmail.com> | 2021-01-11 13:14:51 +0300 |
---|---|---|
committer | Vojtech Bubnik <bubnikv@gmail.com> | 2021-01-11 13:14:59 +0300 |
commit | 7780221683adca49e3e336c38be82134ee8422fd (patch) | |
tree | 73ad39d34ef81c06b046eb9b22e9085796165b77 | |
parent | b7bfaea1ba9a45b9835b741b9439e26bb8ddbcab (diff) |
Fixed "Single instance" locking issue on Linux with AppImage,
where the PrusaSlicer binary is mounted at a different mount point
at each AppImage execution.
Fixes Lock files in the local configuration directory are not deleted (#5733)
-rw-r--r-- | src/slic3r/GUI/InstanceCheck.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
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<std::string>{}(boost::filesystem::system_complete(argv[0]).string()); + hashed_path = std::hash<std::string>{}(boost::filesystem::system_complete(argv[0]).string()); #else - std::hash<std::string>{}(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<std::string>{}(boost::filesystem::canonical(boost::filesystem::system_complete(appimage_binary, ec).string()); + if (ec.value() > 0) +#endif // __linux + 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?) 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<std::string>{}(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); |