Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#24: double click handler for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
hugbug committed Apr 25, 2017
1 parent 5813c90 commit dea9fb2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
53 changes: 26 additions & 27 deletions daemon/windows/WinConsole.cpp
Expand Up @@ -71,29 +71,11 @@ BOOL WINAPI WinConsole::ConsoleCtrlHandler(DWORD dwCtrlType)
}
}

WinConsole::WinConsole()
{
m_initialArguments = nullptr;
m_initialArgumentCount = 0;
m_defaultArguments = nullptr;
m_iconData = nullptr;
m_modal = false;
m_autostart = false;
m_showTrayIcon = true;
m_showConsole = false;
m_showWebUI = true;
m_autoParam = false;
m_doubleClick = false;
m_trayWindow = 0;
m_running = false;
m_runningService = false;
}

WinConsole::~WinConsole()
{
if (m_initialArguments)
{
g_Arguments = (char*(*)[])m_initialArguments;
g_Arguments = (char*(*)[])m_initialArguments;
g_ArgumentCount = m_initialArgumentCount;
}
free(m_defaultArguments);
Expand All @@ -107,7 +89,6 @@ void WinConsole::InitAppMode()
m_instance = (HINSTANCE)GetModuleHandle(0);
DWORD processId;
GetWindowThreadProcessId(GetConsoleWindow(), &processId);
m_appMode = false;

if (GetCurrentProcessId() == processId && g_ArgumentCount == 1)
{
Expand All @@ -131,24 +112,27 @@ void WinConsole::InitAppMode()
{
break;
}
if (!strcmp((*g_Arguments)[i], "-app"))
else if (!strcmp((*g_Arguments)[i], "-app"))
{
m_appMode = true;
}

if (!strcmp((*g_Arguments)[i], "-auto"))
else if (!strcmp((*g_Arguments)[i], "-auto"))
{
m_autoParam = true;
}
else if (!strcmp((*g_Arguments)[i], "-A"))
{
m_addParam = true;
}
}

if (m_appMode)
if (m_appMode || m_autoParam)
{
m_initialArguments = (char**)g_Arguments;
m_initialArgumentCount = g_ArgumentCount;

// remove "-app" from command line
int argc = g_ArgumentCount - 1 - (m_autoParam ? 1 : 0);
int argc = g_ArgumentCount - (m_appMode ? 1 : 0) - (m_autoParam ? 1 : 0);
m_defaultArguments = (char**)malloc(sizeof(char*) * (argc + 2));

int p = 0;
Expand All @@ -166,7 +150,13 @@ void WinConsole::InitAppMode()
}
}

// m_bAppMode indicates whether the program was started as a standalone app
if (m_addParam)
{
RunAnotherInstance();
return;
}

// m_appMode indicates whether the program was started as a standalone app
// (not from a dos box window). In that case we hide the console window,
// show the tray icon and start in server mode

Expand All @@ -179,7 +169,7 @@ void WinConsole::InitAppMode()

void WinConsole::Run()
{
if (!m_appMode)
if (!m_appMode || m_addParam)
{
return;
}
Expand Down Expand Up @@ -1043,3 +1033,12 @@ void WinConsole::ResetFactoryDefaults()
mayStartBrowser = true;
Reload();
}

void WinConsole::RunAnotherInstance()
{
ShowWindow(GetConsoleWindow(), SW_HIDE);
if (!(FindWindow("NZBGet tray window", nullptr) || IsServiceRunning()))
{
ShellExecute(0, "open", (*g_Arguments)[0], nullptr, nullptr, SW_SHOWNORMAL);
}
}
34 changes: 17 additions & 17 deletions daemon/windows/WinConsole.h
Expand Up @@ -26,7 +26,6 @@
class WinConsole : public Thread
{
public:
WinConsole();
~WinConsole();
virtual void Stop();
void InitAppMode();
Expand All @@ -37,16 +36,16 @@ class WinConsole : public Thread
virtual void Run();

private:
bool m_appMode;
char** m_defaultArguments;
char** m_initialArguments;
int m_initialArgumentCount;
HWND m_trayWindow;
NOTIFYICONDATA* m_iconData;
bool m_appMode = false;
char** m_defaultArguments = nullptr;
char** m_initialArguments = nullptr;
int m_initialArgumentCount = 0;
HWND m_trayWindow = 0;
NOTIFYICONDATA* m_iconData = nullptr;
UINT m_taskbarCreatedMessage;
HMENU m_menu;
HINSTANCE m_instance;
bool m_modal;
bool m_modal = false;
HFONT m_linkFont;
HFONT m_nameFont;
HFONT m_titleFont;
Expand All @@ -56,14 +55,15 @@ class WinConsole : public Thread
HICON m_idleIcon;
HICON m_workingIcon;
HICON m_pausedIcon;
bool m_autostart;
bool m_showTrayIcon;
bool m_showConsole;
bool m_showWebUI;
bool m_autoParam;
bool m_running;
bool m_runningService;
bool m_doubleClick;
bool m_autostart = false;
bool m_showTrayIcon = true;
bool m_showConsole = false;
bool m_showWebUI = true;
bool m_autoParam = false;
bool m_addParam = false;
bool m_running = false;
bool m_runningService = false;
bool m_doubleClick = false;

void CreateResources();
void CreateTrayIcon();
Expand All @@ -82,9 +82,9 @@ class WinConsole : public Thread
void BuildMenu();
void ShowCategoryDir(int catIndex);
void SetupConfigFile();
void SetupScripts();
void ShowFactoryResetDialog();
void ResetFactoryDefaults();
void RunAnotherInstance();

static BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType);
static LRESULT CALLBACK TrayWndProcStat(HWND hwndWin, UINT uMsg, WPARAM wParam, LPARAM lParam);
Expand Down
2 changes: 1 addition & 1 deletion windows/setup/nzbget-setup.nsi
Expand Up @@ -216,7 +216,7 @@ ${If} $Checkbox_State <> 0
WriteRegStr HKCR "NZBGet.NZBFile\DefaultIcon" "" `$INSTDIR\nzbget.exe,00`
WriteRegStr HKCR "NZBGet.NZBFile\shell" "" "open"
WriteRegStr HKCR "NZBGet.NZBFile\shell\open" "" `Open with NZBGet`
WriteRegStr HKCR "NZBGet.NZBFile\shell\open\command" "" `$INSTDIR\nzbget.exe -A $\"%1$\"`
WriteRegStr HKCR "NZBGet.NZBFile\shell\open\command" "" `$INSTDIR\nzbget.exe -app -A $\"%1$\"`

System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'

Expand Down

0 comments on commit dea9fb2

Please sign in to comment.