Skip to content

Commit

Permalink
Merge pull request #113 from KnockKnockP/master
Browse files Browse the repository at this point in the history
Add minimize to tray support.
  • Loading branch information
iProgramMC authored Jul 20, 2024
2 parents 7d48e52 + 923e011 commit 979c81b
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/discord/Frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class Frontend
virtual std::string GetFormatTimeShortText() = 0;
virtual std::string GetFormatTimeShorterText() = 0;

virtual void HideWindow() = 0;
virtual void RestoreWindow() = 0;
virtual void MaximizeWindow() = 0;

// Debugging
#ifdef USE_DEBUG_PRINTS
virtual void DebugPrint(const char* fmt, va_list vl) = 0;
Expand Down
17 changes: 16 additions & 1 deletion src/discord/LocalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ bool LocalSettings::Load()
if (j.contains("StartMaximized"))
m_bStartMaximized = j["StartMaximized"];

if (j.contains("OpenOnStartup"))
m_bOpenOnStartup = j["OpenOnStartup"];

if (j.contains("StartMinimized"))
m_bStartMinimized = j["StartMinimized"];

if (j.contains("MinimizeToNotif"))
m_bMinimizeToNotif = j["MinimizeToNotif"];

if (j.contains("Maximized"))
m_bMaximized = j["Maximized"];

if (j.contains("EnableTLSVerification"))
m_bEnableTLSVerification = j["EnableTLSVerification"];

Expand Down Expand Up @@ -134,7 +146,6 @@ bool LocalSettings::Load()

if (j.contains("AddExtraHeaders"))
m_bAddExtraHeaders = j["AddExtraHeaders"];

return true;
}

Expand All @@ -153,6 +164,10 @@ bool LocalSettings::Save()
j["ReplyMentionDefault"] = m_bReplyMentionDefault;
j["StartMaximized"] = m_bStartMaximized;
j["SaveWindowSize"] = m_bSaveWindowSize;
j["OpenOnStartup"] = m_bOpenOnStartup;
j["StartMinimized"] = m_bStartMinimized;
j["MinimizeToNotif"] = m_bMinimizeToNotif;
j["Maximized"] = m_bMaximized;
j["CheckUpdates"] = m_bCheckUpdates;
j["EnableTLSVerification"] = m_bEnableTLSVerification;
j["DisableFormatting"] = m_bDisableFormatting;
Expand Down
28 changes: 28 additions & 0 deletions src/discord/LocalSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ class LocalSettings
bool GetStartMaximized() const {
return m_bStartMaximized;
}
void SetOpenOnStartup(bool b) {
m_bOpenOnStartup = b;
}
bool GetOpenOnStartup() const {
return m_bOpenOnStartup;
}
void SetStartMinimized(bool b) {
m_bStartMinimized = b;
}
bool GetStartMinimized() const {
return m_bStartMinimized;
}
void SetMinimizeToNotif(bool b) {
m_bMinimizeToNotif = b;
}
bool GetMinimizeToNotif() const {
return m_bMinimizeToNotif;
}
void SetMaximized(bool b) {
m_bMaximized = b;
}
bool GetMaximized() const {
return m_bMaximized;
}
bool IsFirstStart() const {
return m_bIsFirstStart;
}
Expand Down Expand Up @@ -196,6 +220,10 @@ class LocalSettings
bool m_bReplyMentionDefault = true;
bool m_bSaveWindowSize = false;
bool m_bStartMaximized = false;
bool m_bOpenOnStartup = false;
bool m_bStartMinimized = false;
bool m_bMinimizeToNotif = true;
bool m_bMaximized = false;
bool m_bIsFirstStart = false;
bool m_bCheckUpdates = false;
bool m_bAskToCheckUpdates = true;
Expand Down
7 changes: 5 additions & 2 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
#define IDI_SCROLL 98
#define IDI_NOTIFICATION 99
#define IDI_NOTIFICATION_2K 100
#define IDR_NOTIFICATION_CONTEXT 101
#define IDB_TARGET 200
#define IDB_CHANNEL 201
#define IDB_CATEGORY 202
Expand Down Expand Up @@ -475,6 +476,8 @@
#define IDM_BLOCK 1065
#define IDM_COPYID 1066
#define ID_ACTIONS_QUICKSWITCHER 1067
#define ID_NOTIFICATION_SHOW 1068
#define ID_NOTIFICATION_EXIT 1069
#define IDR_MAIN_ACCELS 1201
#define IDA_SEARCH 1301
#define IDA_QUICKSWITCHER 1302
Expand All @@ -484,8 +487,8 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 1069
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 1079
#define _APS_NEXT_CONTROL_VALUE 904
#define _APS_NEXT_SYMED_VALUE 40000
#endif
Expand Down
22 changes: 20 additions & 2 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@ BEGIN
END
END

IDR_NOTIFICATION_CONTEXT MENU
BEGIN
POPUP "Notification"
BEGIN
MENUITEM "Show", ID_NOTIFICATION_SHOW
POPUP "Status"
BEGIN
MENUITEM "Online", ID_ONLINESTATUSPLACEHOLDER_ONLINE, CHECKED
MENUITEM SEPARATOR
MENUITEM "Idle", ID_ONLINESTATUSPLACEHOLDER_IDLE
MENUITEM "Do not disturb", ID_ONLINESTATUSPLACEHOLDER_DONOTDISTURB
MENUITEM "Invisible", ID_ONLINESTATUSPLACEHOLDER_INVISIBLE
END
MENUITEM SEPARATOR
MENUITEM "Exit", ID_NOTIFICATION_EXIT
END
END


/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -683,11 +701,11 @@ BEGIN
CONTROL "Save window size",IDC_SAVE_WINDOW_SIZE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,18,236,10
CONTROL "Start maximized",IDC_START_MAXIMIZED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,32,236,10
CONTROL "Open Discord Messenger when your computer starts",IDC_OPEN_ON_STARTUP,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,46,242,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,46,242,10
CONTROL "Open minimized to notification area",IDC_START_MINIMIZED,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,32,60,222,10
CONTROL "Minimize to notification area when clicking the close button",IDC_MINIMIZE_TO_NOTIF,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,74,242,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,74,242,10
END


Expand Down
15 changes: 15 additions & 0 deletions src/windows/Frontend_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,21 @@ void Frontend_Win32::RequestQuit()
::WantQuit();
}

void Frontend_Win32::HideWindow()
{
ShowWindow(g_Hwnd, SW_HIDE);
}

void Frontend_Win32::RestoreWindow()
{
ShowWindow(g_Hwnd, SW_RESTORE);
}

void Frontend_Win32::MaximizeWindow()
{
ShowWindow(g_Hwnd, SW_MAXIMIZE);
}

bool Frontend_Win32::IsWindowMinimized()
{
return IsIconic(g_Hwnd);
Expand Down
3 changes: 3 additions & 0 deletions src/windows/Frontend_Win32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class Frontend_Win32 : public Frontend
void RegisterAttachment(Snowflake sf, const std::string& avatarlnk) override;
void RegisterChannelIcon(Snowflake sf, const std::string& avatarlnk) override;
void RequestQuit() override;
void HideWindow() override;
void RestoreWindow() override;
void MaximizeWindow() override;
bool IsWindowMinimized() override;
std::string GetDirectMessagesText() override;
std::string GetPleaseWaitText() override;
Expand Down
31 changes: 31 additions & 0 deletions src/windows/InstanceMutex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "InstanceMutex.hpp"

void InstanceMutex::Close()
{
if (m_handle)
{
CloseHandle(m_handle);
m_handle = NULL;
}
}

HRESULT InstanceMutex::Init()
{
#ifdef DISABLE_SINGLE_INSTANCE
return 0;
#else

m_handle = CreateMutex(NULL, TRUE, TEXT("DiscordMessenger"));

const DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS)
Close();

return error;
#endif
}

InstanceMutex::~InstanceMutex()
{
Close();
}
15 changes: 15 additions & 0 deletions src/windows/InstanceMutex.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <windows.h>

class InstanceMutex
{
private:
HANDLE m_handle = NULL;

void Close();

public:
HRESULT Init();
~InstanceMutex();
};
2 changes: 1 addition & 1 deletion src/windows/LoadingMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void LoadingMessage::Show()
if (!m_hwnd) {
CreateWnd();
ShowWindow(m_hwnd, SW_SHOWNORMAL);
SetFocus(m_hwnd);
SetActiveWindow(m_hwnd);
}
}

Expand Down
Loading

0 comments on commit 979c81b

Please sign in to comment.