Skip to content
Snippets Groups Projects
Commit e82e377b authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Simplify evaluation of changed status.

We can just derive a status change from the fact that the file system
watcher has fired, so no need to evaluate all kinds of things first.

Refers to #23
parent f567360b
No related branches found
No related tags found
No related merge requests found
...@@ -30,8 +30,8 @@ namespace ATxTray ...@@ -30,8 +30,8 @@ namespace ATxTray
private static ServiceConfig _config; private static ServiceConfig _config;
private static ServiceStatus _status; private static ServiceStatus _status;
private static bool _statusFileChanged = false;
private static bool _statusChanged = false; private static bool _statusChanged = false;
private static bool _statusFileChanged = true;
private static bool _svcRunning = false; private static bool _svcRunning = false;
private static bool _svcSuspended = true; private static bool _svcSuspended = true;
private static string _svcSuspendReason; private static string _svcSuspendReason;
...@@ -201,6 +201,7 @@ namespace ATxTray ...@@ -201,6 +201,7 @@ namespace ATxTray
} }
UpdateSvcRunning(); UpdateSvcRunning();
ReadStatus(); // update the status no matter if the service process is running
var heartBeat = "?"; var heartBeat = "?";
var serviceRunning = "stopped"; var serviceRunning = "stopped";
...@@ -208,22 +209,23 @@ namespace ATxTray ...@@ -208,22 +209,23 @@ namespace ATxTray
if (_svcRunning) { if (_svcRunning) {
serviceRunning = "OK"; serviceRunning = "OK";
ReadStatus();
UpdateSvcSuspended();
UpdateTxProgressBar();
UpdateTxInProgress();
if ((DateTime.Now - _status.LastStatusUpdate).TotalSeconds < 60) if ((DateTime.Now - _status.LastStatusUpdate).TotalSeconds < 60)
heartBeat = "OK"; heartBeat = "OK";
if (_txInProgress) if (_txInProgress)
txProgress = $"{_txProgressPct}%"; txProgress = $"{_txProgressPct}%";
} }
UpdateTrayIcon(); UpdateHoverText($"AutoTx [svc={serviceRunning}] [hb={heartBeat}] [tx={txProgress}]");
if (!_statusChanged) if (!_statusChanged)
return; return;
UpdateHoverText($"AutoTx [svc={serviceRunning}] [hb={heartBeat}] [tx={txProgress}]"); UpdateSvcSuspended();
UpdateTxProgressBar();
UpdateTxInProgress();
UpdateTrayIcon();
_statusChanged = false;
} }
private static void StatusUpdated(object sender, FileSystemEventArgs e) { private static void StatusUpdated(object sender, FileSystemEventArgs e) {
...@@ -360,6 +362,7 @@ namespace ATxTray ...@@ -360,6 +362,7 @@ namespace ATxTray
Log.Debug("Status file was updated, trying to re-read..."); Log.Debug("Status file was updated, trying to re-read...");
_status = ServiceStatus.Deserialize(_statusFile, _config); _status = ServiceStatus.Deserialize(_statusFile, _config);
_statusFileChanged = false; _statusFileChanged = false;
_statusChanged = true;
} }
/// <summary> /// <summary>
...@@ -376,7 +379,6 @@ namespace ATxTray ...@@ -376,7 +379,6 @@ namespace ATxTray
if (_svcRunning == curSvcRunState) if (_svcRunning == curSvcRunState)
return; return;
_statusChanged = true;
_svcRunning = curSvcRunState; _svcRunning = curSvcRunState;
if (_svcRunning) { if (_svcRunning) {
_miSvcRunning.Text = @"Service running."; _miSvcRunning.Text = @"Service running.";
...@@ -406,7 +408,6 @@ namespace ATxTray ...@@ -406,7 +408,6 @@ namespace ATxTray
_svcSuspended == _status.ServiceSuspended) _svcSuspended == _status.ServiceSuspended)
return; return;
_statusChanged = true;
_svcSuspended = _status.ServiceSuspended; _svcSuspended = _status.ServiceSuspended;
_svcSuspendReason = _status.LimitReason; _svcSuspendReason = _status.LimitReason;
if (_svcSuspended) { if (_svcSuspended) {
...@@ -431,7 +432,6 @@ namespace ATxTray ...@@ -431,7 +432,6 @@ namespace ATxTray
_txSize == _status.CurrentTransferSize) _txSize == _status.CurrentTransferSize)
return; return;
_statusChanged = true;
_txInProgress = _status.TransferInProgress; _txInProgress = _status.TransferInProgress;
_txSize = _status.CurrentTransferSize; _txSize = _status.CurrentTransferSize;
if (_txInProgress) { if (_txInProgress) {
...@@ -453,7 +453,6 @@ namespace ATxTray ...@@ -453,7 +453,6 @@ namespace ATxTray
_txProgressPct == _status.CurrentTransferPercent) _txProgressPct == _status.CurrentTransferPercent)
return; return;
_statusChanged = true;
_txProgressPct = _status.CurrentTransferPercent; _txProgressPct = _status.CurrentTransferPercent;
if (_txInProgress) { if (_txInProgress) {
Log.Debug("Transfer progress: {0}%", _txProgressPct); Log.Debug("Transfer progress: {0}%", _txProgressPct);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment