From 20200f75a00bc14b221d9a927809cfe1ca9cc917 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Thu, 5 Apr 2018 16:57:15 +0200 Subject: [PATCH] misc: small fix or general refactoring i did not bother commenting --- Makefile | 2 +- ui/desktop_parser.py | 17 +++++++++++++++-- ui/dialog.py | 2 ++ ui/main.py | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 84554290..1ef01fba 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/ui/desktop_parser.py b/ui/desktop_parser.py index fcaec2f4..5577d3c3 100644 --- a/ui/desktop_parser.py +++ b/ui/desktop_parser.py @@ -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): @@ -44,7 +49,7 @@ class LinuxDesktopParser(threading.Thread): if os.path.exists(filename): cmd = filename break - + return cmd def _parse_desktop_file(self, 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): diff --git a/ui/dialog.py b/ui/dialog.py index 617eae2f..796d7c4a 100644 --- a/ui/dialog.py +++ b/ui/dialog.py @@ -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("%s is connecting to %s on %s port %d" % ( \ app_name or con.process_path, diff --git a/ui/main.py b/ui/main.py index b4b42fbd..b0334743 100644 --- a/ui/main.py +++ b/ui/main.py @@ -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__':