buffer once found icon names #259
This commit is contained in:
@@ -18,6 +18,7 @@ dwl_instances = []
|
||||
app_dirs = []
|
||||
name2icon_dict = {}
|
||||
scratchpad_cons = {}
|
||||
app_name2icon_name = {}
|
||||
|
||||
commands = {
|
||||
"light": False,
|
||||
|
@@ -544,7 +544,7 @@ def main():
|
||||
save_string("-c {} -s {}".format(args.config, args.style), os.path.join(local_dir(), "args"))
|
||||
|
||||
common.app_dirs = get_app_dirs()
|
||||
common.name2icon_dict = map_odd_desktop_files()
|
||||
# common.name2icon_dict = map_odd_desktop_files()
|
||||
|
||||
config_file = os.path.join(common.config_dir, args.config)
|
||||
|
||||
|
@@ -72,32 +72,36 @@ def get_app_dirs():
|
||||
return desktop_dirs
|
||||
|
||||
|
||||
def map_odd_desktop_files():
|
||||
name2icon_dict = {}
|
||||
for d in nwg_panel.common.app_dirs:
|
||||
if os.path.exists(d):
|
||||
for path in os.listdir(d):
|
||||
if os.path.isfile(os.path.join(d, path)):
|
||||
if path.endswith(".desktop") and path.count(".") > 1:
|
||||
try:
|
||||
content = load_text_file(os.path.join(d, path))
|
||||
except Exception as e:
|
||||
eprint(e)
|
||||
if content:
|
||||
for line in content.splitlines():
|
||||
if line.startswith("[") and not line == "[Desktop Entry]":
|
||||
break
|
||||
if line.upper().startswith("ICON="):
|
||||
icon = line.split("=")[1]
|
||||
name2icon_dict[path] = icon
|
||||
break
|
||||
|
||||
return name2icon_dict
|
||||
# def map_odd_desktop_files():
|
||||
# name2icon_dict = {}
|
||||
# for d in nwg_panel.common.app_dirs:
|
||||
# if os.path.exists(d):
|
||||
# for path in os.listdir(d):
|
||||
# if os.path.isfile(os.path.join(d, path)):
|
||||
# if path.endswith(".desktop") and path.count(".") > 1:
|
||||
# try:
|
||||
# content = load_text_file(os.path.join(d, path))
|
||||
# except Exception as e:
|
||||
# eprint(e)
|
||||
# if content:
|
||||
# for line in content.splitlines():
|
||||
# if line.startswith("[") and not line == "[Desktop Entry]":
|
||||
# break
|
||||
# if line.upper().startswith("ICON="):
|
||||
# icon = line.split("=")[1]
|
||||
# name2icon_dict[path] = icon
|
||||
# break
|
||||
#
|
||||
# return name2icon_dict
|
||||
|
||||
|
||||
def get_icon_name(app_name):
|
||||
if not app_name:
|
||||
return ""
|
||||
# the name might've been already found in .desktop files and stored
|
||||
if app_name in nwg_panel.common.app_name2icon_name:
|
||||
return nwg_panel.common.app_name2icon_name[app_name]
|
||||
|
||||
# GIMP returns "app_id": null and for some reason "class": "Gimp-2.10" instead of just "gimp".
|
||||
# Until the GTK3 version is released, let's make an exception for GIMP.
|
||||
if "GIMP" in app_name.upper():
|
||||
@@ -114,7 +118,9 @@ def get_icon_name(app_name):
|
||||
if content:
|
||||
for line in content.splitlines():
|
||||
if line.upper().startswith("ICON"):
|
||||
return line.split("=")[1]
|
||||
icon_name = line.split("=")[1]
|
||||
nwg_panel.common.app_name2icon_name[app_name] = icon_name
|
||||
return icon_name
|
||||
|
||||
# Otherwise, we need to search all .desktop files
|
||||
if os.path.isdir(d):
|
||||
@@ -125,13 +131,15 @@ def get_icon_name(app_name):
|
||||
if content:
|
||||
for line in content.splitlines():
|
||||
if line.upper().startswith("ICON"):
|
||||
return line.split("=")[1]
|
||||
icon_name = line.split("=")[1]
|
||||
nwg_panel.common.app_name2icon_name[app_name] = icon_name
|
||||
return icon_name
|
||||
|
||||
# Search the dictionary made of .desktop files that use "reverse DNS"-style names, prepared on startup.
|
||||
# see: https://github.com/nwg-piotr/nwg-panel/issues/64
|
||||
for key in nwg_panel.common.name2icon_dict.keys():
|
||||
if app_name in key.split("."):
|
||||
return nwg_panel.common.name2icon_dict[key]
|
||||
# for key in nwg_panel.common.name2icon_dict.keys():
|
||||
# if app_name in key.split("."):
|
||||
# return nwg_panel.common.name2icon_dict[key]
|
||||
|
||||
# if all above fails
|
||||
return app_name
|
||||
|
Reference in New Issue
Block a user