diff --git a/CommonClient.py b/CommonClient.py index 750bee80bd70..fe9df38dbdeb 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -994,7 +994,7 @@ def get_base_parser(description: typing.Optional[str] = None): return parser -def run_as_textclient(): +def run_as_textclient(*args): class TextContext(CommonContext): # Text Mode to use !hint and such with games that have no text entry tags = CommonContext.tags | {"TextOnly"} @@ -1033,7 +1033,7 @@ async def main(args): parser = get_base_parser(description="Gameless Archipelago Client, for text interfacing.") parser.add_argument('--name', default=None, help="Slot Name to connect as.") parser.add_argument("url", nargs="?", help="Archipelago connection url") - args = parser.parse_args() + args = parser.parse_args(args if args else None) # this is necessary as long as CommonClient itself is launchable if args.url: url = urllib.parse.urlparse(args.url) diff --git a/Launcher.py b/Launcher.py index 6b66b2a3a671..97903e2ad103 100644 --- a/Launcher.py +++ b/Launcher.py @@ -16,10 +16,11 @@ import shlex import subprocess import sys +import urllib.parse import webbrowser from os.path import isfile from shutil import which -from typing import Callable, Sequence, Union, Optional +from typing import Callable, Optional, Sequence, Tuple, Union import Utils import settings @@ -107,7 +108,81 @@ def update_settings(): ]) -def identify(path: Union[None, str]): +def handle_uri(path: str, launch_args: Tuple[str, ...]) -> None: + url = urllib.parse.urlparse(path) + queries = urllib.parse.parse_qs(url.query) + launch_args = (path, *launch_args) + client_component = None + text_client_component = None + if "game" in queries: + game = queries["game"][0] + else: # TODO around 0.6.0 - this is for pre this change webhost uri's + game = "Archipelago" + for component in components: + if component.supports_uri and component.game_name == game: + client_component = component + elif component.display_name == "Text Client": + text_client_component = component + + from kvui import App, Button, BoxLayout, Label, Clock, Window + + class Popup(App): + timer_label: Label + remaining_time: Optional[int] + + def __init__(self): + self.title = "Connect to Multiworld" + self.icon = r"data/icon.png" + super().__init__() + + def build(self): + layout = BoxLayout(orientation="vertical") + + if client_component is None: + self.remaining_time = 7 + label_text = (f"A game client able to parse URIs was not detected for {game}.\n" + f"Launching Text Client in 7 seconds...") + self.timer_label = Label(text=label_text) + layout.add_widget(self.timer_label) + Clock.schedule_interval(self.update_label, 1) + else: + layout.add_widget(Label(text="Select client to open and connect with.")) + button_row = BoxLayout(orientation="horizontal", size_hint=(1, 0.4)) + + text_client_button = Button( + text=text_client_component.display_name, + on_release=lambda *args: run_component(text_client_component, *launch_args) + ) + button_row.add_widget(text_client_button) + + game_client_button = Button( + text=client_component.display_name, + on_release=lambda *args: run_component(client_component, *launch_args) + ) + button_row.add_widget(game_client_button) + + layout.add_widget(button_row) + + return layout + + def update_label(self, dt): + if self.remaining_time > 1: + # countdown the timer and string replace the number + self.remaining_time -= 1 + self.timer_label.text = self.timer_label.text.replace( + str(self.remaining_time + 1), str(self.remaining_time) + ) + else: + # our timer is finished so launch text client and close down + run_component(text_client_component, *launch_args) + Clock.unschedule(self.update_label) + App.get_running_app().stop() + Window.close() + + Popup().run() + + +def identify(path: Union[None, str]) -> Tuple[Union[None, str], Union[None, Component]]: if path is None: return None, None for component in components: @@ -299,20 +374,24 @@ def main(args: Optional[Union[argparse.Namespace, dict]] = None): elif not args: args = {} - if args.get("Patch|Game|Component", None) is not None: - file, component = identify(args["Patch|Game|Component"]) + path = args.get("Patch|Game|Component|url", None) + if path is not None: + if path.startswith("archipelago://"): + handle_uri(path, args.get("args", ())) + return + file, component = identify(path) if file: args['file'] = file if component: args['component'] = component if not component: - logging.warning(f"Could not identify Component responsible for {args['Patch|Game|Component']}") + logging.warning(f"Could not identify Component responsible for {path}") if args["update_settings"]: update_settings() - if 'file' in args: + if "file" in args: run_component(args["component"], args["file"], *args["args"]) - elif 'component' in args: + elif "component" in args: run_component(args["component"], *args["args"]) elif not args["update_settings"]: run_gui() @@ -326,8 +405,9 @@ def main(args: Optional[Union[argparse.Namespace, dict]] = None): run_group = parser.add_argument_group("Run") run_group.add_argument("--update_settings", action="store_true", help="Update host.yaml and exit.") - run_group.add_argument("Patch|Game|Component", type=str, nargs="?", - help="Pass either a patch file, a generated game or the name of a component to run.") + run_group.add_argument("Patch|Game|Component|url", type=str, nargs="?", + help="Pass either a patch file, a generated game, the component name to run, or a url to " + "connect with.") run_group.add_argument("args", nargs="*", help="Arguments to pass to component.") main(parser.parse_args()) diff --git a/WebHostLib/templates/macros.html b/WebHostLib/templates/macros.html index 7bbb894de090..6b2a4b0ed784 100644 --- a/WebHostLib/templates/macros.html +++ b/WebHostLib/templates/macros.html @@ -22,7 +22,7 @@ {% for patch in room.seed.slots|list|sort(attribute="player_id") %}