Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimize to tray support. #113

Merged
merged 13 commits into from
Jul 20, 2024
Merged

Conversation

KnockKnockP
Copy link
Contributor

No description provided.

@iProgramMC
Copy link
Contributor

iProgramMC commented Jun 26, 2024 via email

@KnockKnockP
Copy link
Contributor Author

Thinking about it, I could probably just use mutex to force single instance. I don't know why I overcomplicated it.

@iProgramMC
Copy link
Contributor

Yeah, you can do that. Here's an example:

// I use a class here to perform cleanup after winmain
class InstanceMutex
{
	HANDLE m_handle = NULL;

public:
	HRESULT Init()
	{
#ifdef _DEBUG
		return 0;
#else
		SetLastError(NO_ERROR);

		m_handle = CreateMutex(NULL, TRUE, WINDOW_CLASS);

		if (GetLastError() == ERROR_ALREADY_EXISTS)
		{
			if (m_handle)
			{
				CloseHandle(m_handle);
				m_handle = NULL;
			}

			return ERROR_ALREADY_EXISTS;
		}

		return GetLastError();
#endif
	}

	~InstanceMutex()
	{
#ifdef _DEBUG
		if (m_handle)
			CloseHandle(m_handle);
#endif
	}
};

InstanceMutex g_instanceMutex;

bool DetectDuplicateInstances()
{
    HRESULT hres = g_instanceMutex.Init();
    if (hres != ERROR_ALREADY_EXISTS) return false;
    
    HWND hWnd = FindWindow(WINDOW_CLASS_NAME, NULL);
    if (hWnd) {
        SendMessage (hWnd, WM_REQUESTACTIVATE, 0, 0);
        return true;
    }
    
    return false;
}

src/windows/InstanceMutex.cpp Outdated Show resolved Hide resolved
src/windows/InstanceMutex.cpp Show resolved Hide resolved
src/windows/Main.cpp Outdated Show resolved Hide resolved
src/windows/Main.cpp Show resolved Hide resolved
src/windows/ShellNotification.cpp Outdated Show resolved Hide resolved
@KnockKnockP KnockKnockP marked this pull request as draft June 27, 2024 14:28
@KnockKnockP KnockKnockP marked this pull request as ready for review June 27, 2024 17:35
@KnockKnockP KnockKnockP requested a review from iProgramMC June 29, 2024 11:16
@@ -1580,21 +1580,21 @@ static bool ForceSingleInstance(LPCWSTR pClassName)
HRESULT hResult = g_instanceMutex.Init();

if (hResult != ERROR_ALREADY_EXISTS)
return false;
return true;

HWND hWnd = FindWindow(pClassName, NULL);
if (hWnd)
{
SendMessage(hWnd, WM_RESTORE, 0, 0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return false in the condition, and true just below.

src/discord/LocalSettings.hpp Show resolved Hide resolved
@iProgramMC iProgramMC dismissed their stale review June 29, 2024 18:26

didnt check everything

src/windows/Main.cpp Outdated Show resolved Hide resolved
src/windows/WindowMessages.hpp Outdated Show resolved Hide resolved
src/discord/LocalSettings.cpp Outdated Show resolved Hide resolved
@iProgramMC iProgramMC self-assigned this Jun 30, 2024
@iProgramMC iProgramMC added the enhancement New feature or request label Jun 30, 2024
Copy link
Contributor

@iProgramMC iProgramMC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :)

src/windows/Main.cpp Outdated Show resolved Hide resolved
KnockKnockP and others added 2 commits June 30, 2024 19:41
* Don't show the main window on startup.
* Don't take focus to the main message box when the channel is switched if the window is not active.
* Change `--startup` to `/startup`.
@iProgramMC iProgramMC merged commit 979c81b into DiscordMessenger:master Jul 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants