refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s

The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-23 12:45:18 +02:00
1 parent c99842cc86
commit f2b58522b9
1801 files changed
+11804 -10676

No files matched your search

@@ -0,0 +1,62 @@
using System.IO;
using Chronos.Core.Diagnostics;
using Chronos.Core.IO;
namespace Chronos.Uploader.Infrastructure;
/// <summary>
/// Writes state files off the UI thread with <see cref="AtomicFile"/>. Only the newest content of each file is kept
/// while a write is in progress, so a slow disk never writes an older snapshot after a newer one.
/// </summary>
public sealed class CoalescingWriter
{
private readonly Lock _gate = new();
private readonly Dictionary<string, byte[]> _pending = new(StringComparer.OrdinalIgnoreCase);
private Task _worker = Task.CompletedTask;
private bool _running;
public void Write(string path, byte[] content)
{
lock (_gate)
{
_pending[path] = content;
if (_running) return;
_running = true;
_worker = Task.Run(Drain);
}
}
/// <summary>Waits for pending writes (at exit).</summary>
public void Flush(TimeSpan timeout)
{
Task worker;
lock (_gate) worker = _worker;
if (!worker.Wait(timeout)) Log.Warning("persist", "State files still being written at exit");
}
private void Drain()
{
while (true)
{
KeyValuePair<string, byte[]> next;
lock (_gate)
{
if (_pending.Count == 0)
{
_running = false;
return;
}
next = _pending.First();
_pending.Remove(next.Key);
}
try
{
AtomicFile.WriteAllBytes(next.Key, next.Value);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Log.Warning("persist", $"{next.Key} not written", ex);
}
}
}
}
@@ -0,0 +1,27 @@
namespace Chronos.Uploader.Infrastructure;
/// <summary>
/// <c>Chronos.Uploader.exe [--tray] [--capture &lt;dir&gt;] [files or folders…]</c>: paths are enqueued, <c>--tray</c>
/// starts hidden (used by the Run key), <c>--capture</c> renders screenshots and exits.
/// </summary>
public sealed record CommandLine(IReadOnlyList<string> Paths, bool StartInTray, string? CaptureDirectory)
{
public const string TrayOption = "--tray";
public const string CaptureOption = "--capture";
public static CommandLine Parse(IReadOnlyList<string> args)
{
var paths = new List<string>();
var tray = false;
string? capture = null;
for (var i = 0; i < args.Count; i++)
{
var a = args[i];
if (a.Equals(TrayOption, StringComparison.OrdinalIgnoreCase)) tray = true;
else if (a.Equals(CaptureOption, StringComparison.OrdinalIgnoreCase))
capture = i + 1 < args.Count && !args[i + 1].StartsWith("--", StringComparison.Ordinal) ? args[++i] : "screenshots";
else if (!a.StartsWith("--", StringComparison.Ordinal) && a.Length > 0) paths.Add(a);
}
return new CommandLine(paths, tray, capture);
}
}
@@ -0,0 +1,98 @@
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Text;
using Chronos.Core.Diagnostics;
namespace Chronos.Uploader.Infrastructure;
/// <summary>
/// One uploader per Windows session: a named mutex marks the running instance, and a second launch hands its
/// file arguments over a named pipe (current user only) before exiting.
/// </summary>
public sealed class SingleInstance : IDisposable
{
private const string MutexName = @"Local\Chronos.Uploader";
private const string Header = "CHRONOS-UPLOADER/1";
private const int MaxMessageBytes = 1 << 20;
private readonly Mutex _mutex;
private readonly CancellationTokenSource _stop = new();
private SingleInstance(Mutex mutex) => _mutex = mutex;
private static string PipeName => $"Chronos.Uploader.{Process.GetCurrentProcess().SessionId}.{Environment.UserName}";
/// <summary>The instance guard, or null when another uploader already runs in this session.</summary>
public static SingleInstance? TryAcquire()
{
var mutex = new Mutex(initiallyOwned: true, MutexName, out var createdNew);
if (createdNew) return new SingleInstance(mutex);
mutex.Dispose();
return null;
}
/// <summary>Sends <paramref name="args"/> (absolute paths; empty = just show the window) to the running instance.</summary>
public static void HandOver(IReadOnlyList<string> args)
{
try
{
using var pipe = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.CurrentUserOnly);
pipe.Connect(3000);
pipe.Write(Encode(args));
pipe.Flush();
}
catch (Exception ex) when (ex is IOException or TimeoutException or UnauthorizedAccessException)
{
Log.Warning("instance", "Could not reach the running uploader", ex);
}
}
/// <summary>Receives messages from later launches; <paramref name="received"/> runs on a pool thread.</summary>
public void Listen(Action<IReadOnlyList<string>> received) => _ = ListenAsync(received, _stop.Token);
public void Dispose()
{
_stop.Cancel();
_mutex.ReleaseMutex();
_mutex.Dispose();
_stop.Dispose();
}
/// <summary>UTF-8: a header line, then one argument per line (paths cannot contain line breaks).</summary>
public static byte[] Encode(IReadOnlyList<string> args) =>
Encoding.UTF8.GetBytes(Header + "\n" + string.Join("\n", args.Where(a => !a.Contains('\n', StringComparison.Ordinal))));
/// <summary>Arguments of a message, or null when it is not one of ours.</summary>
public static IReadOnlyList<string>? Decode(ReadOnlySpan<byte> message)
{
if (message.Length > MaxMessageBytes) return null;
var lines = Encoding.UTF8.GetString(message).Split('\n');
if (lines[0] != Header) return null;
return [.. lines.Skip(1).Where(l => l.Length > 0)];
}
private static async Task ListenAsync(Action<IReadOnlyList<string>> received, CancellationToken ct)
{
while (!ct.IsCancellationRequested)
{
try
{
await using var pipe = new NamedPipeServerStream(PipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte,
PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly);
await pipe.WaitForConnectionAsync(ct).ConfigureAwait(false);
using var buffer = new MemoryStream();
await pipe.CopyToAsync(buffer, ct).ConfigureAwait(false);
if (Decode(buffer.GetBuffer().AsSpan(0, (int)buffer.Length)) is { } args) received(args);
}
catch (OperationCanceledException)
{
return;
}
catch (IOException ex)
{
Log.Warning("instance", "Hand-over pipe failed; listening again", ex);
}
}
}
}
@@ -0,0 +1,80 @@
using System.IO;
using System.Security;
using Microsoft.Win32;
using Chronos.Core.Diagnostics;
using Chronos.Core.IO;
namespace Chronos.Uploader.Infrastructure;
/// <summary>"Start with Windows".</summary>
public interface IStartupRegistration
{
bool IsEnabled { get; }
void SetEnabled(bool enabled);
}
/// <summary>
/// <c>HKCU\Software\Microsoft\Windows\CurrentVersion\Run</c> value that starts the uploader in the tray at sign-in.
/// The registry stays the source of truth because Task Manager can turn it off: an entry it turned off
/// (<see cref="StartupApproval"/>) shows as off, and ticking the box turns it on again. Uninstalling removes the value
/// when it starts the Uploader the uninstaller removes (<see cref="StartupCommand"/> names it for both).
/// </summary>
/// <param name="executable">The Uploader's program; the running one by default.</param>
/// <param name="root">The registry hive holding the entries; <c>HKEY_CURRENT_USER</c> by default (tests pass a scratch key).</param>
public sealed class RunKeyStartupRegistration(string? executable = null, RegistryKey? root = null) : IStartupRegistration
{
private const string RunKey = StartupCommand.RunKey;
private const string ValueName = StartupCommand.UploaderValue;
private readonly string? _executable = executable ?? Environment.ProcessPath;
private readonly RegistryKey _root = root ?? Registry.CurrentUser;
/// <summary>The entry exists and Task Manager has not turned it off.</summary>
public bool IsEnabled => HasEntry && !StartupApproval.IsTurnedOff(Read(StartupApproval.RunKey) as byte[]);
private bool HasEntry => Read(RunKey) is string { Length: > 0 };
private string Command => StartupCommand.Format(_executable ?? string.Empty, CommandLine.TrayOption);
public void SetEnabled(bool enabled) => Update(key =>
{
if (enabled) key.SetValue(ValueName, Command, RegistryValueKind.String);
else key.DeleteValue(ValueName, throwOnMissingValue: false);
// Task Manager's "Disable" outlives a new command: ticking the box undoes it, and unticking leaves nothing behind.
using var approval = _root.OpenSubKey(StartupApproval.RunKey, writable: true);
approval?.DeleteValue(ValueName, throwOnMissingValue: false);
});
/// <summary>Points an existing entry at the current executable (after an update moved it); one Task Manager turned off stays off.</summary>
public void Refresh()
{
if (HasEntry) Update(key => key.SetValue(ValueName, Command, RegistryValueKind.String));
}
private object? Read(string subKey)
{
try
{
using var key = _root.OpenSubKey(subKey);
return key?.GetValue(ValueName);
}
catch (Exception ex) when (ex is SecurityException or IOException)
{
return null;
}
}
private void Update(Action<RegistryKey> change)
{
try
{
using var key = _root.CreateSubKey(RunKey, writable: true);
change(key);
}
catch (Exception ex) when (ex is SecurityException or UnauthorizedAccessException or IOException)
{
Log.Warning("startup", "Run key not updated", ex);
}
}
}
@@ -0,0 +1,98 @@
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
namespace Chronos.Uploader.Infrastructure;
/// <summary>
/// Encrypts the sign-in token for the current Windows user with DPAPI (<c>CryptProtectData</c>, no machine scope),
/// so <c>uploader.json</c> copied to another account or PC cannot be used.
/// </summary>
public static partial class TokenProtector
{
private const int CryptProtectUiForbidden = 0x1;
// Ties the blob to this program; other DPAPI consumers of the same user cannot unwrap it by accident.
private static readonly byte[] Entropy = "Chronos.Uploader.Token.v1"u8.ToArray();
/// <summary>Base64 DPAPI blob of <paramref name="token"/>.</summary>
public static string Protect(string token)
{
var plain = Encoding.UTF8.GetBytes(token);
try
{
return Convert.ToBase64String(Transform(plain, protect: true));
}
finally
{
CryptographicOperations.ZeroMemory(plain);
}
}
/// <summary>The token, or null when the blob is corrupt or belongs to another user.</summary>
public static string? Unprotect(string protectedToken)
{
byte[] blob;
try
{
blob = Convert.FromBase64String(protectedToken);
}
catch (FormatException)
{
return null;
}
try
{
var plain = Transform(blob, protect: false);
var token = Encoding.UTF8.GetString(plain);
CryptographicOperations.ZeroMemory(plain);
return token;
}
catch (CryptographicException)
{
return null;
}
}
private static unsafe byte[] Transform(byte[] input, bool protect)
{
fixed (byte* inPtr = input)
fixed (byte* entropyPtr = Entropy)
{
var source = new DataBlob { Size = input.Length, Data = (IntPtr)inPtr };
var entropy = new DataBlob { Size = Entropy.Length, Data = (IntPtr)entropyPtr };
var ok = protect
? CryptProtectData(source, null, entropy, IntPtr.Zero, IntPtr.Zero, CryptProtectUiForbidden, out var output)
: CryptUnprotectData(source, IntPtr.Zero, entropy, IntPtr.Zero, IntPtr.Zero, CryptProtectUiForbidden, out output);
if (!ok) throw new CryptographicException(Marshal.GetLastPInvokeError());
try
{
var result = new byte[output.Size];
Marshal.Copy(output.Data, result, 0, output.Size);
return result;
}
finally
{
LocalFree(output.Data);
}
}
}
[StructLayout(LayoutKind.Sequential)]
private struct DataBlob
{
public int Size;
public IntPtr Data;
}
[LibraryImport("crypt32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool CryptProtectData(in DataBlob dataIn, string? description, in DataBlob entropy, IntPtr reserved, IntPtr prompt, int flags, out DataBlob dataOut);
[LibraryImport("crypt32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool CryptUnprotectData(in DataBlob dataIn, IntPtr description, in DataBlob entropy, IntPtr reserved, IntPtr prompt, int flags, out DataBlob dataOut);
[LibraryImport("kernel32.dll")]
private static partial IntPtr LocalFree(IntPtr memory);
}
@@ -0,0 +1,38 @@
using System.IO;
namespace Chronos.Uploader.Infrastructure;
/// <summary>
/// Where the uploader keeps its files: <c>%LOCALAPPDATA%\Chronos</c> (shared with the client), or <c>.\data</c> next
/// to the executable when <c>portable.txt</c> exists — the desktop client's rule, except that the client never keeps
/// its SQLite index in a folder OneDrive synchronises; the Uploader's JSON files, written atomically, stay there.
/// </summary>
public sealed class UploaderEnvironment
{
private UploaderEnvironment(string dataDirectory)
{
DataDirectory = dataDirectory;
Directory.CreateDirectory(DataDirectory);
Directory.CreateDirectory(LogDirectory);
}
public string DataDirectory { get; }
public string LogDirectory => Path.Combine(DataDirectory, "logs");
/// <summary>Settings, DPAPI-protected token and trusted certificate fingerprints.</summary>
public string SettingsPath => Path.Combine(DataDirectory, "uploader.json");
/// <summary>The persisted upload queue.</summary>
public string QueuePath => Path.Combine(DataDirectory, "uploader-queue.json");
/// <summary>Files of watch folders the server already confirmed.</summary>
public string WatchMemoryPath => Path.Combine(DataDirectory, "uploader-watch.json");
public static UploaderEnvironment Detect()
{
var exeDir = AppContext.BaseDirectory;
if (File.Exists(Path.Combine(exeDir, "portable.txt"))) return new UploaderEnvironment(Path.Combine(exeDir, "data"));
var local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return new UploaderEnvironment(Path.Combine(local, "Chronos"));
}
}
@@ -0,0 +1,77 @@
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using Chronos.Core.Diagnostics;
using Chronos.Core.IO;
using Chronos.Ui.Theming;
using Chronos.Uploader.Uploads;
namespace Chronos.Uploader.Infrastructure;
/// <summary>
/// <c>uploader.json</c>. The bearer token is stored only DPAPI-protected for the current Windows user
/// (<see cref="TokenProtector"/>); "Start with Windows" lives in the registry, which stays the source of truth.
/// </summary>
public sealed class UploaderSettings
{
public string? ServerUrl { get; set; }
public string? Username { get; set; }
/// <summary>Base64 of the DPAPI (CurrentUser) blob of the bearer token.</summary>
public string? ProtectedToken { get; set; }
/// <summary>SHA-256 fingerprints (XX:XX:…) of self-signed certificates the user trusted (TOFU).</summary>
public List<string> TrustedFingerprints { get; set; } = [];
/// <summary>Upload limit in MB/s (decimal megabytes); 0 = unlimited.</summary>
public int BandwidthLimit { get; set; }
public bool MinimizeToTray { get; set; } = true;
public bool DeleteAfterUpload { get; set; }
public UploadTargetMode Target { get; set; } = UploadTargetMode.Sessions;
public Guid? TargetSequenceId { get; set; }
public string? NewSequenceTitle { get; set; }
public List<WatchFolderSettings> WatchFolders { get; set; } = [];
public string? Language { get; set; }
public AppTheme Theme { get; set; } = AppTheme.Dark;
public WindowPlacement? Window { get; set; }
public sealed class WatchFolderSettings
{
public string Path { get; set; } = string.Empty;
public int IntervalSeconds { get; set; } = 60;
}
public sealed class WindowPlacement
{
public double Left { get; set; }
public double Top { get; set; }
public double Width { get; set; }
public double Height { get; set; }
}
public static UploaderSettings Load(string path)
{
try
{
if (File.Exists(path))
return JsonSerializer.Deserialize(File.ReadAllBytes(path), UploaderSettingsJson.Default.UploaderSettings) ?? new UploaderSettings();
}
catch (JsonException ex)
{
// A corrupt settings file must never block startup; defaults apply.
Log.Warning("settings", "uploader.json unreadable; using defaults", ex);
}
catch (IOException ex)
{
Log.Warning("settings", "uploader.json unreadable; using defaults", ex);
}
return new UploaderSettings();
}
public void Save(string path) => AtomicFile.WriteAllBytes(path, JsonSerializer.SerializeToUtf8Bytes(this, UploaderSettingsJson.Default.UploaderSettings));
}
[JsonSourceGenerationOptions(WriteIndented = true, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, UseStringEnumConverter = true)]
[JsonSerializable(typeof(UploaderSettings))]
internal sealed partial class UploaderSettingsJson : JsonSerializerContext;