Override --backend argument from backend problem dialog

This commit is contained in:
Florian Bruhin 2017-09-28 08:30:28 +02:00
parent defcf5394a
commit e5958e6061
2 changed files with 27 additions and 10 deletions

View File

@ -513,12 +513,13 @@ class Quitter:
with tokenize.open(os.path.join(dirpath, fn)) as f: with tokenize.open(os.path.join(dirpath, fn)) as f:
compile(f.read(), fn, 'exec') compile(f.read(), fn, 'exec')
def _get_restart_args(self, pages=(), session=None): def _get_restart_args(self, pages=(), session=None, override_args=None):
"""Get the current working directory and args to relaunch qutebrowser. """Get the current working directory and args to relaunch qutebrowser.
Args: Args:
pages: The pages to re-open. pages: The pages to re-open.
session: The session to load, or None. session: The session to load, or None.
override_args: Argument overrides as a dict.
Return: Return:
An (args, cwd) tuple. An (args, cwd) tuple.
@ -569,6 +570,9 @@ class Quitter:
argdict['temp_basedir'] = False argdict['temp_basedir'] = False
argdict['temp_basedir_restarted'] = True argdict['temp_basedir_restarted'] = True
if override_args is not None:
argdict.update(override_args)
# Dump the data # Dump the data
data = json.dumps(argdict) data = json.dumps(argdict)
args += ['--json-args', data] args += ['--json-args', data]
@ -593,7 +597,7 @@ class Quitter:
if ok: if ok:
self.shutdown(restart=True) self.shutdown(restart=True)
def restart(self, pages=(), session=None): def restart(self, pages=(), session=None, override_args=None):
"""Inner logic to restart qutebrowser. """Inner logic to restart qutebrowser.
The "better" way to restart is to pass a session (_restart usually) as The "better" way to restart is to pass a session (_restart usually) as
@ -606,6 +610,7 @@ class Quitter:
Args: Args:
pages: A list of URLs to open. pages: A list of URLs to open.
session: The session to load, or None. session: The session to load, or None.
override_args: Argument overrides as a dict.
Return: Return:
True if the restart succeeded, False otherwise. True if the restart succeeded, False otherwise.
@ -621,7 +626,7 @@ class Quitter:
session_manager.save(session, with_private=True) session_manager.save(session, with_private=True)
# Open a new process and immediately shutdown the existing one # Open a new process and immediately shutdown the existing one
try: try:
args, cwd = self._get_restart_args(pages, session) args, cwd = self._get_restart_args(pages, session, override_args)
if cwd is None: if cwd is None:
subprocess.Popen(args) subprocess.Popen(args)
else: else:

View File

@ -35,8 +35,10 @@ from qutebrowser.utils import usertypes, objreg, version, qtutils, log
from qutebrowser.misc import objects, msgbox from qutebrowser.misc import objects, msgbox
_Result = usertypes.enum('_Result', ['quit', 'restart'], is_int=True, _Result = usertypes.enum(
start=QDialog.Accepted + 1) '_Result',
['quit', 'restart', 'restart_webkit', 'restart_webengine'],
is_int=True, start=QDialog.Accepted + 1)
@attr.s @attr.s
@ -105,7 +107,13 @@ class _Dialog(QDialog):
config.instance.set_obj(setting, value, save_yaml=True) config.instance.set_obj(setting, value, save_yaml=True)
save_manager = objreg.get('save-manager') save_manager = objreg.get('save-manager')
save_manager.save_all(is_exit=True) save_manager.save_all(is_exit=True)
self.done(_Result.restart)
if setting == 'backend' and value == 'webkit':
self.done(_Result.restart_webkit)
elif setting == 'backend' and value == 'webengine':
self.done(_Result.restart_webengine)
else:
self.done(_Result.restart)
def _show_dialog(*args, **kwargs): def _show_dialog(*args, **kwargs):
@ -113,17 +121,21 @@ def _show_dialog(*args, **kwargs):
dialog = _Dialog(*args, **kwargs) dialog = _Dialog(*args, **kwargs)
status = dialog.exec_() status = dialog.exec_()
quitter = objreg.get('quitter')
if status in [_Result.quit, QDialog.Rejected]: if status in [_Result.quit, QDialog.Rejected]:
sys.exit(usertypes.Exit.err_init) pass
elif status == _Result.restart_webkit:
quitter.restart(override_args={'backend': 'webkit'})
elif status == _Result.restart_webengine:
quitter.restart(override_args={'backend': 'webengine'})
elif status == _Result.restart: elif status == _Result.restart:
# FIXME pass --backend webengine
quitter = objreg.get('quitter')
quitter.restart() quitter.restart()
sys.exit(usertypes.Exit.err_init)
else: else:
assert False, status assert False, status
sys.exit(usertypes.Exit.err_init)
def _handle_nouveau_graphics(): def _handle_nouveau_graphics():
force_sw_var = 'QT_XCB_FORCE_SOFTWARE_OPENGL' force_sw_var = 'QT_XCB_FORCE_SOFTWARE_OPENGL'