Skip to content

Commit

Permalink
* Fix bad startup command being added to the run registry key.
Browse files Browse the repository at this point in the history
* 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`.
  • Loading branch information
iProgramMC committed Jul 5, 2024
1 parent a88aabd commit 923e011
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
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
16 changes: 10 additions & 6 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,7 @@ void ResetTryAgainInTime() {
g_tryAgainTimerElapse = 500;
}

const TCHAR g_tStartupArg[] = TEXT(" --startup");
const CHAR g_StartupArg[] = "--startup";
const CHAR g_StartupArg[] = "/startup";

bool g_bFromStartup = false;

Expand All @@ -659,7 +658,7 @@ void AddOrRemoveAppFromStartup()
TCHAR tPath[MAX_PATH];
const DWORD length = GetModuleFileName(NULL, tPath, MAX_PATH);

const std::string sPath = "\"" + MakeStringFromTString(tPath) + "\"" + std::string(g_StartupArg);
const std::string sPath = "\"" + MakeStringFromTString(tPath) + "\" " + std::string(g_StartupArg);
const LPTSTR finalPath = ConvertCppStringToTString(sPath);

RegSetValueEx(hkey, value, 0, REG_SZ, (BYTE *)finalPath, (wcslen(finalPath) + 1) * sizeof(TCHAR));
Expand Down Expand Up @@ -791,7 +790,9 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
g_pMessageList->UpdateAllowDrop();

UpdateMainWindowTitle(hWnd);
SetFocus(g_pMessageEditor->m_edit_hwnd);

if (IsWindowActive(g_Hwnd))
SetFocus(g_pMessageEditor->m_edit_hwnd);

if (!GetDiscordInstance()->GetCurrentChannel())
{
Expand Down Expand Up @@ -1147,7 +1148,8 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
break;
case WM_CONNECTING: {
g_pLoadingMessage->Show();
if (!g_bFromStartup || !GetLocalSettings()->GetStartMinimized())
g_pLoadingMessage->Show();
break;
}
case WM_LOGINAGAIN:
Expand Down Expand Up @@ -1745,7 +1747,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLin
TextToSpeech::Initialize();

// Run the message loop.
ShowWindow (g_Hwnd, startMaximized ? SW_SHOWMAXIMIZED : nShowCmd);

if (!g_bFromStartup || !GetLocalSettings()->GetStartMinimized())
ShowWindow (g_Hwnd, startMaximized ? SW_SHOWMAXIMIZED : nShowCmd);

while (GetMessage(&msg, NULL, 0, 0) > 0)
{
Expand Down
4 changes: 4 additions & 0 deletions src/windows/ShellNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ void ShellNotification::Callback(WPARAM wParam, LPARAM lParam)
{
// TODO: Don't know how to know which one we clicked
DbgPrintW("Acknowledge Notification");

ShowWindow(g_Hwnd, SW_SHOW);
SetActiveWindow(g_Hwnd);

break;
}

Expand Down
5 changes: 5 additions & 0 deletions src/windows/WinUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ void WindowScrollXY(HWND hWnd, int diffLeftRight, int diffUpDown)
UpdateWindow(hWnd);
}

bool IsWindowActive(HWND hWnd)
{
return IsWindowVisible(hWnd) && GetForegroundWindow() == hWnd;
}

bool FileExists(const std::string& path)
{
#ifdef OLD_WINDOWS
Expand Down
1 change: 1 addition & 0 deletions src/windows/WinUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ std::string GetStringFromHResult(HRESULT hr);
LPTSTR GetTStringFromHResult(HRESULT hr);

// Window utils
bool IsWindowActive(HWND hWnd);
void WindowScroll(HWND hWnd, int diffUpDown);
void WindowScrollXY(HWND hWnd, int diffLeftRight, int diffUpDown);
void DrawBitmap(HDC hdc, HBITMAP bitmap, int x, int y, LPRECT clip = NULL, COLORREF transparent = CLR_NONE, int scaleToWidth = 0, int scaleToHeight = 0, bool hasAlpha = false);
Expand Down

0 comments on commit 923e011

Please sign in to comment.