Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for desktop files in all subdirectories of app dirs #370

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Handle OSError and UnicodeDecodeError when listing app dirs and openi…
…ng .desktop files
  • Loading branch information
yawor committed Dec 27, 2024
commit 1e7fbfa5cb03a4ee53215bd717a66c8dd50c8f93
20 changes: 17 additions & 3 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 @@ -78,7 +86,13 @@ def __populate_caches():
continue
seen_dirs.add(d)
if os.path.isdir(d):
for file_name in os.listdir(d):
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
Expand Down