Some work on untangling FIXMEGlobal

This commit is contained in:
Kenneth Skovhede
2024-06-09 22:00:34 +02:00
parent 25bb4f3701
commit 270f2f9cea
12 changed files with 90 additions and 89 deletions
+16 -16
View File
@@ -22,7 +22,7 @@
using System;
using System.Linq;
using System.Threading;
using Duplicati.Library.RestAPI;
using Duplicati.Server.Database;
using Duplicati.Server.Serialization;
namespace Duplicati.Server
@@ -30,7 +30,7 @@ namespace Duplicati.Server
/// <summary>
/// The thread that checks on the update server if new versions are available
/// </summary>
public class UpdatePollThread
public class UpdatePollThread(Connection connection, EventPollNotify eventPollNotify)
{
private Thread m_thread;
private volatile bool m_terminated = false;
@@ -51,7 +51,7 @@ namespace Duplicati.Server
var oldv = m_downloadProgress;
m_downloadProgress = value;
if ((int)(oldv * 100) != (int)(value * 100))
FIXMEGlobal.StatusEventNotifyer.SignalNewEvent();
eventPollNotify.SignalNewEvent();
}
}
@@ -97,12 +97,12 @@ namespace Duplicati.Server
while (!m_terminated)
{
var nextCheck = FIXMEGlobal.DataConnection.ApplicationSettings.NextUpdateCheck;
var nextCheck = connection.ApplicationSettings.NextUpdateCheck;
var maxcheck = TimeSpan.FromDays(7);
try
{
maxcheck = Library.Utility.Timeparser.ParseTimeSpan(FIXMEGlobal.DataConnection.ApplicationSettings.UpdateCheckInterval);
maxcheck = Library.Utility.Timeparser.ParseTimeSpan(connection.ApplicationSettings.UpdateCheckInterval);
}
catch
{
@@ -118,14 +118,14 @@ namespace Duplicati.Server
m_forceCheck = false;
ThreadState = UpdatePollerStates.Checking;
FIXMEGlobal.StatusEventNotifyer.SignalNewEvent();
eventPollNotify.SignalNewEvent();
DateTime started = DateTime.UtcNow;
FIXMEGlobal.DataConnection.ApplicationSettings.LastUpdateCheck = started;
nextCheck = FIXMEGlobal.DataConnection.ApplicationSettings.NextUpdateCheck;
connection.ApplicationSettings.LastUpdateCheck = started;
nextCheck = connection.ApplicationSettings.NextUpdateCheck;
Library.AutoUpdater.ReleaseType rt;
if (!Enum.TryParse<Library.AutoUpdater.ReleaseType>(FIXMEGlobal.DataConnection.ApplicationSettings.UpdateChannel, true, out rt))
if (!Enum.TryParse<Library.AutoUpdater.ReleaseType>(connection.ApplicationSettings.UpdateChannel, true, out rt))
rt = Duplicati.Library.AutoUpdater.ReleaseType.Unknown;
// Choose the default channel in case we have unknown
@@ -135,7 +135,7 @@ namespace Duplicati.Server
{
var update = Duplicati.Library.AutoUpdater.UpdaterManager.CheckForUpdate(rt);
if (update != null)
FIXMEGlobal.DataConnection.ApplicationSettings.UpdatedVersion = update;
connection.ApplicationSettings.UpdatedVersion = update;
}
catch
{
@@ -144,10 +144,10 @@ namespace Duplicati.Server
// It could be that we have registered an update from a more unstable channel,
// but the user has switched to a more stable channel.
// In that case we discard the old update to avoid offering it.
if (FIXMEGlobal.DataConnection.ApplicationSettings.UpdatedVersion != null)
if (connection.ApplicationSettings.UpdatedVersion != null)
{
Library.AutoUpdater.ReleaseType updatert;
var updatertstring = FIXMEGlobal.DataConnection.ApplicationSettings.UpdatedVersion.ReleaseType;
var updatertstring = connection.ApplicationSettings.UpdatedVersion.ReleaseType;
if (string.Equals(updatertstring, "preview", StringComparison.OrdinalIgnoreCase))
updatertstring = Library.AutoUpdater.ReleaseType.Experimental.ToString();
@@ -158,15 +158,15 @@ namespace Duplicati.Server
updatert = Duplicati.Library.AutoUpdater.ReleaseType.Nightly;
if (updatert > rt)
FIXMEGlobal.DataConnection.ApplicationSettings.UpdatedVersion = null;
connection.ApplicationSettings.UpdatedVersion = null;
}
var updatedinfo = FIXMEGlobal.DataConnection.ApplicationSettings.UpdatedVersion;
var updatedinfo = connection.ApplicationSettings.UpdatedVersion;
if (updatedinfo != null && Duplicati.Library.AutoUpdater.UpdaterManager.TryParseVersion(updatedinfo.Version) > System.Reflection.Assembly.GetExecutingAssembly().GetName().Version)
{
var package = updatedinfo.FindPackage();
FIXMEGlobal.DataConnection.RegisterNotification(
connection.RegisterNotification(
NotificationType.Information,
"Found update",
updatedinfo.Displayname,
@@ -189,7 +189,7 @@ namespace Duplicati.Server
if (ThreadState != UpdatePollerStates.Waiting)
{
ThreadState = UpdatePollerStates.Waiting;
FIXMEGlobal.StatusEventNotifyer.SignalNewEvent();
eventPollNotify.SignalNewEvent();
}
var waitTime = nextCheck - DateTime.UtcNow;