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

Commit

Permalink
#351: sleep longer in frontend when console window is hidden
Browse files Browse the repository at this point in the history
(only in Windows app)
  • Loading branch information
hugbug committed Feb 9, 2019
1 parent fa57474 commit e07a6b9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
28 changes: 28 additions & 0 deletions daemon/frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 34,24 @@ Frontend::Frontend()
{
debug("Creating Frontend");

m_workStateObserver.m_owner = this;
g_WorkState->Attach(&m_workStateObserver);

m_updateInterval = g_Options->GetUpdateInterval();
}

void Frontend::Stop()
{
Thread::Stop();

m_waitCond.NotifyAll();
}

void Frontend::WorkStateUpdate(Subject* caller, void* aspect)
{
m_waitCond.NotifyAll();
}

bool Frontend::PrepareData()
{
if (IsRemoteMode())
Expand Down Expand Up @@ -308,3 323,16 @@ bool Frontend::RequestEditQueue(DownloadQueue::EEditAction action, int offset, i
IdList ids = { id };
return client.RequestServerEditQueue(action, offset, nullptr, &ids, nullptr, rmId);
}

void Frontend::Wait(int milliseconds)
{
if (g_WorkState->GetPauseFrontend())
{
Guard guard(m_waitMutex);
m_waitCond.WaitFor(m_waitMutex, 2000);
}
else
{
Util::Sleep(milliseconds);
}
}
14 changes: 14 additions & 0 deletions daemon/frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@
#include "DownloadInfo.h"
#include "MessageBase.h"
#include "QueueEditor.h"
#include "Observer.h"

class Frontend : public Thread
{
Expand All @@ -51,7 52,10 @@ class Frontend : public Thread
int m_dnTimeSec = 0;
int64 m_allBytes = 0;
bool m_standBy = false;
Mutex m_waitMutex;
ConditionVar m_waitCond;

virtual void Stop();
bool PrepareData();
void FreeData();
GuardedMessageList GuardMessages();
Expand All @@ -63,12 67,22 @@ class Frontend : public Thread
bool RequestSetDownloadRate(int rate);
bool ServerEditQueue(DownloadQueue::EEditAction action, int offset, int entry);
bool RequestEditQueue(DownloadQueue::EEditAction action, int offset, int id);
void Wait(int milliseconds);

private:
class WorkStateObserver : public Observer
{
public:
Frontend* m_owner;
virtual void Update(Subject* caller, void* aspect) { m_owner->WorkStateUpdate(caller, aspect); }
};

MessageList m_remoteMessages;
WorkStateObserver m_workStateObserver;

bool RequestMessages();
bool RequestFileList();
void WorkStateUpdate(Subject* caller, void* aspect);
};

#endif
2 changes: 1 addition & 1 deletion daemon/frontend/LoggableFrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 31,7 @@ void LoggableFrontend::Run()
while (!IsStopped())
{
Update();
Util::Sleep(m_updateInterval);
Wait(m_updateInterval);
}
// Printing the last messages
Update();
Expand Down
2 changes: 1 addition & 1 deletion daemon/frontend/NCursesFrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 215,7 @@ void NCursesFrontend::Run()

// update more often (sleep shorter) if need faster reaction on user input
int sleepInterval = m_inputMode == normal ? 100 : 10;
Util::Sleep(sleepInterval);
Wait(sleepInterval);
m_dataUpdatePos -= sleepInterval;
}

Expand Down
3 changes: 3 additions & 0 deletions daemon/main/WorkState.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 41,8 @@ class WorkState : public Subject
bool GetTempPauseDownload() const { return m_tempPauseDownload; }
void SetTempPausePostprocess(bool tempPausePostprocess) { m_tempPausePostprocess = tempPausePostprocess; Changed(); }
bool GetTempPausePostprocess() const { return m_tempPausePostprocess; }
void SetPauseFrontend(bool pauseFrontend) { m_pauseFrontend = pauseFrontend; Changed(); }
bool GetPauseFrontend() const { return m_pauseFrontend; }
void SetSpeedLimit(int speedLimit) { m_speedLimit = speedLimit; Changed(); }
int GetSpeedLimit() const { return m_speedLimit; }
void SetResumeTime(time_t resumeTime) { m_resumeTime = resumeTime; Changed(); }
Expand All @@ -58,6 60,7 @@ class WorkState : public Subject
bool m_pauseScan = false;
bool m_tempPauseDownload = true;
bool m_tempPausePostprocess = true;
bool m_pauseFrontend = false;
int m_downloadRate = 0;
time_t m_resumeTime = 0;
int m_localTimeOffset = 0;
Expand Down
1 change: 1 addition & 0 deletions daemon/windows/WinConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 660,7 @@ void WinConsole::LoadPrefs()
void WinConsole::ApplyPrefs()
{
ShowWindow(GetConsoleWindow(), m_showConsole ? SW_SHOW : SW_HIDE);
g_WorkState->SetPauseFrontend(!m_showConsole);
if (m_showTrayIcon)
{
UpdateTrayIcon();
Expand Down

0 comments on commit e07a6b9

Please sign in to comment.