From 9d83f491d9cf4f00ddf6ab727b95f8787021787c Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Sun, 11 Dec 2022 12:44:59 -0500 Subject: [PATCH] Always show persistent connections under a separate sub-menu Since version 11.30, we scan config-auto folder and show them in the menu of available connection profiles. To reduce user-confusion, always group these configs under a submenu ("Persistent Connections") even when nested config menu view is not in use. ActivateConfigGroups() is now always called as Persistent and System profile groups can now go from empty to non-empty on rescan. When nested config menu view is enabled, "persistent", "system" and "user" configs are always shown in separate groups. Signed-off-by: Selva Nair --- openvpn_config.c | 9 ++++----- options.h | 1 + tray.c | 40 +++++++++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/openvpn_config.c b/openvpn_config.c index a57c42a..f319cc0 100644 --- a/openvpn_config.c +++ b/openvpn_config.c @@ -26,6 +26,7 @@ #endif #include +#include #include "main.h" #include "openvpn-gui-res.h" @@ -438,6 +439,8 @@ BuildFileList() } /* else these parent groups use their saved values */ + assert (&o.groups[persistent_gp] == PERSISTENT_ROOT_GROUP); /* sanity check */ + if (issue_warnings) { flags |= FLAG_WARN_DUPLICATES | FLAG_WARN_MAX_CONFIGS; @@ -470,11 +473,7 @@ BuildFileList() o.num_configs = max_configs; /* management-port cant handle more -- ignore the rest */ } - /* if adding groups, activate non-empty ones */ - if (flags &FLAG_ADD_CONFIG_GROUPS) - { - ActivateConfigGroups(); - } + ActivateConfigGroups(); issue_warnings = false; } diff --git a/options.h b/options.h index 8910566..ab4bcbd 100644 --- a/options.h +++ b/options.h @@ -123,6 +123,7 @@ typedef struct config_group { /* short hand for pointer to the group a config belongs to */ #define CONFIG_GROUP(c) (&o.groups[(c)->group]) #define PARENT_GROUP(cg) ((cg)->parent < 0 ? NULL : &o.groups[(cg)->parent]) +#define PERSISTENT_ROOT_GROUP (&o.groups[1]) /* Connections parameters */ struct connection { diff --git a/tray.c b/tray.c index ff05bde..d79f21e 100644 --- a/tray.c +++ b/tray.c @@ -218,22 +218,25 @@ CreatePopupMenus() } else { /* construct the submenu tree first */ - if (USE_NESTED_CONFIG_MENU) + /* i = 0 is the root menu and has no parent */ + for (int i = 1; i < o.num_groups; i++) { - /* i = 0 is the root menu and has no parent */ - for (int i = 1; i < o.num_groups; i++) + config_group_t *this = &o.groups[i]; + config_group_t *parent = PARENT_GROUP(this); + + /* Root group of persistent connections is always displayed if active. + * Add the rest only if (USE_NESTED_CONFIG_MENU) + */ + if (!this->active || !parent + || (this != PERSISTENT_ROOT_GROUP && !USE_NESTED_CONFIG_MENU)) { - config_group_t *this = &o.groups[i]; - config_group_t *parent = PARENT_GROUP(this); - - if (!this->active || !parent) - continue; - AppendMenu(parent->menu, MF_POPUP, (UINT_PTR) this->menu, this->name); - this->pos = parent->children++; - - PrintDebug(L"Submenu %d named %ls added to parent %ls with position %d", - i, this->name, parent->name, this->pos); + continue; } + AppendMenu(parent->menu, MF_POPUP, (UINT_PTR) this->menu, this->name); + this->pos = parent->children++; + + PrintDebug(L"Submenu %d named %ls added to parent %ls with position %d", + i, this->name, parent->name, this->pos); } /* add config file (connection) entries */ @@ -246,6 +249,11 @@ CreatePopupMenus() { parent = CONFIG_GROUP(c); } + else if (c->flags & FLAG_DAEMON_PERSISTENT) + { + /* Persistent connections always displayed under a submenu */ + parent = PERSISTENT_ROOT_GROUP; + } assert(parent); /* Add config to the current sub menu */ @@ -554,7 +562,13 @@ SetMenuStatusById(int i, conn_state_t state) int pos = c->pos; if (USE_NESTED_CONFIG_MENU && CONFIG_GROUP(c)) + { parent = CONFIG_GROUP(c); + } + else if (c->flags & FLAG_DAEMON_PERSISTENT) + { + parent = PERSISTENT_ROOT_GROUP; + } if (checked == 1) {