From c8a35b02cc24799d3dffc2a4d77ba8dc034bf661 Mon Sep 17 00:00:00 2001
From: Boria138 <boriabloger@protonmail.com>
Date: Tue, 19 Mar 2024 12:41:28 +0500
Subject: [PATCH] Fixed "Use system wine" option in flatpak

---
 data_from_portwine/scripts/functions_helper | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/data_from_portwine/scripts/functions_helper b/data_from_portwine/scripts/functions_helper
index 6367207..010cf16 100755
--- a/data_from_portwine/scripts/functions_helper
+++ b/data_from_portwine/scripts/functions_helper
@@ -413,12 +413,21 @@ check_user_conf () {
 init_wine_ver () {
     if [[ "${PW_WINE_USE}" == "USE_SYSTEM_WINE" ]] \
     && command -v wine &>/dev/null ; then
-        export WINEDIR="$RT_PREFIX/usr"
-        export WINE="$RT_PREFIX/$(command -v wine)"
-        export WINELOADER="$WINE"
-        export WINESERVER="$RT_PREFIX/$(command -v wineserver)"
-        export PW_USE_RUNTIME=0
-        export PW_NO_FSYNC=1
+        if ! grep -i "flatpak" /etc/os-release &>/dev/null ; then
+            export WINEDIR="$RT_PREFIX/usr"
+            export WINE="$RT_PREFIX/$(command -v wine)"
+            export WINELOADER="$WINE"
+            export WINESERVER="$RT_PREFIX/$(command -v wineserver)"
+            export PW_USE_RUNTIME=0
+            export PW_NO_FSYNC=1
+        else
+            export WINEDIR="$RT_PREFIX/app"
+            export WINE="$RT_PREFIX/app/bin/wine"
+            export WINELOADER="$WINE"
+            export WINESERVER="$RT_PREFIX/app/bin/wineserver"
+            export PW_USE_RUNTIME=0
+            export PW_NO_FSYNC=1
+        fi
     else
         if [[ -d "${PORT_WINE_PATH}/data/dist" ]] ; then
         orig_IFS="$IFS"
-- 
2.24.1