Unione dell'ondata 5 (desktop M6, rifiniture M8): avvisi collegati una sola volta nella composizione condivisa per le due vesti

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 22:04:54 +00:00
commit 5be0b1dee8
62 files changed
+4168 -327

No files matched your search

+32 -9
View File
@@ -1,6 +1,7 @@
using System.Globalization;
using Febe.Browser.Recipes;
using Febe.Core.Abstractions;
using Febe.Core.Alerts;
using Febe.Core.Collection.Downloads;
using Febe.Core.Domain;
using Febe.Core.Engine;
@@ -12,6 +13,7 @@ using Febe.Web;
using Febe.Web.Connection;
using Febe.Web.Engine;
using Febe.Web.Library;
using Febe.Web.Native;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@@ -25,7 +27,8 @@ namespace Febe.App;
/// in Docker, Data folder not writable or on a network share, WebView2 missing on Windows) neither the engine nor the
/// browser start, and the interface shows only the page that explains it. Otherwise: database, library, thumbnails,
/// perceptual hashes, import, daily backup, the browser of the platform, the collection pipeline, the download queue,
/// the engine, the connection, the alerts hook and the interface. Disposing stops everything in order.
/// the engine, the connection, the alerts (Windows notifications through the shell, Telegram, free disk space) and the
/// interface. Disposing stops everything in order.
/// </summary>
public sealed class FebeApp : IAsyncDisposable
{
@@ -36,6 +39,7 @@ public sealed class FebeApp : IAsyncDisposable
private readonly List<IDisposable> _disposables = [];
private readonly List<Action> _unsubscribe = [];
private readonly TaskCompletionSource _running = new(TaskCreationOptions.RunContinuationsAsynchronously);
private TelegramClient? _telegram;
private string? _temporaryFolder;
private int _disposed;
@@ -85,8 +89,11 @@ public sealed class FebeApp : IAsyncDisposable
/// <summary>When Alberto last used the browser («Riprendi» after a verification).</summary>
public BrowserUseTracker Tracker { get; } = new();
/// <summary>The alerts hook (null with a configuration problem).</summary>
public AlertDispatcher? Alerts { get; private set; }
/// <summary>
/// The alerts of spec §13.3 (null with a configuration problem): Windows notifications through the shell's
/// <see cref="INativeShell"/> (silent in Docker), Telegram, and the free space of the library and the Data folder.
/// </summary>
public AlertService? Alerts { get; private set; }
/// <summary>Completes when browser, pipeline and engine are running (never, with a configuration problem).</summary>
public Task Running => _running.Task;
@@ -246,6 +253,8 @@ public sealed class FebeApp : IAsyncDisposable
EventHandler<bool> drivingChanged = (_, _) => engine.NotifyUserDrivingChanged();
browser.UserDriving.Changed += drivingChanged;
_unsubscribe.Add(() => browser.UserDriving.Changed -= drivingChanged);
_telegram = new TelegramClient(hooks.TelegramHandler);
var telegramChannel = new TelegramAlertChannel(_telegram);
await StartWebAsync(hooks, s =>
{
@@ -266,6 +275,7 @@ public sealed class FebeApp : IAsyncDisposable
}
s.AddSingleton(new DailyBackup(Database, Clock, data.Backups));
s.AddSingleton<IAlertTestSender>(telegramChannel);
_platform.RegisterServices(s, this);
}).ConfigureAwait(false);
@@ -275,14 +285,28 @@ public sealed class FebeApp : IAsyncDisposable
await Web.Services.GetRequiredService<Febe.Web.Import.ImportHub>().GetAsync(ct).ConfigureAwait(false);
}
// The alerts hook: the channels the shell registered (Windows notifications; Telegram with M8).
Alerts = new AlertDispatcher(services.Events, Database.Settings, Web.Services.GetServices<IAlertChannel>(), Log);
// Alerts (spec §13.3): from the engine's timeline and the free space of the two folders, to the shell's
// notifications (the desktop's; in Docker the shell cannot notify and the channel stays silent) and Telegram.
// The strip of the interface is the engine snapshot's. The library folder is read at every check: on Windows
// it can change in Impostazioni while Febe runs.
Alerts = new AlertService(
Database.Settings,
Clock,
services.Events,
[new NativeShellAlertChannel(Web.Services.GetRequiredService<INativeShell>()), telegramChannel],
new AlertServiceOptions
{
FolderSource = () => [WatchedFolder.Library(library.Layout.Root), WatchedFolder.Data(data.Root)],
FreeSpace = hooks.FreeSpace ?? new DriveFreeSpaceProbe(),
Log = (level, message) => Log.Write(level == AlertLogLevel.Warning ? LogLevel.Warning : LogLevel.Information, "avvisi", message),
}).Attach();
// Housekeeping in the background: temporary files of an interrupted run, the daily copy of the database.
var lifetime = _lifetime.Token;
_background.Add(Task.Run(() => CleanTemporaryFilesAsync(staging, layout, lifetime), CancellationToken.None));
_background.Add(Task.Run(() => BackupLoopAsync(new DailyBackup(Database, Clock, data.Backups), lifetime), CancellationToken.None));
_background.Add(Task.Run(() => BringUpBrowserAsync(ingest, staging, services, engine, runner, lifetime), CancellationToken.None));
_background.Add(Task.Run(() => Alerts.WatchDiskSpaceAsync(lifetime), CancellationToken.None));
}
private async Task StartWebAsync(FebeAppHooks hooks, Action<IServiceCollection> register)
@@ -570,10 +594,9 @@ public sealed class FebeApp : IAsyncDisposable
unsubscribe();
}
if (Alerts is { } alerts)
{
await Quietly(() => alerts.DisposeAsync().AsTask()).ConfigureAwait(false);
}
// Alerts in flight are cancelled before the Telegram client goes away.
Alerts?.Dispose();
_telegram?.Dispose();
if (Import is { } import)
{