Skip to content

Commit

Permalink
Merge pull request #370 from yawor/icons-cache-fix
Browse files Browse the repository at this point in the history
Search for desktop files in all subdirectories of app dirs
  • Loading branch information
nwg-piotr authored Dec 27, 2024
2 parents 61163ff + 1e7fbfa commit 00357f5
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions nwg_panel/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ def __get_app_dirs():


def __process_desktop_file(file_path):
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
except UnicodeDecodeError:
print(f"Warning: Invalid .desktop file '{file_path}'")
return
except OSError as e:
print(f"Warning: Unable to read .desktop file '{file_path}': {e}")
return

icon_name = None
app_names = []
startup_wm_class = None
Expand Down Expand Up @@ -70,10 +78,27 @@ def __process_desktop_file(file_path):


def __populate_caches():
for d in __get_app_dirs():
app_dirs = __get_app_dirs()
seen_dirs = set()
while app_dirs:
d = app_dirs.pop(0)
if d in seen_dirs:
continue
seen_dirs.add(d)
if os.path.isdir(d):
for file_name in os.listdir(d):
file_path = os.path.join(d, file_name)
try:
files = os.listdir(d)
except OSError as e:
print(f"Warning: Can't list files in directory '{d}': {e}")
continue

for file_name in files:
file_path = os.path.realpath(os.path.join(d, file_name))
if not os.path.exists(file_path):
continue
if os.path.isdir(file_path):
app_dirs.insert(0, file_path)
continue
__process_desktop_file(file_path)


Expand Down

0 comments on commit 00357f5

Please sign in to comment.