mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 08:34:40 +01:00
Workaround for crashes parsing .desktop files
We parse .desktop files to get the icon of a program, but sometimes we can't parse the Name translation due to unicode encoding problems. Besides, on some distributions there're .desktop files without Exec= line, so we also crash. With this workaround we miss (mainly) the icon of a program, but at least we won't crash. It should help with #5.
This commit is contained in:
parent
c4a9a21afa
commit
401329171a
1 changed files with 15 additions and 12 deletions
|
@ -57,19 +57,22 @@ class LinuxDesktopParser(threading.Thread):
|
|||
|
||||
def _parse_desktop_file(self, desktop_path):
|
||||
parser = configparser.ConfigParser(strict=False) # Allow duplicate config entries
|
||||
parser.read(desktop_path, 'utf8')
|
||||
try:
|
||||
parser.read(desktop_path, 'utf8')
|
||||
|
||||
cmd = parser.get('Desktop Entry', 'exec', raw=True, fallback=None)
|
||||
if cmd is not None:
|
||||
cmd = self._parse_exec(cmd)
|
||||
icon = parser.get('Desktop Entry', 'Icon', raw=True, fallback=None)
|
||||
name = parser.get('Desktop Entry', 'Name', raw=True, fallback=None)
|
||||
with self.lock:
|
||||
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.realpath(cmd)
|
||||
self.apps[link_to] = (name, icon, desktop_path)
|
||||
cmd = parser.get('Desktop Entry', 'exec', raw=True, fallback=None)
|
||||
if cmd is not None:
|
||||
cmd = self._parse_exec(cmd)
|
||||
icon = parser.get('Desktop Entry', 'Icon', raw=True, fallback=None)
|
||||
name = parser.get('Desktop Entry', 'Name', raw=True, fallback=None)
|
||||
with self.lock:
|
||||
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.realpath(cmd)
|
||||
self.apps[link_to] = (name, icon, desktop_path)
|
||||
except:
|
||||
print("Exception parsing .desktop file ", desktop_path)
|
||||
|
||||
def get_info_by_path(self, path, default_icon):
|
||||
def_name = os.path.basename(path)
|
||||
|
|
Loading…
Add table
Reference in a new issue