Merge remote-tracking branch 'origin/pr/3055'

This commit is contained in:
Florian Bruhin 2017-10-11 14:37:59 +02:00
commit 1b5f1aaebf
4 changed files with 86 additions and 22 deletions

View File

@ -71,9 +71,5 @@ coll = COLLECT(exe,
app = BUNDLE(coll,
name='qutebrowser.app',
icon=icon,
info_plist={
'NSHighResolutionCapable': 'True',
'NSSupportsAutomaticGraphicsSwitching': 'True',
},
# https://github.com/pyinstaller/pyinstaller/blob/b78bfe530cdc2904f65ce098bdf2de08c9037abb/PyInstaller/hooks/hook-PyQt5.QtWebEngineWidgets.py#L24
bundle_identifier='org.qt-project.Qt.QtWebEngineCore')

View File

@ -288,11 +288,7 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None):
if via_ipc and target_arg and target_arg != 'auto':
open_target = target_arg
else:
open_target = config.val.new_instance_open_target
win_id = mainwindow.get_window(via_ipc, force_target=open_target)
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
log.init.debug("Startup URL {}".format(cmd))
open_target = None
if not cwd: # could also be an empty string due to the PyQt signal
cwd = None
try:
@ -301,9 +297,30 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None):
message.error("Error in startup argument '{}': {}".format(
cmd, e))
else:
background = open_target in ['tab-bg', 'tab-bg-silent']
tabbed_browser.tabopen(url, background=background,
related=False)
win_id = open_url(url, target=open_target, via_ipc=via_ipc)
def open_url(url, target=None, no_raise=False, via_ipc=True):
"""Open an URL in new window/tab
Args:
url: An URL to open
target: same as new_instance_open_target (used as a default)
no_raise: suppress target window raising
via_ipc: Whether the arguments were transmitted over IPC.
Return:
ID of a window that was used to open URL
"""
target = target or config.val.new_instance_open_target
background = target in {'tab-bg', 'tab-bg-silent'}
win_id = mainwindow.get_window(via_ipc, force_target=target,
no_raise=no_raise)
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
log.init.debug("About to open URL: {}".format(url.toDisplayString()))
tabbed_browser.tabopen(url, background=background, related=False)
return win_id
def _open_startpage(win_id=None):
@ -810,6 +827,14 @@ class Application(QApplication):
log.misc.debug("Focus object changed: {}".format(output))
self._last_focus_object = output
def event(self, e):
if e.type() == QEvent.FileOpen:
open_url(e.url(), no_raise=True)
else:
return super().event(e)
return True
def __repr__(self):
return utils.get_repr(self)

View File

@ -43,7 +43,7 @@ win_id_gen = itertools.count(0)
def get_window(via_ipc, force_window=False, force_tab=False,
force_target=None):
force_target=None, no_raise=False):
"""Helper function for app.py to get a window id.
Args:
@ -51,6 +51,10 @@ def get_window(via_ipc, force_window=False, force_tab=False,
force_window: Whether to force opening in a window.
force_tab: Whether to force opening in a tab.
force_target: Override the new_instance_open_target config
no_raise: suppress target window raising
Return:
ID of a window that was used to open URL
"""
if force_window and force_tab:
raise ValueError("force_window and force_tab are mutually exclusive!")
@ -71,29 +75,33 @@ def get_window(via_ipc, force_window=False, force_tab=False,
open_target = 'tab-silent'
window = None
raise_window = False
should_raise = False
# Try to find the existing tab target if opening in a tab
if open_target != 'window':
window = get_target_window()
raise_window = open_target not in ['tab-silent', 'tab-bg-silent']
should_raise = open_target not in ['tab-silent', 'tab-bg-silent']
# Otherwise, or if no window was found, create a new one
if window is None:
window = MainWindow(private=None)
window.show()
raise_window = True
should_raise = True
if raise_window:
window.setWindowState(window.windowState() & ~Qt.WindowMinimized)
window.setWindowState(window.windowState() | Qt.WindowActive)
window.raise_()
window.activateWindow()
QApplication.instance().alert(window)
if should_raise and not no_raise:
raise_window(window)
return window.win_id
def raise_window(window):
window.setWindowState(window.windowState() & ~Qt.WindowMinimized)
window.setWindowState(window.windowState() | Qt.WindowActive)
window.raise_()
window.activateWindow()
QApplication.instance().alert(window)
def get_target_window():
"""Get the target window for new tabs, or None if none exist."""
try:

View File

@ -26,6 +26,7 @@ import sys
import glob
import os.path
import shutil
import plistlib
import subprocess
import argparse
import tarfile
@ -123,6 +124,40 @@ def patch_mac_app():
os.symlink(os.path.join(os.pardir, os.pardir, os.pardir, 'Contents',
'MacOS', lib),
os.path.join(dest, lib))
# Patch Info.plist - pyinstaller's options are too limiting
plist_path = os.path.join(app_path, 'Contents', 'Info.plist')
with open(plist_path, "rb") as f:
plist_data = plistlib.load(f)
plist_data.update(INFO_PLIST_UPDATES)
with open(plist_path, "wb") as f:
plistlib.dump(plist_data, f)
INFO_PLIST_UPDATES = {
'CFBundleVersion': qutebrowser.__version__,
'CFBundleShortVersionString': qutebrowser.__version__,
'NSSupportsAutomaticGraphicsSwitching': True,
'NSHighResolutionCapable': True,
'CFBundleURLTypes': [{
"CFBundleURLName": "http(s) URL",
"CFBundleURLSchemes": ["http", "https"]
}, {
"CFBundleURLName": "local file URL",
"CFBundleURLSchemes": ["file"]
}],
'CFBundleDocumentTypes': [{
"CFBundleTypeExtensions": ["html", "htm"],
"CFBundleTypeMIMETypes": ["text/html"],
"CFBundleTypeName": "HTML document",
"CFBundleTypeOSTypes": ["HTML"],
"CFBundleTypeRole": "Viewer",
}, {
"CFBundleTypeExtensions": ["xhtml"],
"CFBundleTypeMIMETypes": ["text/xhtml"],
"CFBundleTypeName": "XHTML document",
"CFBundleTypeRole": "Viewer",
}]
}
def build_mac():