Linux: Workaround for systems with broken xdg-open implementations that do not unquote urls before passing them to applications

This commit is contained in:
Kovid Goyal 2015-09-13 09:31:51 +05:30
parent 2af36a378b
commit 7bae9efc65

View File

@ -3,7 +3,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
""" The GUI """
import os, sys, Queue, threading, glob
from contextlib import contextmanager
from threading import RLock, Lock
from threading import RLock, Lock, Thread
from urllib import unquote
from PyQt5.QtWidgets import QStyle # Gives a nicer error message than import from Qt
from PyQt5.Qt import (
@ -1140,6 +1140,15 @@ def open_local_file(path):
if iswindows:
with sanitize_env_vars():
os.startfile(os.path.normpath(path))
elif islinux or isbsd:
import subprocess
if isinstance(path, unicode):
path = path.encode(filesystem_encoding)
with sanitize_env_vars():
p = subprocess.Popen(['xdg-open', path])
t = Thread(name='WaitXDGOpen', target=p.wait)
t.daemon = True
t.start()
else:
url = QUrl.fromLocalFile(path)
open_url(url)