Add restart command

This commit is contained in:
Florian Bruhin 2014-05-14 08:56:42 +02:00
parent 4a2fee8b1c
commit e786fe4e82

View File

@ -427,17 +427,7 @@ class QuteBrowser(QApplication):
dlg = CrashDialog(pages, history, exc)
ret = dlg.exec_()
if ret == QDialog.Accepted: # restore
os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
argv = sys.argv[:]
for page in self._opened_urls:
try:
argv.remove(page)
except ValueError:
pass
argv = [sys.executable] + argv + pages
logging.debug("Running {} with args {}".format(sys.executable,
argv))
subprocess.Popen(argv)
self.restart(shutdown=False, pages=pages)
# We might risk a segfault here, but that's better than continuing to
# run in some undefined state.
sys.exit(1)
@ -458,6 +448,31 @@ class QuteBrowser(QApplication):
logging.debug("maybe_quit quitting.")
self.quit()
@cmdutils.register(instance='', nargs=0)
def restart(self, shutdown=True, pages=None):
"""Restart qutebrowser while keeping existing tabs open."""
# We don't use _recover_pages here as it's too forgiving when
# exceptions occur.
if pages is None:
pages = []
for tab in self.mainwindow.tabs.widgets:
url = tab.url().toString()
if url:
pages.append(url)
os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
argv = sys.argv[:]
for page in self._opened_urls:
try:
argv.remove(page)
except ValueError:
pass
argv = [sys.executable] + argv + pages
logging.debug("Running {} with args {}".format(sys.executable,
argv))
subprocess.Popen(argv)
if shutdown:
self.shutdown()
@cmdutils.register(instance='', split=False)
def pyeval(self, s):
"""Evaluate a python string and display the results as a webpage.