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) {