Hi Bastien, On Tue, May 13, 2025 at 5:58 AM Bastien Nocera <hadess@xxxxxxxxxx> wrote: > > --- > client/assistant.c | 11 +++++++++-- > client/assistant.h | 1 - > client/main.c | 2 -- > 3 files changed, 9 insertions(+), 5 deletions(-) > > diff --git a/client/assistant.c b/client/assistant.c > index 555ac6feb048..6d172a8d8e81 100644 > --- a/client/assistant.c > +++ b/client/assistant.c > @@ -55,6 +55,8 @@ static DBusConnection *dbus_conn; > > static GList *assistants; > > +static void assistant_menu_pre_run(const struct bt_shell_menu *menu); > + > static char *proxy_description(GDBusProxy *proxy, const char *title, > const char *description) > { > @@ -384,6 +386,7 @@ fail: > static const struct bt_shell_menu assistant_menu = { > .name = "assistant", > .desc = "Media Assistant Submenu", > + .pre_run = assistant_menu_pre_run, > .entries = { > { "push", "<assistant>", cmd_push_assistant, > "Send stream information to peer" }, > @@ -397,10 +400,12 @@ void assistant_add_submenu(void) > bt_shell_add_submenu(&assistant_menu); > } > > -void assistant_enable_submenu(void) > +static bool pre_run_done = false; Is the flag above really required though, I mean the bt_shell_run shall only be run once and even if that is no the case the shell itself could be doing the checking if the submenu.pre_run has been called, anyway if that is required Id say we do this in a separate patch, just let me know since I can drop the use of pre_run_done flag while applying these changes. > +static void assistant_menu_pre_run(const struct bt_shell_menu *menu) > { > dbus_conn = bt_shell_get_env("DBUS_CONNECTION"); > - if (!dbus_conn || client) > + if (pre_run_done || !dbus_conn || client) > return; > > client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez"); > @@ -408,6 +413,8 @@ void assistant_enable_submenu(void) > g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed, > property_changed, NULL); > g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL); > + > + pre_run_done = true; > } > > void assistant_remove_submenu(void) > diff --git a/client/assistant.h b/client/assistant.h > index c304abea0515..418b0b84031f 100644 > --- a/client/assistant.h > +++ b/client/assistant.h > @@ -9,6 +9,5 @@ > */ > > void assistant_add_submenu(void); > -void assistant_enable_submenu(void); > void assistant_remove_submenu(void); > > diff --git a/client/main.c b/client/main.c > index 06ae25c9d8e9..36a7446d52c1 100644 > --- a/client/main.c > +++ b/client/main.c > @@ -3426,8 +3426,6 @@ int main(int argc, char *argv[]) > bt_shell_set_env("AUTO_REGISTER_ENDPOINT", > (void *)endpoint_option); > > - assistant_enable_submenu(); > - > client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez"); > > g_dbus_client_set_connect_watch(client, connect_handler, NULL); > -- > 2.49.0 > > -- Luiz Augusto von Dentz