Skip to content

Commit

Permalink
* Add some more notification options
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Jun 21, 2024
1 parent 4686304 commit d51fad1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/discord/LocalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ bool LocalSettings::Load()
if (j.contains("ShowEmbedContent"))
m_bShowEmbedContent = j["ShowEmbedContent"];

if (j.contains("EnableNotifications"))
m_bEnableNotifications = j["EnableNotifications"];

if (j.contains("FlashOnNotification"))
m_bFlashOnNotification = j["FlashOnNotification"];

if (m_bSaveWindowSize)
{
if (j.contains("WindowWidth"))
Expand Down Expand Up @@ -160,6 +166,8 @@ bool LocalSettings::Save()
j["ShowAttachmentImages"] = m_bShowAttachmentImages;
j["ShowEmbedImages"] = m_bShowEmbedImages;
j["ShowEmbedContent"] = m_bShowEmbedContent;
j["EnableNotifications"] = m_bEnableNotifications;
j["FlashOnNotification"] = m_bFlashOnNotification;

if (m_bSaveWindowSize) {
j["WindowWidth"] = m_width;
Expand Down
14 changes: 14 additions & 0 deletions src/discord/LocalSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ class LocalSettings
void SetShowEmbedContent(bool b) {
m_bShowEmbedContent = b;
}
bool EnableNotifications() const {
return m_bEnableNotifications;
}
bool FlashOnNotification() const {
return m_bFlashOnNotification;
}
void SetEnableNotifications(bool b) {
m_bEnableNotifications = b;
}
void SetFlashOnNotification(bool b) {
m_bFlashOnNotification = b;
}

private:
std::string m_token;
Expand All @@ -192,6 +204,8 @@ class LocalSettings
bool m_bShowAttachmentImages = true;
bool m_bShowEmbedImages = true;
bool m_bShowEmbedContent = true;
bool m_bEnableNotifications = true;
bool m_bFlashOnNotification = true;
time_t m_remindUpdatesOn = 0;
int m_width = 1000;
int m_height = 700;
Expand Down
9 changes: 5 additions & 4 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,13 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
GROUPBOX "Balloon Notifications",IDC_STATIC,6,7,248,65
CONTROL "Enable balloon notifications",IDC_ENABLE_BALLOON_NOTIFS,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,18,103,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,18,235,10
CONTROL "Flash the window on the taskbar if a notification is received",IDC_FLASH_TASKBAR,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,31,205,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,31,235,10
CONTROL "Play Discord notification sound when a notification is received",IDC_USE_DISCORD_SOUND,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,57,212,10
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,57,235,10
CONTROL "Don't play sound when a notification is received",IDC_MUTE_NOTIFICATIONS,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,44,242,10
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,44,235,10
END

IDD_DIALOG_CHATSETTINGS DIALOGEX 0, 0, 260, 242
Expand Down Expand Up @@ -823,6 +823,7 @@ BEGIN
LEFTMARGIN, 6
RIGHTMARGIN, 254
VERTGUIDE, 12
VERTGUIDE, 247
TOPMARGIN, 7
BOTTOMMARGIN, 234
END
Expand Down
20 changes: 20 additions & 0 deletions src/windows/OptionsDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Config.hpp"
#include "OptionsDialog.hpp"
#include "ShellNotification.hpp"
#include "../discord/LocalSettings.hpp"

#ifdef NEW_WINDOWS
Expand Down Expand Up @@ -226,6 +227,12 @@ void WINAPI OnChildDialogInit(HWND hwndDlg)

break;
}
case PG_NOTIFICATIONS:
{
CheckDlgButton(hwndDlg, IDC_ENABLE_BALLOON_NOTIFS, GetLocalSettings()->EnableNotifications() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_FLASH_TASKBAR, GetLocalSettings()->FlashOnNotification() ? BST_CHECKED : BST_UNCHECKED);
break;
}
case PG_CHAT:
{
CheckDlgButton(hwndDlg, IDC_IMAGES_WHEN_UPLOADED, GetLocalSettings()->ShowAttachmentImages() ? BST_CHECKED : BST_UNCHECKED);
Expand Down Expand Up @@ -438,6 +445,19 @@ INT_PTR CALLBACK ChildDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
}
break;
}
case PG_NOTIFICATIONS:
{
switch (LOWORD(wParam))
{
case IDC_ENABLE_BALLOON_NOTIFS:
GetLocalSettings()->SetEnableNotifications(IsDlgButtonChecked(hWnd, IDC_ENABLE_BALLOON_NOTIFS));
break;
case IDC_FLASH_TASKBAR:
GetLocalSettings()->SetFlashOnNotification(IsDlgButtonChecked(hWnd, IDC_FLASH_TASKBAR));
break;
}
break;
}
case PG_CHAT:
{
switch (LOWORD(wParam))
Expand Down
9 changes: 9 additions & 0 deletions src/windows/ShellNotification.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ShellNotification.hpp"
#include "Main.hpp"
#include "../discord/LocalSettings.hpp"

constexpr int NOTIFICATION_ID = 1000;

Expand Down Expand Up @@ -51,6 +52,9 @@ void ShellNotification::Deinitialize()

void ShellNotification::ShowBalloon(const std::string& titleString, const std::string& contents)
{
if (!GetLocalSettings()->EnableNotifications())
return;

// If user is in 'Do Not Disturb' mode, no taskbar notification should be fired.
// However, other methods of checking notifications will still work, such as the menu.
Profile* pf = GetDiscordInstance()->GetProfile();
Expand All @@ -60,6 +64,11 @@ void ShellNotification::ShowBalloon(const std::string& titleString, const std::s
return;
}

if (GetLocalSettings()->FlashOnNotification() && IsIconic(g_Hwnd))
{
FlashWindow(g_Hwnd, FALSE);
}

NOTIFYICONDATA d;
ZeroMemory(&d, sizeof d);
d.cbSize = NOTIFYICONDATA_V2_SIZE;
Expand Down

0 comments on commit d51fad1

Please sign in to comment.