diff --git a/src/wzpropertyproviders.cpp b/src/wzpropertyproviders.cpp index b77d4fbb50a..cd5a75036db 100644 --- a/src/wzpropertyproviders.cpp +++ b/src/wzpropertyproviders.cpp @@ -53,6 +53,12 @@ #include #endif +// Includes for Unix +#if defined(WZ_OS_UNIX) +#include +#include +#endif + // MARK: - BuildPropertyProvider enum class BuildProperty { @@ -160,6 +166,64 @@ static std::string Get_WinPackageFullName() } #endif +enum class WZ_CONTAINER_TYPE +{ + NONE_DETECTED, + FLATPAK, + SNAP, + APPIMAGE, + WIN_PACKAGE // ex. MSIX package +}; + +static std::string to_string(const WZ_CONTAINER_TYPE& type) +{ + switch (type) + { + case WZ_CONTAINER_TYPE::NONE_DETECTED: + return ""; + case WZ_CONTAINER_TYPE::FLATPAK: + return "flatpak"; + case WZ_CONTAINER_TYPE::SNAP: + return "snap"; + case WZ_CONTAINER_TYPE::APPIMAGE: + return "appimage"; + case WZ_CONTAINER_TYPE::WIN_PACKAGE: + return "winpackage"; + } + return ""; // silence warning +} + +static WZ_CONTAINER_TYPE GetCurrentContainerType() +{ +#if defined(WZ_OS_WIN) + if (!Get_WinPackageFullName().empty()) + { + return WZ_CONTAINER_TYPE::WIN_PACKAGE; + } +#elif defined(WZ_OS_UNIX) + if (access("/.flatpak-info", F_OK) == 0) + { + return WZ_CONTAINER_TYPE::FLATPAK; + } + // Check multiple variables, as is done by both WebKit and SDL + // See: https://snapcraft.io/docs/environment-variables + if (std::getenv("SNAP") && std::getenv("SNAP_NAME") && std::getenv("SNAP_REVISION")) + { + return WZ_CONTAINER_TYPE::SNAP; + } + if (std::getenv("APPIMAGE")) + { + return WZ_CONTAINER_TYPE::APPIMAGE; + } +#endif + return WZ_CONTAINER_TYPE::NONE_DETECTED; +} + +static std::string GetCurrentContainerTypeStr() +{ + return to_string(GetCurrentContainerType()); +} + static std::string GetCurrentBuildPropertyValue(const BuildProperty& property) { using BP = BuildProperty; @@ -251,6 +315,7 @@ static const std::unordered_map