Launcher: skip launcher gui when opening webhost list with no game handlers (#4888)

* calc relevant components before opening the launcher app so it can be skipped for text client only uri launches

* generically passthrough the url arg

* Apply suggestions from code review

Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com>

* flip if not else

* Update Launcher.py

* pluralize

---------

Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com>
This commit is contained in:
qwint
2025-05-23 17:02:50 -05:00
committed by GitHub
parent 13ca134d12
commit 0a7aa9e3e2

View File

@@ -115,28 +115,24 @@ components.extend([
]) ])
def handle_uri(path: str, launch_args: tuple[str, ...]) -> None: def handle_uri(path: str) -> tuple[list[Component], Component]:
url = urllib.parse.urlparse(path) url = urllib.parse.urlparse(path)
queries = urllib.parse.parse_qs(url.query) queries = urllib.parse.parse_qs(url.query)
launch_args = (path, *launch_args) client_components = []
client_component = []
text_client_component = None text_client_component = None
game = queries["game"][0] game = queries["game"][0]
for component in components: for component in components:
if component.supports_uri and component.game_name == game: if component.supports_uri and component.game_name == game:
client_component.append(component) client_components.append(component)
elif component.display_name == "Text Client": elif component.display_name == "Text Client":
text_client_component = component text_client_component = component
return client_components, text_client_component
if not client_component: def build_uri_popup(component_list: list[Component], launch_args: tuple[str, ...]) -> None:
run_component(text_client_component, *launch_args)
return
else:
from kvui import ButtonsPrompt from kvui import ButtonsPrompt
component_options = { component_options = {
text_client_component.display_name: text_client_component, component.display_name: component for component in component_list
**{component.display_name: component for component in client_component}
} }
popup = ButtonsPrompt("Connect to Multiworld", popup = ButtonsPrompt("Connect to Multiworld",
"Select client to open and connect with.", "Select client to open and connect with.",
@@ -212,7 +208,7 @@ def create_shortcut(button: Any, component: Component) -> None:
refresh_components: Callable[[], None] | None = None refresh_components: Callable[[], None] | None = None
def run_gui(path: str, args: Any) -> None: def run_gui(launch_components: list[Component], args: Any) -> None:
from kvui import (ThemedApp, MDFloatLayout, MDGridLayout, ScrollBox) from kvui import (ThemedApp, MDFloatLayout, MDGridLayout, ScrollBox)
from kivy.properties import ObjectProperty from kivy.properties import ObjectProperty
from kivy.core.window import Window from kivy.core.window import Window
@@ -245,12 +241,12 @@ def run_gui(path: str, args: Any) -> None:
cards: list[LauncherCard] cards: list[LauncherCard]
current_filter: Sequence[str | Type] | None current_filter: Sequence[str | Type] | None
def __init__(self, ctx=None, path=None, args=None): def __init__(self, ctx=None, components=None, args=None):
self.title = self.base_title + " " + Utils.__version__ self.title = self.base_title + " " + Utils.__version__
self.ctx = ctx self.ctx = ctx
self.icon = r"data/icon.png" self.icon = r"data/icon.png"
self.favorites = [] self.favorites = []
self.launch_uri = path self.launch_components = components
self.launch_args = args self.launch_args = args
self.cards = [] self.cards = []
self.current_filter = (Type.CLIENT, Type.TOOL, Type.ADJUSTER, Type.MISC) self.current_filter = (Type.CLIENT, Type.TOOL, Type.ADJUSTER, Type.MISC)
@@ -372,9 +368,9 @@ def run_gui(path: str, args: Any) -> None:
return self.top_screen return self.top_screen
def on_start(self): def on_start(self):
if self.launch_uri: if self.launch_components:
handle_uri(self.launch_uri, self.launch_args) build_uri_popup(self.launch_components, self.launch_args)
self.launch_uri = None self.launch_components = None
self.launch_args = None self.launch_args = None
@staticmethod @staticmethod
@@ -415,7 +411,7 @@ def run_gui(path: str, args: Any) -> None:
for filter in self.current_filter)) for filter in self.current_filter))
super().on_stop() super().on_stop()
Launcher(path=path, args=args).run() Launcher(components=launch_components, args=args).run()
# avoiding Launcher reference leak # avoiding Launcher reference leak
# and don't try to do something with widgets after window closed # and don't try to do something with widgets after window closed
@@ -442,7 +438,15 @@ def main(args: argparse.Namespace | dict | None = None):
path = args.get("Patch|Game|Component|url", None) path = args.get("Patch|Game|Component|url", None)
if path is not None: if path is not None:
if not path.startswith("archipelago://"): if path.startswith("archipelago://"):
args["args"] = (path, *args.get("args", ()))
# add the url arg to the passthrough args
components, text_client_component = handle_uri(path)
if not components:
args["component"] = text_client_component
else:
args['launch_components'] = [text_client_component, *components]
else:
file, component = identify(path) file, component = identify(path)
if file: if file:
args['file'] = file args['file'] = file
@@ -458,7 +462,7 @@ def main(args: argparse.Namespace | dict | None = None):
elif "component" in args: elif "component" in args:
run_component(args["component"], *args["args"]) run_component(args["component"], *args["args"])
elif not args["update_settings"]: elif not args["update_settings"]:
run_gui(path, args.get("args", ())) run_gui(args.get("launch_components", None), args.get("args", ()))
if __name__ == '__main__': if __name__ == '__main__':