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 <selva.nair@gmail.com>
pull/561/head
Selva Nair 2022-12-11 12:44:59 -05:00
parent d24876c863
commit 9d83f491d9
3 changed files with 32 additions and 18 deletions

View File

@ -26,6 +26,7 @@
#endif
#include <windows.h>
#include <assert.h>
#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;
}

View File

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

40
tray.c
View File

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