parent
d30ec95f72
commit
e23360bb88
@ -210,19 +210,23 @@ class Application(QApplication):
|
|||||||
self._open_startpage()
|
self._open_startpage()
|
||||||
self._open_quickstart()
|
self._open_quickstart()
|
||||||
|
|
||||||
def _get_window(self, via_ipc, args_empty):
|
def _get_window(self, via_ipc, force_window=False, force_tab=False):
|
||||||
"""Helper function for process_args to get a window id.
|
"""Helper function for process_args to get a window id.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
via_ipc: Whether the request was made via IPC.
|
via_ipc: Whether the request was made via IPC.
|
||||||
args_empty: Whether there are no arguments.
|
force_window: Whether to force opening in a window.
|
||||||
|
force_tab: Whether to force opening in a tab.
|
||||||
"""
|
"""
|
||||||
|
if force_window and force_tab:
|
||||||
|
raise ValueError("force_window and force_tab are mutually "
|
||||||
|
"exclusive!")
|
||||||
if not via_ipc:
|
if not via_ipc:
|
||||||
# Initial main window
|
# Initial main window
|
||||||
return 0
|
return 0
|
||||||
window_to_raise = None
|
window_to_raise = None
|
||||||
open_target = config.get('general', 'new-instance-open-target')
|
open_target = config.get('general', 'new-instance-open-target')
|
||||||
if open_target == 'window' or args_empty:
|
if (open_target == 'window' or force_window) and not force_tab:
|
||||||
win_id = mainwindow.MainWindow.spawn()
|
win_id = mainwindow.MainWindow.spawn()
|
||||||
window = objreg.get('main-window', scope='window', window=win_id)
|
window = objreg.get('main-window', scope='window', window=win_id)
|
||||||
window_to_raise = window
|
window_to_raise = window
|
||||||
@ -256,18 +260,23 @@ class Application(QApplication):
|
|||||||
args: A list of arguments to process.
|
args: A list of arguments to process.
|
||||||
via_ipc: Whether the arguments were transmitted over IPC.
|
via_ipc: Whether the arguments were transmitted over IPC.
|
||||||
"""
|
"""
|
||||||
win_id = self._get_window(via_ipc, not args)
|
|
||||||
if ipc and not args:
|
if ipc and not args:
|
||||||
|
win_id = self._get_window(via_ipc, force_window=True)
|
||||||
self._open_startpage(win_id)
|
self._open_startpage(win_id)
|
||||||
|
return
|
||||||
|
win_id = None
|
||||||
for cmd in args:
|
for cmd in args:
|
||||||
if cmd.startswith(':'):
|
if cmd.startswith(':'):
|
||||||
|
if win_id is None:
|
||||||
|
win_id = self._get_window(via_ipc, force_tab=True)
|
||||||
log.init.debug("Startup cmd {}".format(cmd))
|
log.init.debug("Startup cmd {}".format(cmd))
|
||||||
commandrunner = runners.CommandRunner(win_id)
|
commandrunner = runners.CommandRunner(win_id)
|
||||||
commandrunner.run_safely_init(cmd.lstrip(':'))
|
commandrunner.run_safely_init(cmd.lstrip(':'))
|
||||||
elif not cmd:
|
elif not cmd:
|
||||||
log.init.debug("Empty argument")
|
log.init.debug("Empty argument")
|
||||||
win_id = mainwindow.MainWindow.spawn()
|
win_id = self._get_window(via_ipc, force_window=True)
|
||||||
else:
|
else:
|
||||||
|
win_id = self._get_window(via_ipc)
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
log.init.debug("Startup URL {}".format(cmd))
|
log.init.debug("Startup URL {}".format(cmd))
|
||||||
@ -743,7 +752,7 @@ class Application(QApplication):
|
|||||||
@pyqtSlot(QUrl)
|
@pyqtSlot(QUrl)
|
||||||
def open_desktopservices_url(self, url):
|
def open_desktopservices_url(self, url):
|
||||||
"""Handler to open an URL via QDesktopServices."""
|
"""Handler to open an URL via QDesktopServices."""
|
||||||
win_id = self._get_window(True, False)
|
win_id = self._get_window(via_ipc=True, force_window=False)
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
tabbed_browser.tabopen(url)
|
tabbed_browser.tabopen(url)
|
||||||
|
Loading…
Reference in New Issue
Block a user