diff options
Diffstat (limited to 'app/ui/hub.py')
| -rw-r--r-- | app/ui/hub.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/app/ui/hub.py b/app/ui/hub.py index 9282fa7..a8c167e 100644 --- a/app/ui/hub.py +++ b/app/ui/hub.py @@ -365,22 +365,28 @@ class _Hub: continue if not ok: return tui.Wizard.BACK - self._run_conversion(cmd[1], cmd[2]) + if self._run_conversion(cmd[1], cmd[2]): + # "Stop server and exit after generating" was on: returning + # None ends the wizard stack (the whole TUI). + return None return tui.Wizard.BACK - def _run_conversion(self, backend: str, kwargs: dict) -> None: + def _run_conversion(self, backend: str, kwargs: dict) -> bool: """Run a conversion in the full-screen run view on this session. - A crash inside the view cancels the worker and flashes an error - instead of taking the whole hub down; the timed getch the run view - leaves behind is reset so the hub menus still block for keys. + Returns True when the run view's stop-and-exit toggle was on — the + caller then quits the whole TUI (results are printed after curses + closes) instead of landing back on the menu. A crash inside the view + cancels the worker and flashes an error instead of taking the whole + hub down; the timed getch the run view leaves behind is reset so the + hub menus still block for keys. """ run_config = _prepare_run_config(backend, kwargs) if run_config is None: - return + return False view = runview.RunView(self.stdscr, run_config) try: - view.run() + return bool(view.run()) except tui.WizardCancelled: pass except KeyboardInterrupt: @@ -394,6 +400,7 @@ class _Hub: self.stdscr.timeout(-1) except Exception: pass + return False # -- settings ------------------------------------------------------- @@ -843,6 +850,8 @@ def _common_fields() -> list: "kind": "bool", "value": False, "visible": lambda fs: _field_value(fs, "output_format") != "m4b"}, {"key": "debug", "label": "Debug", "kind": "bool", "value": False}, + {"key": "stop_and_exit", "label": "Stop server and exit after " + "generating", "kind": "bool", "value": True}, ] @@ -855,6 +864,7 @@ def _common_kwargs(values: dict) -> dict: "single_file": bool(values["single_file"]) and output_format != "m4b", "debug": bool(values["debug"]), + "stop_and_exit": bool(values["stop_and_exit"]), } @@ -1411,6 +1421,9 @@ def _prepare_run_config(backend: str, kwargs: dict LOGS_FOLDER.mkdir(parents=True, exist_ok=True) Path(log_path).touch() autostart = kwargs.pop("autostart", None) + # The run-view behavior toggle (not a converter kwarg): stop the server + # and quit the TUI once the generation ends. + stop_and_exit = bool(kwargs.pop("stop_and_exit", False)) # book_files/planned travel on the dedicated RunConfig fields; keeping # them in kwargs too would collide with convert()'s named parameters. book_files = kwargs.pop("book_files", None) or [] @@ -1424,7 +1437,7 @@ def _prepare_run_config(backend: str, kwargs: dict kwargs=kwargs, book_files=book_files, planned=planned, server_url=api_url, server_identity=identity, - log_path=log_path) + log_path=log_path, stop_and_exit=stop_and_exit) status = next((s for s in detect_all() if s.key == backend), None) notice = "" @@ -1448,7 +1461,7 @@ def _prepare_run_config(backend: str, kwargs: dict server_url=spec.url if spec is not None else None, server_identity=spec.identity if spec is not None else None, autostart_spec=spec if autostart else None, - log_path=log_path, notice=notice) + log_path=log_path, notice=notice, stop_and_exit=stop_and_exit) def _remote_identity(backend: str, kwargs: dict) -> Optional[str]: |
