misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-04-05 16:57:15 +02:00
parent aa63a47bc1
commit 20200f75a0
Failed to generate hash of commit
4 changed files with 19 additions and 4 deletions

View file

@ -18,5 +18,5 @@ test:
mkdir rules
make
clear
xterm -e "python ui/main.py" &
xterm -e "python ui/main.py ; read" &
sudo ./daemon/daemon

View file

@ -19,6 +19,11 @@ class LinuxDesktopParser(threading.Thread):
self.daemon = True
self.running = False
self.apps = {}
# some things are just weird
self.fixes = {
'/opt/google/chrome/chrome': '/opt/google/chrome/google-chrome',
'/usr/lib/firefox/firefox': '/usr/lib/firefox/firefox.sh'
}
for desktop_path in DESKTOP_PATHS:
if not os.path.exists(desktop_path):
@ -60,11 +65,19 @@ class LinuxDesktopParser(threading.Thread):
self.apps[cmd] = (name, icon, desktop_path)
# if the command is a symlink, add the real binary too
if os.path.islink(cmd):
link_to = os.path.abspath(os.readlink(cmd))
link_to = os.path.realpath(cmd)
if "spotify" in cmd:
print "%s -> %s" % (cmd, link_to)
self.apps[link_to] = (name, icon, desktop_path)
def get_info_by_path(self, path):
def_name = os.path.basename(path)
# apply fixes
for orig, to in self.fixes.iteritems():
if path == orig:
path = to
break
return self.apps.get(path, (def_name, None, None))
def run(self):

View file

@ -80,6 +80,8 @@ class Dialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
icon = QtGui.QIcon().fromTheme(app_icon)
pixmap = icon.pixmap(icon.actualSize(QtCore.QSize(48, 48)))
self._app_icon_label.setPixmap(pixmap)
else:
self._app_icon_label.clear()
self._message_label.setText("<b>%s</b> is connecting to %s on %s port %d" % ( \
app_name or con.process_path,

View file

@ -25,7 +25,7 @@ class UIServicer(ui_pb2_grpc.UIServicer):
def AskRule(self, request, context):
rule = self.dialog.promptUser(request)
print "%s -> %s" % ( request, rule )
# print "%s -> %s" % ( request, rule )
return rule
if __name__ == '__main__':