[Common] Fix show_file unhandled dbus error
If dbus org.freedesktop.FileManager1 service is missing then show_file raised an unhandled exception. The service is not available on certain desktop environments e.g. i3wm. The solution is to fallback to xdg-open. Fixes: #3272
This commit is contained in:
parent
24b094a04a
commit
833b5a1f30
|
@ -81,6 +81,9 @@ TORRENT_STATE = [
|
|||
# The output formatting for json.dump
|
||||
JSON_FORMAT = {'indent': 4, 'sort_keys': True, 'ensure_ascii': False}
|
||||
|
||||
DBUS_FM_ID = 'org.freedesktop.FileManager1'
|
||||
DBUS_FM_PATH = '/org/freedesktop/FileManager1'
|
||||
|
||||
PY2 = sys.version_info.major == 2
|
||||
|
||||
|
||||
|
@ -355,20 +358,23 @@ def show_file(path, timestamp=None):
|
|||
timestamp,
|
||||
timestamp,
|
||||
)
|
||||
|
||||
if dbus:
|
||||
bus = dbus.SessionBus()
|
||||
filemanager1 = bus.get_object(
|
||||
'org.freedesktop.FileManager1', '/org/freedesktop/FileManager1'
|
||||
)
|
||||
paths = [urljoin('file:', pathname2url(path))]
|
||||
filemanager1.ShowItems(
|
||||
paths, startup_id, dbus_interface='org.freedesktop.FileManager1'
|
||||
)
|
||||
else:
|
||||
env = os.environ.copy()
|
||||
env['DESKTOP_STARTUP_ID'] = startup_id.replace('dbus', 'xdg-open')
|
||||
# No option in xdg to highlight a file so just open parent folder.
|
||||
subprocess.Popen(['xdg-open', os.path.dirname(path.rstrip('/'))], env=env)
|
||||
try:
|
||||
filemanager1 = bus.get_object(DBUS_FM_ID, DBUS_FM_PATH)
|
||||
except dbus.exceptions.DBusException as ex:
|
||||
log.debug('Unable to get dbus file manager: %s', ex)
|
||||
# Fallback to xdg-open
|
||||
else:
|
||||
paths = [urljoin('file:', pathname2url(path))]
|
||||
filemanager1.ShowItems(paths, startup_id, dbus_interface=DBUS_FM_ID)
|
||||
return
|
||||
|
||||
env = os.environ.copy()
|
||||
env['DESKTOP_STARTUP_ID'] = startup_id.replace('dbus', 'xdg-open')
|
||||
# No option in xdg to highlight a file so just open parent folder.
|
||||
subprocess.Popen(['xdg-open', os.path.dirname(path.rstrip('/'))], env=env)
|
||||
|
||||
|
||||
def open_url_in_browser(url):
|
||||
|
|
Loading…
Reference in New Issue