@@ -62,8 +62,44 @@ appimage_python()
6262 exec " ${APPDIR} /usr/bin/python" " $@ "
6363}
6464
65+ install_udev_rule ()
66+ {
67+ # Pass through variables because pkexec doesn't pass through env
68+ local UDEV_RULE_FILE=" $1 "
69+ local USER=" $2 "
70+ if ! grep -q " ^plover:" /etc/group; then
71+ groupadd plover
72+ fi
73+ # NOTE: this requires a reboot!
74+ if ! groups " $USER " | grep -qw " plover" ; then
75+ usermod -aG plover " $USER "
76+ fi
77+ if [ ! -f " $UDEV_RULE_FILE " ]; then
78+ echo ' KERNEL=="uinput", GROUP="plover", MODE="0660", OPTIONS+="static_node=uinput"' > " $UDEV_RULE_FILE "
79+ chmod 644 " $UDEV_RULE_FILE "
80+ udevadm control --reload-rules
81+ udevadm trigger
82+ # Temporarily give the current user access
83+ # This is done because the groupadd does not take effect until next reboot
84+ # And this temporary solution works *until* the next reboot
85+ # FIXME if someone can find a better solution
86+ chown " ${USER} :plover" /dev/uinput
87+ chmod 660 /dev/uinput
88+ fi
89+ }
90+
6591appimage_launch ()
6692{
93+ # Install the udev rule required for uinput
94+ UDEV_RULE_FILE=" /etc/udev/rules.d/99-plover-uinput.rules"
95+ # It's done like this to have the lowest possible number of pkexec calls
96+ # Each time it's called, the user gets shown a new password input dialog
97+ # FIXME if there is an easier way to do it
98+ if [ ! -f " $UDEV_RULE_FILE " ] || ! grep -q " ^plover:" /etc/group || ! groups | grep -qw " plover" ; then
99+ notify-send -t 10000 " Installing udev rules" " You will be prompted for your password"
100+ pkexec bash -c " $( declare -f install_udev_rule) ; install_udev_rule '$UDEV_RULE_FILE ' '$USER '"
101+ notify-send -t 10000 " Successfully installed udev rules" " A reboot may be required for output to work"
102+ fi
67103 appimage_python -s -m plover.scripts.dist_main " $@ "
68104}
69105
@@ -73,6 +109,7 @@ APPDIR="$(dirname "$(readlink -e "$0")")"
73109
74110appimage_setenv
75111
112+
76113# Handle AppImage specific options.
77114[ -n " $APPIMAGE " ] && case " $1 " in
78115 --install|--uninstall)
0 commit comments