Skip to content

Commit

Permalink
Fixes #5
Browse files Browse the repository at this point in the history
* When getting icons for the apps prefer the app icon asset of the app
  windows10  --> Square44x44Logo
  windows8.1 --> Square30x30Logo
  windows8   --> SmallLogo
* Different scale versions of the icons are already handled
  • Loading branch information
ueffel committed Jul 25, 2019
1 parent 35955de commit 8dc81ea
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
RESOURCE_DESC_FORMAT = "ms-resource://Windows.UI.SettingsAppThreshold/SearchResources/{}/Description"
RESOURCE_SETTINGS_TITLE = "ms-resource://Windows.UI.SettingsAppThreshold/SystemSettings/Resources/SettingsAppTitle/Text"

WINDOWS10 = "http://schemas.microsoft.com/appx/manifest/foundation/windows10"
WINDOWS81 = "http://schemas.microsoft.com/appx/2013/manifest"
WINDOWS8 = "http://schemas.microsoft.com/appx/2010/manifest"


class AppXPackage(object):
"""Represents a windows app package
Expand Down Expand Up @@ -84,23 +88,30 @@ def _get_applications(self):
app_description = visual_elements.get("Description")

logos = {attr: visual_elements.get(attr) for attr in visual_elements.attrib if "logo" in attr.lower()}
if default_tile:
logos.update({attr: default_tile.get(attr) for attr in default_tile.attrib
if "logo" in attr.lower()})
square_logos = {key: value for key, value in logos.items() if "square" in key.lower()}
wide_logos = {key: value for key, value in logos.items() if "wide" in key.lower()}

if square_logos:
biggest = max(square_logos.keys(), key=lambda x: int(re.search(r"(\d+)x\d+", x).groups()[0]))
app_icon_path = os.path.join(self.InstallLocation, logos[biggest])
elif not app_icon_path and wide_logos:
biggest = max(wide_logos, key=lambda x: re.search(r"(\d+)x\d+", x).groups()[0])
app_icon_path = os.path.join(self.InstallLocation, logos[biggest])
elif not app_icon_path and logos:
biggest = min(logos)
app_icon_path = os.path.join(self.InstallLocation, logos[biggest])
elif not app_icon_path:
app_icon_path = package_icon_path
if ns["default"] == WINDOWS10 and "Square44x44Logo" in logos:
app_icon_path = os.path.join(self.InstallLocation, logos["Square44x44Logo"])
elif ns["default"] == WINDOWS81 and "Square30x30Logo" in logos:
app_icon_path = os.path.join(self.InstallLocation, logos["Square30x30Logo"])
elif ns["default"] == WINDOWS8 and "SmallLogo" in logos:
app_icon_path = os.path.join(self.InstallLocation, logos["SmallLogo"])
else:
if default_tile:
logos.update({attr: default_tile.get(attr) for attr in default_tile.attrib
if "logo" in attr.lower()})
square_logos = {key: value for key, value in logos.items() if "square" in key.lower()}
wide_logos = {key: value for key, value in logos.items() if "wide" in key.lower()}

if square_logos:
biggest = max(square_logos.keys(), key=lambda x: int(re.search(r"(\d+)x\d+", x).groups()[0]))
app_icon_path = os.path.join(self.InstallLocation, logos[biggest])
elif not app_icon_path and wide_logos:
biggest = max(wide_logos, key=lambda x: re.search(r"(\d+)x\d+", x).groups()[0])
app_icon_path = os.path.join(self.InstallLocation, logos[biggest])
elif not app_icon_path and logos:
biggest = min(logos)
app_icon_path = os.path.join(self.InstallLocation, logos[biggest])
elif not app_icon_path:
app_icon_path = package_icon_path

if app_display_name and app_display_name.startswith(RESOURCE_PREFIX):
resource = self.get_resource(self.InstallLocation, app_display_name)
Expand Down

0 comments on commit 8dc81ea

Please # to comment.