Skip to content

Commit

Permalink
Make CloseToTrayWithEscape-feature optional
Browse files Browse the repository at this point in the history
  • Loading branch information
d4koon committed Dec 13, 2020
1 parent f86cf1b commit 111443f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions WhatsappTray/AppData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DataEntryS<SBool> AppData::CloseToTray(Data::CLOSE_TO_TRAY, false, &AppData::Set
DataEntryS<SBool> AppData::LaunchOnWindowsStartup(Data::LAUNCH_ON_WINDOWS_STARTUP, false, &AppData::SetData);
DataEntryS<SBool> AppData::StartMinimized(Data::START_MINIMIZED, false, &AppData::SetData);
DataEntryS<SBool> AppData::ShowUnreadMessages(Data::SHOW_UNREAD_MESSAGES, false, &AppData::SetData);
DataEntryS<SBool> AppData::CloseToTrayWithEscape(Data::CLOSE_TO_TRAY_WITH_ESCAPE, false, &AppData::SetData);
DataEntryS<SString> AppData::WhatsappStartpath(Data::WHATSAPP_STARTPATH, std::string("%userStartmenuePrograms%\\WhatsApp\\WhatsApp.lnk"), &AppData::SetData);
DataEntryS<SString> AppData::WhatsappRoamingDirectory(Data::WHATSAPP_ROAMING_DIRECTORY, Helper::GetWindowsAppDataDirectory(), &AppData::SetData);

Expand All @@ -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));

Expand Down
2 changes: 2 additions & 0 deletions WhatsappTray/AppData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -127,6 +128,7 @@ class AppData
static DataEntryS<SBool> LaunchOnWindowsStartup;
static DataEntryS<SBool> StartMinimized;
static DataEntryS<SBool> ShowUnreadMessages;
static DataEntryS<SBool> CloseToTrayWithEscape;

static std::string WhatsappStartpathGet();
static std::string WhatsappRoamingDirectoryGet();
Expand Down
1 change: 1 addition & 0 deletions WhatsappTray/SharedDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <string>
Expand Down
19 changes: 16 additions & 3 deletions WhatsappTray/WhatsappTray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 111443f

Please sign in to comment.