diff --git a/WhatsappTray/AppData.cpp b/WhatsappTray/AppData.cpp index 88c3699..5502491 100644 --- a/WhatsappTray/AppData.cpp +++ b/WhatsappTray/AppData.cpp @@ -21,6 +21,7 @@ DataEntryS AppData::CloseToTray(Data::CLOSE_TO_TRAY, false, &AppData::Set DataEntryS AppData::LaunchOnWindowsStartup(Data::LAUNCH_ON_WINDOWS_STARTUP, false, &AppData::SetData); DataEntryS AppData::StartMinimized(Data::START_MINIMIZED, false, &AppData::SetData); DataEntryS AppData::ShowUnreadMessages(Data::SHOW_UNREAD_MESSAGES, false, &AppData::SetData); +DataEntryS AppData::CloseToTrayWithEscape(Data::CLOSE_TO_TRAY_WITH_ESCAPE, false, &AppData::SetData); DataEntryS AppData::WhatsappStartpath(Data::WHATSAPP_STARTPATH, std::string("%userStartmenuePrograms%\\WhatsApp\\WhatsApp.lnk"), &AppData::SetData); DataEntryS AppData::WhatsappRoamingDirectory(Data::WHATSAPP_ROAMING_DIRECTORY, Helper::GetWindowsAppDataDirectory(), &AppData::SetData); @@ -33,6 +34,7 @@ bool AppData::initDone([]() LaunchOnWindowsStartup.Get().SetAsString(GetDataOrSetDefault(LaunchOnWindowsStartup)); StartMinimized.Get().SetAsString(GetDataOrSetDefault(StartMinimized)); ShowUnreadMessages.Get().SetAsString(GetDataOrSetDefault(ShowUnreadMessages)); + CloseToTrayWithEscape.Get().SetAsString(GetDataOrSetDefault(CloseToTrayWithEscape)); WhatsappStartpath.Get().SetAsString(GetDataOrSetDefault(WhatsappStartpath)); WhatsappRoamingDirectory.Get().SetAsString(GetDataOrSetDefault(WhatsappRoamingDirectory)); diff --git a/WhatsappTray/AppData.h b/WhatsappTray/AppData.h index 7054f03..6c55658 100644 --- a/WhatsappTray/AppData.h +++ b/WhatsappTray/AppData.h @@ -13,6 +13,7 @@ BETTER_ENUM(Data, uint8_t, LAUNCH_ON_WINDOWS_STARTUP, START_MINIMIZED, SHOW_UNREAD_MESSAGES, + CLOSE_TO_TRAY_WITH_ESCAPE, WHATSAPP_STARTPATH, WHATSAPP_ROAMING_DIRECTORY ) @@ -127,6 +128,7 @@ class AppData static DataEntryS LaunchOnWindowsStartup; static DataEntryS StartMinimized; static DataEntryS ShowUnreadMessages; + static DataEntryS CloseToTrayWithEscape; static std::string WhatsappStartpathGet(); static std::string WhatsappRoamingDirectoryGet(); diff --git a/WhatsappTray/SharedDefines.h b/WhatsappTray/SharedDefines.h index ab56cee..9d007ec 100644 --- a/WhatsappTray/SharedDefines.h +++ b/WhatsappTray/SharedDefines.h @@ -28,6 +28,7 @@ #define IDM_SETTING_LAUNCH_ON_WINDOWS_STARTUP 0x1006 #define IDM_SETTING_START_MINIMIZED 0x1007 #define IDM_SETTING_SHOW_UNREAD_MESSAGES 0x1008 +#define IDM_SETTING_CLOSE_TO_TRAY_WITH_ESCAPE 0x1009 #include #include diff --git a/WhatsappTray/WhatsappTray.cpp b/WhatsappTray/WhatsappTray.cpp index 7182b83..fe66525 100644 --- a/WhatsappTray/WhatsappTray.cpp +++ b/WhatsappTray/WhatsappTray.cpp @@ -166,6 +166,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara // Toggle the 'ShowUnreadMessages'-feature. AppData::ShowUnreadMessages.Set(!AppData::ShowUnreadMessages.Get()); } break; + case IDM_SETTING_CLOSE_TO_TRAY_WITH_ESCAPE: { + // Toggle the 'CloseToTrayWithEscape'-feature. + AppData::CloseToTrayWithEscape.Set(!AppData::CloseToTrayWithEscape.Get()); + } break; case IDM_RESTORE: { LogInfo("IDM_RESTORE"); _trayManager->RestoreWindowFromTray(_hwndWhatsapp); @@ -203,9 +207,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara case WM_WA_KEY_PRESSED: { LogInfo("WM_WA_KEY_PRESSED wParam=%d", wParam); - if (wParam == 27) { - // Esc-key was pressed - _trayManager->MinimizeWindowToTray(_hwndWhatsapp); + if (AppData::CloseToTrayWithEscape.Get() == true) { + if (wParam == 27) { + // Esc-key was pressed + _trayManager->MinimizeWindowToTray(_hwndWhatsapp); + } } } break; case WM_WHAHTSAPP_CLOSING: { @@ -556,6 +562,13 @@ static void ExecuteMenu() AppendMenu(hMenu, MF_UNCHECKED, IDM_SETTING_SHOW_UNREAD_MESSAGES, "Show Unread Messages (experimental)"); } + // -- Close to tray with escape key. + if (AppData::CloseToTrayWithEscape.Get()) { + AppendMenu(hMenu, MF_CHECKED, IDM_SETTING_CLOSE_TO_TRAY_WITH_ESCAPE, "Close to tray with escape key"); + } else { + AppendMenu(hMenu, MF_UNCHECKED, IDM_SETTING_CLOSE_TO_TRAY_WITH_ESCAPE, "Close to tray with escape key"); + } + AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); //-------------- AppendMenu(hMenu, MF_STRING, IDM_RESTORE, "Restore Window");