mirror of
https://github.com/rbreaves/kinto.git
synced 2025-08-05 18:38:26 +02:00
- GUI & sys tray interaction issues resolved
- Added fix to kill spawned processes to GUI app - Added proper handling of spawn from disabling sys tray app - Improved checkTray function - Set full path to avoid issues on About
This commit is contained in:
@@ -6,13 +6,26 @@ from gi.repository import Gtk,Gdk,GdkPixbuf
|
||||
from gi.repository import Vte,GLib
|
||||
from subprocess import Popen,PIPE,CalledProcessError
|
||||
|
||||
import signal
|
||||
|
||||
def kill_child():
|
||||
if child_pid is None:
|
||||
pass
|
||||
else:
|
||||
os.kill(child_pid, signal.SIGTERM)
|
||||
|
||||
import atexit
|
||||
atexit.register(kill_child)
|
||||
|
||||
class MyWindow(Gtk.Window):
|
||||
|
||||
label = Gtk.Label()
|
||||
label.set_alignment(1, 0)
|
||||
ostype = os.environ.get('XDG_CURRENT_DESKTOP')
|
||||
|
||||
global child_pid
|
||||
kinto_status = Popen("while :; do clear; systemctl is-active xkeysnail; sleep 2; done", stdout=PIPE, shell=True)
|
||||
child_pid = kinto_status.pid
|
||||
|
||||
winkb = Gtk.RadioMenuItem(label='Windows')
|
||||
mackb = Gtk.RadioMenuItem(label='Apple',group=winkb)
|
||||
@@ -26,10 +39,12 @@ class MyWindow(Gtk.Window):
|
||||
ibmkb.signal_id = 0
|
||||
winmackb.signal_id = 0
|
||||
|
||||
menuitem_enable = Gtk.CheckMenuItem(label="Enabled")
|
||||
menuitem_enable.signal_id = 0
|
||||
menuitem_auto = Gtk.CheckMenuItem(label="Autostart")
|
||||
menuitem_auto.signal_id = 0
|
||||
menuitem_enable = Gtk.CheckMenuItem(label="Enable")
|
||||
menuitem_enable.signal_id = 0
|
||||
menuitem_systray = Gtk.CheckMenuItem(label="Tray Enabled")
|
||||
menuitem_systray.signal_id = 0
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -173,8 +188,17 @@ class MyWindow(Gtk.Window):
|
||||
menubar.append(menuitem_file)
|
||||
submenu_file = Gtk.Menu()
|
||||
menuitem_file.set_submenu(submenu_file)
|
||||
submenu_file.append(self.menuitem_auto)
|
||||
submenu_file.append(self.menuitem_enable)
|
||||
submenu_file.append(self.menuitem_auto)
|
||||
kintotray = int(self.queryConfig('ps -aux | grep [k]intotray >/dev/null 2>&1 && echo "1" || echo "0"'))
|
||||
if kintotray and os.path.exists(os.environ['HOME']+'/.config/autostart/kintotray.desktop'):
|
||||
self.menuitem_systray.set_active(True)
|
||||
self.menuitem_systray.signal_id = self.menuitem_systray.connect('activate',self.checkTray,False)
|
||||
else:
|
||||
self.menuitem_systray.set_active(False)
|
||||
self.menuitem_systray.signal_id = self.menuitem_systray.connect('activate',self.checkTray,True)
|
||||
menuitem_file.connect('activate',self.refreshFile)
|
||||
submenu_file.append(self.menuitem_systray)
|
||||
# self.menuitem_enable.connect('activate', self.setEnable)
|
||||
menuitem_restart = Gtk.MenuItem(label="Restart")
|
||||
menuitem_restart.connect('activate',self.runRestart)
|
||||
@@ -264,6 +288,22 @@ class MyWindow(Gtk.Window):
|
||||
# radiomenuitem2 = Gtk.RadioMenuItem(label="Apple", group=radiomenuitem1)
|
||||
# menu.append(radiomenuitem2)
|
||||
|
||||
def refreshFile(self,button):
|
||||
kintotray = int(self.queryConfig('ps -aux | grep [k]intotray >/dev/null 2>&1 && echo "1" || echo "0"'))
|
||||
if os.path.exists(os.environ['HOME']+'/.config/autostart/kintotray.desktop') and kintotray and self.menuitem_systray.get_active() == False:
|
||||
self.menuitem_systray.disconnect(self.menuitem_systray.signal_id)
|
||||
self.menuitem_systray.set_active(True)
|
||||
self.menuitem_systray.signal_id = self.menuitem_systray.connect('activate',self.checkTray,False)
|
||||
elif os.path.exists(os.environ['HOME']+'/.config/autostart/kintotray.desktop') and not kintotray and self.menuitem_systray.get_active() == True:
|
||||
self.menuitem_systray.disconnect(self.menuitem_systray.signal_id)
|
||||
self.menuitem_systray.set_active(False)
|
||||
self.menuitem_systray.signal_id = self.menuitem_systray.connect('activate',self.checkTray,True)
|
||||
elif not os.path.exists(os.environ['HOME']+'/.config/autostart/kintotray.desktop') and self.menuitem_systray.get_active() == True:
|
||||
self.menuitem_systray.disconnect(self.menuitem_systray.signal_id)
|
||||
self.menuitem_systray.set_active(False)
|
||||
self.menuitem_systray.signal_id = self.menuitem_systray.connect('activate',self.checkTray,True)
|
||||
# return
|
||||
|
||||
def refresh(self,button):
|
||||
self.refreshKB()
|
||||
|
||||
@@ -386,6 +426,31 @@ class MyWindow(Gtk.Window):
|
||||
|
||||
return
|
||||
|
||||
def checkTray(self,button,tray_bool):
|
||||
kintotray = int(self.queryConfig('ps -aux | grep [k]intotray >/dev/null 2>&1 && echo "1" || echo "0"'))
|
||||
# path.exists('.config/autostart/kintotray.py')
|
||||
if tray_bool:
|
||||
Popen(['cp',os.environ['HOME']+'/.config/kinto/kintotray.desktop',os.environ['HOME']+'/.config/autostart/kintotray.desktop'])
|
||||
if not kintotray:
|
||||
Popen([os.environ['HOME']+'/.config/kinto/kintotray.py'])
|
||||
self.menuitem_systray.disconnect(self.menuitem_systray.signal_id)
|
||||
self.menuitem_systray.set_active(True)
|
||||
self.menuitem_systray.signal_id = self.menuitem_systray.connect('activate',self.checkTray,False)
|
||||
else:
|
||||
Popen(['rm',os.environ['HOME']+'/.config/autostart/kintotray.desktop'])
|
||||
Popen(['pkill','-f','kintotray.py'])
|
||||
killspawn = "for pid in `ps -ef | grep 'active xkeysnail' | awk '{print $2}'` ; do kill -2 $pid ; done"
|
||||
self.queryConfig(killspawn)
|
||||
time.sleep(1)
|
||||
global child_pid
|
||||
self.kinto_status = Popen("while :; do clear; systemctl is-active xkeysnail; sleep 2; done", stdout=PIPE, shell=True)
|
||||
child_pid = self.kinto_status.pid
|
||||
# Popen(['pkill','-f','kintotray.py'])
|
||||
self.menuitem_systray.disconnect(self.menuitem_systray.signal_id)
|
||||
self.menuitem_systray.set_active(False)
|
||||
self.menuitem_systray.signal_id = self.menuitem_systray.connect('activate',self.checkTray,True)
|
||||
return
|
||||
|
||||
def setKB(self,button,kbtype):
|
||||
try:
|
||||
if kbtype == "win":
|
||||
@@ -643,11 +708,11 @@ class MyWindow(Gtk.Window):
|
||||
pkillxkey = Popen(['sudo', 'pkill','-f','bin/xkeysnail'])
|
||||
pkillxkey.wait()
|
||||
Popen(['sudo', 'systemctl','start','xkeysnail'])
|
||||
command = "send \003 journalctl -f --unit=xkeysnail.service -b\n"
|
||||
cmdbytes = str.encode(command)
|
||||
self.InputToTerm(cmdbytes)
|
||||
self.command = "send \003 journalctl -f --unit=xkeysnail.service -b\n"
|
||||
self.cmdbytes = str.encode(self.command)
|
||||
self.InputToTerm(self.cmdbytes)
|
||||
except:
|
||||
Popen(['notify-send','Kinto: Error restarting Kinto!','-i','budgie-desktop-symbolic'])
|
||||
Popen(['notify-send','Kinto: Errror restarting Kinto!','-i','budgie-desktop-symbolic'])
|
||||
|
||||
def setEnable(self,button,enableKinto):
|
||||
try:
|
||||
@@ -665,11 +730,13 @@ class MyWindow(Gtk.Window):
|
||||
self.menuitem_enable.disconnect(self.menuitem_enable.signal_id)
|
||||
self.menuitem_enable.set_active(True)
|
||||
self.menuitem_enable.signal_id = self.menuitem_enable.connect('activate',self.setEnable,False)
|
||||
command = "send \003 journalctl -f --unit=xkeysnail.service -b\n"
|
||||
cmdbytes = str.encode(command)
|
||||
self.command = "send \003 journalctl -f --unit=xkeysnail.service -b\n"
|
||||
self.cmdbytes = str.encode(self.command)
|
||||
self.InputToTerm(cmdbytes)
|
||||
else:
|
||||
Popen(['sudo', 'systemctl','stop','xkeysnail'])
|
||||
self.command = "send \003 journalctl -f --unit=xkeysnail.service -b\n"
|
||||
self.cmdbytes = str.encode(self.command)
|
||||
self.menuitem_enable.disconnect(self.menuitem_enable.signal_id)
|
||||
self.menuitem_enable.set_active(False)
|
||||
self.menuitem_enable.signal_id = self.menuitem_enable.connect('activate',self.setEnable,True)
|
||||
|
8
xkeysnail-config/trayapps/appindicator/kintotray.desktop
Normal file
8
xkeysnail-config/trayapps/appindicator/kintotray.desktop
Normal file
@@ -0,0 +1,8 @@
|
||||
[Desktop Entry]
|
||||
Name=Kinto Tray
|
||||
GenericName=Kintotray
|
||||
Comment=Make Linux Type Like it's a Mac
|
||||
Exec=/bin/bash -c "{homedir}/.config/kinto/kintotray.py"
|
||||
Terminal=false
|
||||
Type=Application
|
||||
X-GNOME-Autostart-enabled=true
|
@@ -65,6 +65,7 @@ class Indicator():
|
||||
# Keyboard type set below
|
||||
button_syskb = Gtk.MenuItem('System Shortcuts')
|
||||
button_region = Gtk.MenuItem('Change Language')
|
||||
systray = Gtk.CheckMenuItem('Tray Enabled')
|
||||
helpm = Gtk.MenuItem('Help')
|
||||
help_submenu = Gtk.Menu()
|
||||
helpm.set_submenu(help_submenu)
|
||||
@@ -109,7 +110,6 @@ class Indicator():
|
||||
else:
|
||||
self.checkbox_autostart.set_active(False)
|
||||
self.chkautostart_id = self.checkbox_autostart.connect('activate',self.setAutostart,True)
|
||||
self.menu.append(self.checkbox_autostart)
|
||||
|
||||
# Kinto Enable
|
||||
|
||||
@@ -161,6 +161,13 @@ class Indicator():
|
||||
# Set Language
|
||||
self.button_region.connect('activate',self.setRegion)
|
||||
self.edit_submenu.append(self.button_region)
|
||||
self.edit_submenu.append(self.checkbox_autostart)
|
||||
if os.path.exists(os.environ['HOME']+'/.config/autostart/kintotray.desktop'):
|
||||
self.systray.set_active(True)
|
||||
self.systray.signal_id = self.systray.connect('activate',self.checkTray,False)
|
||||
else:
|
||||
self.systray.signal_id = self.systray.connect('activate',self.checkTray,True)
|
||||
self.edit_submenu.append(self.systray)
|
||||
self.menu.append(self.edit)
|
||||
|
||||
self.debug.connect('activate',self.runDebug)
|
||||
@@ -207,6 +214,21 @@ class Indicator():
|
||||
# md.destroy()
|
||||
# return True
|
||||
|
||||
def checkTray(self,button,tray_bool):
|
||||
# path.exists('.config/autostart/kintotray.py')
|
||||
if tray_bool:
|
||||
Popen(['cp',os.environ['HOME']+'/.config/kinto/kintotray.desktop',os.environ['HOME']+'/.config/autostart/kintotray.desktop'])
|
||||
self.systray.disconnect(self.systray.signal_id)
|
||||
self.systray.set_active(True)
|
||||
self.systray.signal_id = self.systray.connect('activate',self.checkTray,False)
|
||||
else:
|
||||
Popen(['rm',os.environ['HOME']+'/.config/autostart/kintotray.desktop'])
|
||||
Gtk.main_quit()
|
||||
self.systray.disconnect(self.systray.signal_id)
|
||||
self.systray.set_active(False)
|
||||
self.systray.signal_id = self.systray.connect('activate',self.checkTray,True)
|
||||
return
|
||||
|
||||
def refresh(self,button):
|
||||
self.refreshKB()
|
||||
|
||||
@@ -340,7 +362,7 @@ class Indicator():
|
||||
image = Gtk.Image()
|
||||
image.set_from_pixbuf(pixbuf)
|
||||
|
||||
with open('version', 'r') as file:
|
||||
with open(os.environ['HOME']+'/.config/kinto/version', 'r') as file:
|
||||
verdata = file.read().replace('\n', '')
|
||||
|
||||
version = Gtk.Label('Kinto v' + verdata)
|
||||
|
@@ -3,6 +3,8 @@ Name=Kinto_xkey
|
||||
GenericName=Kinto_xkey
|
||||
Comment=Make Linux Type Like it's a Mac
|
||||
Exec=/bin/bash -c "grep -q 'autostart = true' {homedir}/.config/kinto/kinto.py && {xhost} +SI:localuser:root && sudo {systemctl} restart xkeysnail"
|
||||
# Budgie logoff fix to avoid key input loss
|
||||
# ;{homedir}/.config/kinto/logoff.sh
|
||||
# ;sudo /usr/local/bin/logoff.sh $USER $DISPLAY
|
||||
Terminal=false
|
||||
Type=Application
|
||||
|
@@ -306,6 +306,7 @@ if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "4" || $1 == "winmac" || $1 =
|
||||
yes | cp -rf ./xkeysnail-config/killdups.sh ~/.config/kinto/killdups.sh
|
||||
yes | cp -rf ./xkeysnail-config/appleKB.sh ~/.config/kinto/appleKB.sh
|
||||
yes | cp -rf ./xkeysnail-config/trayapps/appindicator/kintotray.py ~/.config/kinto/kintotray.py
|
||||
yes | cp -rf ./xkeysnail-config/trayapps/appindicator/kintotray.desktop ~/.config/kinto/kintotray.desktop
|
||||
yes | cp -rf ./xkeysnail-config/trayapps/BudgieApplet/icons/kinto-color-16.svg ~/.config/kinto/kinto-color.svg
|
||||
yes | cp -rf ./xkeysnail-config/trayapps/BudgieApplet/icons/kinto-invert-16.svg ~/.config/kinto/kinto-invert.svg
|
||||
yes | cp -rf ./xkeysnail-config/trayapps/BudgieApplet/icons/kinto-solid-16.svg ~/.config/kinto/kinto-solid.svg
|
||||
@@ -320,6 +321,7 @@ if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "4" || $1 == "winmac" || $1 =
|
||||
fi
|
||||
sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/xkeysnail.service.new
|
||||
sed -i "s#{homedir}#`echo "$HOME"`#g" ./xkeysnail-config/xkeysnail.service.new
|
||||
sed -i "s#{homedir}#`echo "$HOME"`#g" ~/.config/kinto/kintotray.desktop
|
||||
sed -i "s#{xhost}#`\\which xhost`#g" ./xkeysnail-config/xkeysnail.service.new
|
||||
sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/limitedadmins.new
|
||||
sed -i "s#{systemctl}#`\\which systemctl`#g" ./xkeysnail-config/limitedadmins.new
|
||||
@@ -328,6 +330,7 @@ if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "4" || $1 == "winmac" || $1 =
|
||||
sudo chown root:root ./xkeysnail-config/limitedadmins.new
|
||||
sudo mv ./xkeysnail-config/limitedadmins.new /etc/sudoers.d/limitedadmins
|
||||
sed -i "s#{systemctl}#`\\which systemctl`#g" ~/.config/autostart/xkeysnail.desktop
|
||||
yes | cp -rf ~/.config/kinto/kintotray.desktop ~/.config/autostart/kintotray.desktop
|
||||
if $installtray ; then
|
||||
sed -i "s#-c \"grep#-c \"python3 {homedir}/.config/kinto/kintotray.py;grep#g" ~/.config/autostart/xkeysnail.desktop
|
||||
sed -i "s#xkeysnail\"#xkeysnail;{homedir}/.config/kinto/logoff.sh\"#g" ~/.config/autostart/xkeysnail.desktop
|
||||
|
Reference in New Issue
Block a user