Merge branch 'p5c-p3' into review2-p5c

This commit is contained in:
Alby96 committed 2026-11-04 16:04:05 +01:00
commit b0b55ff570
12 files changed
+894 -53

No files matched your search

@@ -236,7 +236,7 @@ public sealed class AppSettings
/// <summary>Send and take project settings changed on one side without asking (Server.html).</summary>
public bool SyncSettingsAutomatically { get; set; } = true;
/// <summary>Pause upload jobs while Windows reports the connection as metered (Server.html).</summary>
/// <summary>Pause transfers with a server (uploads, workspace copies and renders sent) while Windows reports the connection as metered (Server.html).</summary>
public bool PauseUploadsOnMetered { get; set; }
// ---- Jobs ----
+1 -1
View File
@@ -160,7 +160,7 @@
</StackPanel>
<CheckBox Content="{l:Loc Server.KeepProxies}" IsChecked="{Binding KeepProxiesOffline}" ToolTip="{l:Loc Tooltips.Server.KeepProxies}" Margin="0,0,22,0" />
<CheckBox Content="{l:Loc Server.AutoSync}" IsChecked="{Binding SyncSettingsAutomatically}" ToolTip="{l:Loc Tooltips.Server.AutoSync}" Margin="0,0,22,0" />
<CheckBox Content="{l:Loc Server.PauseMetered}" IsChecked="{Binding PauseUploadsOnMetered}" ToolTip="{l:Loc Tooltips.Server.PauseMetered}" Margin="0,0,22,0" />
<CheckBox Content="{l:Loc Server.PauseMeteredTransfers}" IsChecked="{Binding PauseUploadsOnMetered}" ToolTip="{l:Loc Tooltips.Server.PauseMeteredTransfers}" Margin="0,0,22,0" />
</WrapPanel>
</Border>
</Grid>
+34 -9
View File
@@ -4,14 +4,17 @@ using Chronos.App.Infrastructure;
using Chronos.Core.Diagnostics;
using Chronos.Core.Model;
using Chronos.Data.Jobs;
using Chronos.Data.Workspaces;
namespace Chronos.App.Server;
/// <summary>
/// "Pause uploads on metered networks" (Server.html): while <see cref="AppSettings.PauseUploadsOnMetered"/> is on and
/// Windows reports the connection as metered, upload jobs are paused (a running one stops after its current chunk and
/// keeps its checkpoint); they are resumed when the connection is no longer metered or the option goes off. Only the
/// uploads it paused are resumed. Checked when the network or an upload job changes, and every minute.
/// "Pause metered transfers" (Server.html): while <see cref="AppSettings.PauseUploadsOnMetered"/> is on and Windows reports
/// the connection as metered, the transfers with a server are paused (a running one stops after its current chunk or file
/// and keeps its checkpoint): upload jobs, and since phase 5c the workspace's copies from a server and its renders sent to
/// one (<see cref="Holds"/>); a copy from or a send to this PC's archive is never held. They are resumed when the connection
/// is no longer metered or the option goes off. Only the jobs it paused are resumed. Checked when the network or one of
/// those jobs changes, and every minute.
/// </summary>
public sealed class UploadHold : IDisposable
{
@@ -58,7 +61,26 @@ public sealed class UploadHold : IDisposable
private void OnJobChanged(Job job)
{
if (job is { Kind: JobKind.UploadCommit, State: JobState.Queued or JobState.Running }) Request();
if (job is { State: JobState.Queued or JobState.Running } && Holds(job)) Request();
}
/// <summary>The kinds of job a metered connection may hold (<see cref="Holds"/> says which of them).</summary>
internal static IReadOnlyList<JobKind> Kinds { get; } = [JobKind.UploadCommit, JobKind.WorkspaceCopy, JobKind.WorkspaceSend];
/// <summary>
/// Whether a metered connection holds <paramref name="job"/>: an upload, or a workspace copy or send whose home is a server
/// (its parameters name one). One whose parameters cannot be read is not held: it fails with its reason.
/// </summary>
internal static bool Holds(Job job)
{
ArgumentNullException.ThrowIfNull(job);
return job.Kind switch
{
JobKind.UploadCommit => true,
JobKind.WorkspaceCopy => WorkspaceJobs.CopyParameters(job)?.Server is { Length: > 0 },
JobKind.WorkspaceSend => WorkspaceJobs.SendParameters(job)?.Server is { Length: > 0 },
_ => false,
};
}
private async Task ApplyAsync()
@@ -71,10 +93,13 @@ public sealed class UploadHold : IDisposable
{
foreach (var state in new[] { JobState.Queued, JobState.Running })
{
foreach (var job in (await db.Jobs.ListAsync(state, JobKind.UploadCommit, 500)).Items)
foreach (var kind in Kinds)
{
await engine.PauseAsync(job.Id);
_held.Add(job.Id);
foreach (var job in (await db.Jobs.ListAsync(state, kind, 500)).Items.Where(Holds))
{
await engine.PauseAsync(job.Id);
_held.Add(job.Id);
}
}
}
return;
@@ -87,7 +112,7 @@ public sealed class UploadHold : IDisposable
}
catch (Data.DatabaseException ex)
{
Log.Warning("sync", "Uploads could not be paused or resumed for the metered connection", ex);
Log.Warning("sync", "Transfers could not be paused or resumed for the metered connection", ex);
}
finally
{