[GTK] Fix file manager window popup behind Deluge

Added 'TIMESTAMP' key to startup-id string for dbus method. Unsure if
this is the correct way to specify startup id but it seems to work.

Recreate the dbus session with each call since if there is an error
with the dbus method then it will crash and subsequent calls will fail
with a cryptic message:

   dbus error the name was not provided by any .service files
This commit is contained in:
Calum Lind 2018-11-17 13:12:35 +00:00
parent 389f4167b2
commit b2e19561e6
1 changed files with 9 additions and 13 deletions

View File

@ -53,21 +53,12 @@ if platform.system() in ('Windows', 'Microsoft'):
os.environ['SSL_CERT_FILE'] = where()
DBUS_FILEMAN = None
# gi makes dbus available on Window but don't import it as unused.
if platform.system() not in ('Windows', 'Microsoft', 'Darwin'):
try:
import dbus
except ImportError:
pass
else:
try:
bus = dbus.SessionBus()
DBUS_FILEMAN = bus.get_object(
'org.freedesktop.FileManager1', '/org/freedesktop/FileManager1'
)
except dbus.DBusException:
pass
dbus = None
log = logging.getLogger(__name__)
@ -352,15 +343,20 @@ def show_file(path, timestamp=None):
else:
if timestamp is None:
timestamp = int(time.time())
startup_id = '%s_%u_%s-dbus_TIME%d' % (
startup_id = '%s_%u_%s-dbus_TIME%d TIMESTAMP=%d' % (
os.path.basename(sys.argv[0]),
os.getpid(),
os.uname()[1],
timestamp,
timestamp,
)
if DBUS_FILEMAN:
if dbus:
bus = dbus.SessionBus()
filemanager1 = bus.get_object(
'org.freedesktop.FileManager1', '/org/freedesktop/FileManager1'
)
paths = [urljoin('file:', pathname2url(path))]
DBUS_FILEMAN.ShowItems(
filemanager1.ShowItems(
paths, startup_id, dbus_interface='org.freedesktop.FileManager1'
)
else: