#351: sleep longer in frontend when console window is hidden

(only in Windows app)
This commit is contained in:
Andrey Prygunkov
2019-02-09 09:45:38 +01:00
parent fa57474d78
commit e07a6b9443
6 changed files with 48 additions and 2 deletions

View File

@@ -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())
@@ -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);
}
}

View File

@@ -27,6 +27,7 @@
#include "DownloadInfo.h"
#include "MessageBase.h"
#include "QueueEditor.h"
#include "Observer.h"
class Frontend : public Thread
{
@@ -51,7 +52,10 @@ protected:
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();
@@ -63,12 +67,22 @@ protected:
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

View File

@@ -31,7 +31,7 @@ void LoggableFrontend::Run()
while (!IsStopped())
{
Update();
Util::Sleep(m_updateInterval);
Wait(m_updateInterval);
}
// Printing the last messages
Update();

View File

@@ -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;
}

View File

@@ -41,6 +41,8 @@ public:
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(); }
@@ -58,6 +60,7 @@ private:
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;

View File

@@ -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();