diff --git a/main.c b/main.c index 115e5fe..d7b3049 100644 --- a/main.c +++ b/main.c @@ -387,7 +387,7 @@ AutoStartConnections() for (i = 0; i < o.num_configs; i++) { - if (o.conn[i].auto_connect) + if (o.conn[i].auto_connect && !(o.conn[i].flags & FLAG_DAEMON_PERSISTENT)) StartOpenVPN(&o.conn[i]); } @@ -529,6 +529,7 @@ ManagePersistent(HWND hwnd, UINT UNUSED msg, UINT_PTR id, DWORD UNUSED now) * connect. */ o.conn[i].auto_connect = false; + o.conn[i].state = detached; /* this is required to retain management-hold on re-attach */ StartOpenVPN(&o.conn[i]); /* attach to the management i/f */ } } @@ -617,7 +618,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM break; } /* A timer to periodically tend to persistent connections */ - SetTimer(hwnd, 0, 10000, ManagePersistent); + SetTimer(hwnd, 0, 100, ManagePersistent); break; diff --git a/openvpn.c b/openvpn.c index 1cd8d32..322c6b6 100644 --- a/openvpn.c +++ b/openvpn.c @@ -1347,7 +1347,6 @@ OnStop(connection_t *c, UNUSED char *msg) if (c->flags & FLAG_DAEMON_PERSISTENT) { /* user initiated disconnection -- stay detached and do not auto-reconnect */ - c->state = detached; c->auto_connect = false; } CheckAndSetTrayIcon(); @@ -1358,7 +1357,7 @@ OnStop(connection_t *c, UNUSED char *msg) case onhold: /* stop triggered while on hold -- possibly the daemon exited. Treat same as detaching */ case detaching: - c->state = detached; + c->state = disconnected; CheckAndSetTrayIcon(); SendMessage(c->hwndStatus, WM_CLOSE, 0, 0); break; @@ -2136,9 +2135,13 @@ ThreadOpenVPNStatus(void *p) wait_event = c->hProcess; } - /* For persistent connections, popup the status win only if we're in manual mode */ - if (o.silent_connection == 0 && ((c->flags & FLAG_DAEMON_PERSISTENT) == 0 || o.enable_persistent == 1)) - ShowWindow(c->hwndStatus, SW_SHOW); + /* For persistent connections, popup the status win only if we're connecting manually */ + BOOL show_status_win = (o.silent_connection == 0); + if ((c->flags & FLAG_DAEMON_PERSISTENT) && c->state == resuming) + { + show_status_win = false; + } + ShowWindow(c->hwndStatus, show_status_win ? SW_SHOW : SW_HIDE); /* Load echo msg histroy from registry */ echo_msg_load(c); diff --git a/openvpn_config.c b/openvpn_config.c index 8b3a5aa..f105739 100644 --- a/openvpn_config.c +++ b/openvpn_config.c @@ -421,9 +421,13 @@ BuildFileList() /* * If no connections are active reset num_configs and rescan * to make a new list. Else we keep all current configs and - * rescan to add any new one's found + * rescan to add any new one's found. + * Do the same when persistent connections are in auto-attach mode, + * to avoid over-writing their status info such as auto_connect=false + * after manual detach. */ - if (!o.num_groups || CountConnState(disconnected) == o.num_configs) + if (!o.num_groups + || (CountConnState(disconnected) == o.num_configs && o.enable_persistent != 2)) { o.num_configs = 0; o.num_groups = 0;