mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-11 03:55:43 +00:00
[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
|
# The output formatting for json.dump
|
||||||
JSON_FORMAT = {'indent': 4, 'sort_keys': True, 'ensure_ascii': False}
|
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
|
PY2 = sys.version_info.major == 2
|
||||||
|
|
||||||
|
|
||||||
@ -355,16 +358,19 @@ def show_file(path, timestamp=None):
|
|||||||
timestamp,
|
timestamp,
|
||||||
timestamp,
|
timestamp,
|
||||||
)
|
)
|
||||||
|
|
||||||
if dbus:
|
if dbus:
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
filemanager1 = bus.get_object(
|
try:
|
||||||
'org.freedesktop.FileManager1', '/org/freedesktop/FileManager1'
|
filemanager1 = bus.get_object(DBUS_FM_ID, DBUS_FM_PATH)
|
||||||
)
|
except dbus.exceptions.DBusException as ex:
|
||||||
paths = [urljoin('file:', pathname2url(path))]
|
log.debug('Unable to get dbus file manager: %s', ex)
|
||||||
filemanager1.ShowItems(
|
# Fallback to xdg-open
|
||||||
paths, startup_id, dbus_interface='org.freedesktop.FileManager1'
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
|
paths = [urljoin('file:', pathname2url(path))]
|
||||||
|
filemanager1.ShowItems(paths, startup_id, dbus_interface=DBUS_FM_ID)
|
||||||
|
return
|
||||||
|
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['DESKTOP_STARTUP_ID'] = startup_id.replace('dbus', 'xdg-open')
|
env['DESKTOP_STARTUP_ID'] = startup_id.replace('dbus', 'xdg-open')
|
||||||
# No option in xdg to highlight a file so just open parent folder.
|
# No option in xdg to highlight a file so just open parent folder.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user