From Marc Jauvin, 1 Year ago, written in Plain Text.
Embed
  1. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
  2. index a0c5e63ff..a11ec8b21 100644
  3. --- a/qutebrowser/browser/commands.py
  4. +++ b/qutebrowser/browser/commands.py
  5. @@ -1217,10 +1217,18 @@ class CommandDispatcher:
  6.  
  7.          log.procs.debug("Executing {} with args {}, userscript={}".format(
  8.              cmd, args, userscript))
  9. +
  10. +        def _on_proc_finished():
  11. +            if output:
  12. +                tabbed_browser = objreg.get('tabbed-browser', scope='window',
  13. +                                            window='last-focused')
  14. +                tabbed_browser.openurl(QUrl('qute://spawn-output'), newtab=True)
  15. +
  16.          if userscript:
  17.              def _selection_callback(s):
  18.                  try:
  19. -                    self._run_userscript(s, cmd, args, verbose)
  20. +                    runner = self._run_userscript(s, cmd, args, verbose)
  21. +                    runner.finished.connect(_on_proc_finished)
  22.                  except cmdexc.CommandError as e:
  23.                      message.error(str(e))
  24.  
  25. @@ -1239,11 +1247,7 @@ class CommandDispatcher:
  26.                  proc.start_detached(cmd, args)
  27.              else:
  28.                  proc.start(cmd, args)
  29. -
  30. -        if output:
  31. -            tabbed_browser = objreg.get('tabbed-browser', scope='window',
  32. -                                        window='last-focused')
  33. -            tabbed_browser.openurl(QUrl('qute://spawn-output'), newtab=True)
  34. +            proc.finished.connect(_on_proc_finished)
  35.  
  36.      @cmdutils.register(instance='command-dispatcher', scope='window')
  37.      def home(self):
  38. @@ -1284,10 +1288,11 @@ class CommandDispatcher:
  39.              env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)
  40.  
  41.          try:
  42. -            userscripts.run_async(tab, cmd, *args, win_id=self._win_id,
  43. +            runner = userscripts.run_async(tab, cmd, *args, win_id=self._win_id,
  44.                                    env=env, verbose=verbose)
  45.          except userscripts.Error as e:
  46.              raise cmdexc.CommandError(e)
  47. +        return runner
  48.  
  49.      @cmdutils.register(instance='command-dispatcher', scope='window')
  50.      def quickmark_save(self):
  51. diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py
  52. index d86cb8ccf..fc6443eb3 100644
  53. --- a/qutebrowser/commands/userscripts.py
  54. +++ b/qutebrowser/commands/userscripts.py
  55. @@ -446,3 +446,4 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False):
  56.      runner.prepare_run(cmd_path, *args, env=env, verbose=verbose)
  57.      tab.dump_async(runner.store_html)
  58.      tab.dump_async(runner.store_text, plain=True)
  59. +    return runner
  60.