Skip to content

Commit

Permalink
utils: Merge the hasTouch calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bbhtt committed Jan 17, 2025
1 parent c0d6857 commit 2ef7ef5
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions backend/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def appstream2dict(appstream_url=None) -> dict[str, dict]:
app["locales"] = {}

isMobileFriendly = False
hasTouch = False

requires = component.find("requires")
if requires is not None:
if display_lengths := requires.findall("display_length"):
Expand All @@ -109,20 +111,13 @@ def appstream2dict(appstream_url=None) -> dict[str, dict]:
):
isMobileFriendly = True

hasTouch = False
supports = component.find("supports")
if supports is not None:
if controls := supports.findall("control"):
for control in controls:
if control.text == "touch":
hasTouch = True

recommends = component.find("recommends")
if recommends is not None:
if controls := recommends.findall("control"):
for control in controls:
if control.text == "touch":
hasTouch = True
for requirement in ("supports", "recommends"):
element = component.find(requirement)
if element is not None:
controls = element.findall("control")
if any(control.text == "touch" for control in controls):
hasTouch = True
break

app["isMobileFriendly"] = isMobileFriendly and hasTouch

Expand Down Expand Up @@ -461,10 +456,10 @@ def appstream2dict(appstream_url=None) -> dict[str, dict]:

def display_length_supports_mobile(display_length: etree.Element) -> bool:
conditions = {
# a value <=1 means neither mobile nor desktop is supported
# a value < 1 means neither mobile nor desktop is supported
# a value > 360 means only desktop is supported
"ge": lambda value: 1 <= value <= 360,
# a value <=1 means neither mobile nor desktop is supported
# a value < 1 means neither mobile nor desktop is supported
# a value > 359 means only desktop is supported
"gt": lambda value: 1 <= value <= 359,
# a value in 768 and 1279 means only mobile is supported
Expand Down

0 comments on commit 2ef7ef5

Please sign in to comment.