I have a program that makes sure that it is not possible to open two instances at once and does it with the following code.
if [[ ! -z "$(pgrep -a yad_v12_3 | grep "{--notification" | awk '{print $1}')" ]]] ; then
kill -s SIGUSR1 "`pgrep -a yad_v12_3 | grep "\--notification" | awk '{print $1}'`" 2>/dev/null
fi
kill -n 9 `pgrep -a start.sh | grep -i '/PortProton/' | awk '{print $1}'`` > /dev/null 2>&1
killall yad_v12_3 &>/dev/null
fi
But inside flatpak this code does not work, the question is how it should be adapted to work and if it is possible at all or if each flatpak application is a separate container not able to interact with each other.