The owner wants the shared library to keep running while Chronos runs. While sharing is on (or on its way), closing the main window now hides it behind a tray icon (Open Chronos, Exit) instead of ending Chronos. Exit asks first when clients used the library in the last minutes, then closes the window for real, so the editor still stores its last edit and the exit path stops sharing before the other services. A start at sign-in (--minimized) with sharing on waits in the tray. With sharing off nothing changes. The decisions live in ShareLifetime (unit-tested); ShellTray wires them to the window, LibraryShare and OsNotifications, whose balloons reuse the icon. Server > This library also warns when the 1.0 Windows Server's service (ChronosServer) is installed, through a read-only SCM P/Invoke probe. Refs #67 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
4.3 KiB
C#
92 lines
4.3 KiB
C#
using System.Globalization;
|
||
using Chronos.App.Server;
|
||
using Chronos.App.Shell;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Core.Windows.Services;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.App.Tests.Server;
|
||
|
||
/// <summary>
|
||
/// The desktop's lifetime while it shares its library (owner review 5, #67): closing hides to the tray while sharing, Exit
|
||
/// asks first when clients are active, a start at sign-in waits in the tray; with sharing off nothing changes.
|
||
/// </summary>
|
||
public sealed class ShareTrayTests
|
||
{
|
||
public ShareTrayTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
|
||
[Test]
|
||
public void ChronosOutlivesItsWindowOnlyWhileSharingIsOnOrOnItsWay()
|
||
{
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.On));
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.Starting));
|
||
// On in the settings, not started yet: the index is opening, or the archive's drive is unplugged.
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.Off));
|
||
Assert.False(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.Failed));
|
||
// Turned off and still stopping: the icon stays until it has stopped.
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: false, ShareState.On));
|
||
Assert.False(ShareLifetime.KeepsRunning(shareEnabled: false, ShareState.Off));
|
||
Assert.False(ShareLifetime.KeepsRunning(shareEnabled: false, ShareState.Failed));
|
||
}
|
||
|
||
[Test]
|
||
public void ClosingHidesToTheTrayWhileSharingAndExitsOtherwise()
|
||
{
|
||
Assert.Equal(CloseAction.HideToTray, ShareLifetime.OnClose(exiting: false, keepsRunning: true));
|
||
Assert.Equal(CloseAction.Exit, ShareLifetime.OnClose(exiting: false, keepsRunning: false));
|
||
// Tray › Exit, or Windows ending the session: the window closes for real.
|
||
Assert.Equal(CloseAction.Exit, ShareLifetime.OnClose(exiting: true, keepsRunning: true));
|
||
Assert.Equal(CloseAction.Exit, ShareLifetime.OnClose(exiting: true, keepsRunning: false));
|
||
}
|
||
|
||
[Test]
|
||
public void ExitAsksFirstOnlyWhenClientsUseTheSharedLibrary()
|
||
{
|
||
Assert.True(ShareLifetime.AsksBeforeExit(ShareState.On, 1));
|
||
Assert.True(ShareLifetime.AsksBeforeExit(ShareState.On, 3));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.On, 0));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.Starting, 2));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.Failed, 2));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.Off, 2));
|
||
}
|
||
|
||
[Test]
|
||
public void TheExitQuestionKeepsSharingByDefaultAndCountsTheClients()
|
||
{
|
||
var one = ShellTray.ExitRequest(1);
|
||
Assert.Equal("Stop sharing?", one.Heading);
|
||
Assert.Equal("1 client used this library in the last minutes. Exiting Chronos stops sharing it.", one.Message);
|
||
Assert.Equal(("Keep sharing", "Exit"), (one.SafeText, one.ActionText));
|
||
Assert.False(one.IsDestructive);
|
||
Assert.Null(one.TypedConfirmation);
|
||
Assert.Contains("4 clients used", ShellTray.ExitRequest(4).Message);
|
||
}
|
||
|
||
[Test]
|
||
public void AStartAtSignInWaitsInTheTrayWhileSharingIsOn()
|
||
{
|
||
Assert.Equal(StartWindow.Tray, ShareLifetime.Start(minimized: true, shareEnabled: true));
|
||
Assert.Equal(StartWindow.Minimized, ShareLifetime.Start(minimized: true, shareEnabled: false));
|
||
Assert.Equal(StartWindow.Shown, ShareLifetime.Start(minimized: false, shareEnabled: true));
|
||
Assert.Equal(StartWindow.Shown, ShareLifetime.Start(minimized: false, shareEnabled: false));
|
||
}
|
||
|
||
[Test]
|
||
public void TheTrayToolTipNamesTheLibraryOrThisPc()
|
||
{
|
||
Assert.Equal("Chronos · sharing Studio", ShareLifetime.ToolTip(" Studio ", "STUDIO-PC"));
|
||
Assert.Equal("Chronos · sharing STUDIO-PC", ShareLifetime.ToolTip(null, "STUDIO-PC"));
|
||
Assert.Equal("Chronos · sharing STUDIO-PC", ShareLifetime.ToolTip(" ", "STUDIO-PC"));
|
||
}
|
||
|
||
[Test]
|
||
[WindowsOnly]
|
||
public void TheServiceProbeFindsInstalledServicesOnly()
|
||
{
|
||
// The event log service runs on every Windows; the probe asks connect and query-status rights only.
|
||
Assert.True(ServiceProbe.IsInstalled("EventLog"));
|
||
Assert.False(ServiceProbe.IsInstalled("ChronosNoSuchService" + Guid.NewGuid().ToString("N")));
|
||
Assert.Equal("ChronosServer", ServiceProbe.LegacyServer);
|
||
}
|
||
}
|