From f8a243fbe892238256148581f7ec462f603dd031 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Thu, 19 Jan 2023 18:42:31 -0500 Subject: [PATCH] Remove tray icon during exit processing During the wait for threads to exit, we no longer sleep, but continue pumping messages. Disable the tray icon during this period to not allow user interaction with the main menu. Signed-off-by: Selva Nair --- main.c | 7 +++++++ tray.c | 12 ++++++++++-- tray.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 0505855..5263e08 100644 --- a/main.c +++ b/main.c @@ -357,6 +357,8 @@ StopAllOpenVPN() { int i; + RemoveTrayIcon(); + /* Stop all connections started by us -- we leave persistent ones * at their current state. Use the disconnect menu to put them into * hold state before exit, if desired. @@ -849,6 +851,8 @@ ShowSettingsDialog() void CloseApplication(HWND hwnd, BOOL ask_user) { + /* Do not let user access main menu through tray icon */ + RemoveTrayIcon(); /* Show a message if any non-persistent connections are active */ for (connection_t *c = o.chead; c && ask_user; c = c->next) { @@ -861,6 +865,9 @@ CloseApplication(HWND hwnd, BOOL ask_user) /* Ask for confirmation if still connected */ if (ShowLocalizedMsgEx(MB_YESNO|MB_TOPMOST, o.hWnd, _T("Exit OpenVPN"), IDS_NFO_ACTIVE_CONN_EXIT) == IDNO) { + /* recreate the tray icon */ + ShowTrayIcon(); + CheckAndSetTrayIcon(); return; } break; /* show the above message box only once */ diff --git a/tray.c b/tray.c index dd0a21b..f1b9c81 100644 --- a/tray.c +++ b/tray.c @@ -388,15 +388,23 @@ OnNotifyTray(LPARAM lParam) } } +void +RemoveTrayIcon() +{ + if (ni.hWnd) + { + Shell_NotifyIcon(NIM_DELETE, &ni); + CLEAR(ni); + } +} void OnDestroyTray() { DestroyMenu(hMenu); - Shell_NotifyIcon(NIM_DELETE, &ni); + RemoveTrayIcon(); } - void ShowTrayIcon() { diff --git a/tray.h b/tray.h index b6f5a94..3f4e69b 100644 --- a/tray.h +++ b/tray.h @@ -50,6 +50,7 @@ void CreatePopupMenus(); void OnNotifyTray(LPARAM); void OnDestroyTray(void); void ShowTrayIcon(); +void RemoveTrayIcon(); void SetTrayIcon(conn_state_t); void SetMenuStatus(connection_t *, conn_state_t); void SetServiceMenuStatus();