Skip to content

Commit

Permalink
xapp-sn-watcher: Create StatusNotifierItem proxies asynchronously,
Browse files Browse the repository at this point in the history
and don't try to load their properties.

This will prevent any delay at login (since this starts in an early
session phase that waits for program registration).  We don't use
the properties anyhow (we use a dbus property interface instead),
and it was causing teamviewer to hang for 30s at startup.
  • Loading branch information
mtwebster committed Jun 21, 2020
1 parent d652d5b commit 624992e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 30 deletions.
1 change: 1 addition & 0 deletions libxapp/xapp-status-icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ xapp_status_icon_dispose (GObject *object)
g_free (self->priv->icon_name);
g_free (self->priv->tooltip_text);
g_free (self->priv->label);
g_free (self->priv->metadata);

g_clear_object (&self->priv->cancellable);

Expand Down
96 changes: 66 additions & 30 deletions xapp-sn-watcher/xapp-sn-watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ on_name_acquired (GDBusConnection *connection,
XAppSnWatcher *watcher = XAPP_SN_WATCHER (user_data);

g_debug ("Name acquired on dbus");

sn_watcher_interface_set_protocol_version (watcher->skeleton, 0);
sn_watcher_interface_set_is_status_notifier_host_registered (watcher->skeleton,
TRUE);
g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (watcher->skeleton));
Expand Down Expand Up @@ -295,6 +295,55 @@ create_key (const gchar *sender,
return TRUE;
}

typedef struct
{
XAppSnWatcher *watcher;
gchar *key;
gchar *path;
gchar *bus_name;
gchar *service;
} NewSnProxyData;

static void
sn_item_proxy_new_completed (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
NewSnProxyData *data = (NewSnProxyData *) user_data;
XAppSnWatcher *watcher = data->watcher;
SnItem *item;
GError *error = NULL;

SnItemInterface *proxy;

proxy = sn_item_interface_proxy_new_finish (res, &error);

if (error != NULL)
{
g_debug ("Could not create new status notifier proxy item for item at %s: %s",
data->bus_name, error->message);
return;
}

item = sn_item_new ((GDBusProxy *) proxy,
g_str_has_prefix (data->path, APPINDICATOR_PATH_PREFIX));

g_hash_table_insert (watcher->items,
g_strdup (data->key),
item);

update_published_items (watcher);

sn_watcher_interface_emit_status_notifier_item_registered (watcher->skeleton,
data->service);

g_free (data->key);
g_free (data->path);
g_free (data->bus_name);
g_free (data->service);
g_slice_free (NewSnProxyData, data);
}

static gboolean
handle_register_item (SnWatcherInterface *skeleton,
GDBusMethodInvocation *invocation,
Expand Down Expand Up @@ -322,40 +371,27 @@ handle_register_item (SnWatcherInterface *skeleton,

if (item == NULL)
{
SnItemInterface *proxy;
NewSnProxyData *data;
error = NULL;
g_debug ("Key: '%s'", key);

proxy = sn_item_interface_proxy_new_sync (watcher->connection,
G_DBUS_PROXY_FLAGS_NONE,
bus_name,
path,
NULL,
&error);

if (error != NULL)
{
g_debug ("Could not create new status notifier proxy item for item at %s: %s", bus_name, error->message);

g_dbus_method_invocation_return_gerror (invocation, error);

return FALSE;
}

item = sn_item_new ((GDBusProxy *) proxy,
g_str_has_prefix (path, APPINDICATOR_PATH_PREFIX));

g_hash_table_insert (watcher->items,
g_strdup (key),
item);

update_published_items (watcher);

sn_watcher_interface_emit_status_notifier_item_registered (skeleton,
service);
data = g_slice_new0 (NewSnProxyData);
data->watcher = watcher;
data->key = g_strdup (key);
data->path = g_strdup (path);
data->bus_name = g_strdup (bus_name);
data->service = g_strdup (service);

sn_item_interface_proxy_new (watcher->connection,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
bus_name,
path,
NULL,
sn_item_proxy_new_completed,
data);
}

sn_watcher_interface_complete_register_status_notifier_item (skeleton,
sn_watcher_interface_complete_register_status_notifier_item (watcher->skeleton,
invocation);

return TRUE;
Expand Down

1 comment on commit 624992e

@mtwebster
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message makes no sense -

  • Switched the creation of the proxy to asynchronous to prevent blocking at startup.
  • Stopped loading properties (G_DBUS_PROXY_DO_NOT_LOAD_PROPERTIES) because it was causing teamviewer to freeze (which was what caused the first item to happen). We don't use the proxy to get properties anyhow, so there's no downside here.

Please sign in to comment.