mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
DRYer
This commit is contained in:
parent
d6f88ab9d0
commit
52ebc78095
@ -1451,22 +1451,25 @@ def open_url(qurl):
|
|||||||
import shlex
|
import shlex
|
||||||
opener = shlex.split(spec)
|
opener = shlex.split(spec)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def run_cmd(cmd):
|
||||||
|
import subprocess
|
||||||
|
subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
with sanitize_env_vars():
|
with sanitize_env_vars():
|
||||||
if opener:
|
if opener:
|
||||||
import subprocess
|
|
||||||
cmd = [x.replace('%u', qurl.toString()) for x in opener]
|
cmd = [x.replace('%u', qurl.toString()) for x in opener]
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print('Running opener:', cmd)
|
print('Running opener:', cmd)
|
||||||
subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
run_cmd(cmd)
|
||||||
else:
|
else:
|
||||||
# Qt 5 requires QApplication to be constructed before trying to use
|
# Qt 5 requires QApplication to be constructed before trying to use
|
||||||
# QDesktopServices::openUrl()
|
# QDesktopServices::openUrl()
|
||||||
ensure_app()
|
ensure_app()
|
||||||
cmd = ['xdg-open', qurl.toLocalFile() if qurl.isLocalFile() else qurl.toString(QUrl.ComponentFormattingOption.FullyEncoded)]
|
cmd = ['xdg-open', qurl.toLocalFile() if qurl.isLocalFile() else qurl.toString(QUrl.ComponentFormattingOption.FullyEncoded)]
|
||||||
if isfrozen and QApplication.instance().platformName() == "wayland":
|
if isfrozen and QApplication.instance().platformName() == "wayland":
|
||||||
import subprocess
|
|
||||||
# See https://bugreports.qt.io/browse/QTBUG-119438
|
# See https://bugreports.qt.io/browse/QTBUG-119438
|
||||||
subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
run_cmd(cmd)
|
||||||
ok = True
|
ok = True
|
||||||
else:
|
else:
|
||||||
ok = QDesktopServices.openUrl(qurl)
|
ok = QDesktopServices.openUrl(qurl)
|
||||||
@ -1476,10 +1479,9 @@ def open_url(qurl):
|
|||||||
# xdg activation token system Wayland imposes.
|
# xdg activation token system Wayland imposes.
|
||||||
print('QDesktopServices::openUrl() failed for url:', qurl, file=sys.stderr)
|
print('QDesktopServices::openUrl() failed for url:', qurl, file=sys.stderr)
|
||||||
if islinux:
|
if islinux:
|
||||||
import subprocess
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print('Running opener:', cmd)
|
print('Opening with xdg-open:', cmd)
|
||||||
subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
run_cmd(cmd)
|
||||||
|
|
||||||
|
|
||||||
def safe_open_url(qurl):
|
def safe_open_url(qurl):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user