[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
commit b2e19561e6

View file

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