deduplicate apps
This commit is contained in:
@@ -56,19 +56,32 @@ def parse_desktop_file(file_path: Path) -> App:
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
def list_apps() -> list[App]:
|
def list_apps() -> list[App]:
|
||||||
all_apps = []
|
seen_apps = {}
|
||||||
|
|
||||||
for desktop_dir in get_desktop_dirs():
|
for desktop_dir in get_desktop_dirs():
|
||||||
for file_path in desktop_dir.glob("*.desktop"):
|
for file_path in desktop_dir.glob("*.desktop"):
|
||||||
app = parse_desktop_file(file_path)
|
try:
|
||||||
if not app.hidden:
|
app = parse_desktop_file(file_path)
|
||||||
all_apps.append(app)
|
|
||||||
|
|
||||||
return all_apps
|
if app.hidden or not app.name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
app_key = (app.name, app.exec)
|
||||||
|
|
||||||
|
if app_key not in seen_apps:
|
||||||
|
seen_apps[app_key] = app
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Warning: Could not parse {file_path}: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
return list(seen_apps.values())
|
||||||
|
|
||||||
def launch(app: App):
|
def launch(app: App):
|
||||||
os.system(f"{app.exec}")
|
os.system(f"{app.exec}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
apps = list_apps()
|
apps = list_apps()
|
||||||
for app in apps:
|
print(f"Found {len(apps)} applications:\n")
|
||||||
|
for app in sorted(apps, key=lambda x: x.name.lower()):
|
||||||
print(app)
|
print(app)
|
||||||
Reference in New Issue
Block a user