From ac20b275809d778dd1a36c9cf0aa0d127d9f07e8 Mon Sep 17 00:00:00 2001
From: Chris Spearman <cspearman@messagebroadcast.com>
Date: Fri, 25 Aug 2023 17:15:06 -0700
Subject: [PATCH] Fixed flatpak driver installed in user context not found

---
 patch-fbc.sh | 4 ++++
 patch.sh     | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/patch-fbc.sh b/patch-fbc.sh
index 5eb6225..a7929d8 100755
--- a/patch-fbc.sh
+++ b/patch-fbc.sh
@@ -312,8 +312,12 @@ check_version_supported () {
 get_flatpak_driver_path () {
     # Flatpak's package versioning replaces '.' by '-'
     version="$(echo "$1" | tr '.' '-')"
+    # Attempts to patch system flatpak
     if path=$(flatpak info --show-location "org.freedesktop.Platform.GL.nvidia-${version}" 2>/dev/null); then
         echo "$path/files/lib"
+    # If it isn't found will login as the user that envoked sudo & patch this version
+    elif path=$(su -c - ${SUDO_USER} 'flatpak info --show-location "org.freedesktop.Platform.GL.nvidia-'${version}'"'); then
+        echo "$path/files/lib"
     fi
 }
 
diff --git a/patch.sh b/patch.sh
index 1c0cac0..f98aef4 100755
--- a/patch.sh
+++ b/patch.sh
@@ -388,8 +388,12 @@ check_version_supported () {
 get_flatpak_driver_path () {
     # Flatpak's package versioning replaces '.' by '-'
     version="$(echo "$1" | tr '.' '-')"
+    # Attempts to patch system flatpak
     if path=$(flatpak info --show-location "org.freedesktop.Platform.GL.nvidia-${version}" 2>/dev/null); then
         echo "$path/files/lib"
+    # If it isn't found will login as the user that envoked sudo & patch this version
+    elif path=$(su -c - ${SUDO_USER} 'flatpak info --show-location "org.freedesktop.Platform.GL.nvidia-'${version}'"'); then
+        echo "$path/files/lib"
     fi
 }