24 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PlotDirector.Companion.Protocol;
namespace PlotDirector.Companion.Agent;
// Pure presentation policy shared by portable tests and the Windows Forms view.
public static class CompanionPresentation
{
public static bool NeedsAuthorisation(ConnectionHealth? health)=>health==null||(health.State=="Action required"&&health.Authentication!="pending")||(string.IsNullOrEmpty(health.State)&&health.Authentication is "expired" or "unauthorised");
public static string WordStatus(bool connected,int book,DateTime verified,string presence,DateTime now)=>!connected?"Microsoft Word · not connected":book==0?"Microsoft Word · connected locally":presence!=""&&now-verified<TimeSpan.FromSeconds(45)?"Microsoft Word · connected to this book":"Microsoft Word · connected locally, registration pending";
public static bool Dark(bool? windowsDark)=>windowsDark??false;
public static string Connection(ConnectionHealth? health,DateTime now)
{
if(health?.Authentication=="pending")return "Waiting for browser approval…";
if(health?.State=="Connected"&&(now-health.VerifiedUtc>TimeSpan.FromSeconds(90)||health.Server!="online"||health.Authentication!="verified"))return "Reconnecting";
if(!string.IsNullOrEmpty(health?.State))return health.State=="Action required"?"Action required · sign in or check connection settings":health.State;
if(health==null)return "Welcome · connect to PlotDirector";
if(health.Authentication is "expired" or "unauthorised")return "Sign in again";
if(health.Server=="checking")return "Checking your connection…";
if(health.Server!="online")return health.Server=="offline"?"Offline · Word is still available":"Connect to PlotDirector";
if(now-health.VerifiedUtc>TimeSpan.FromSeconds(90))return "Connection needs checking";
return health.Authentication=="verified"?"Connected to PlotDirector":"Sign in to continue";
}
public static string Next(bool document,bool book,int chapters,bool busy)=>!document?"Open a manuscript in Word to begin. You can still use PlotDirector in your browser.":!book?"Choose the PlotDirector book for this manuscript.":busy?"Your manuscript stays editable while the Companion works.":chapters==0?"Find chapters using your document’s Heading 1 styles.":"Select chapters to analyse. Review and import are separate steps in PlotDirector.";
public static string Chapter(bool analysing,bool analysed,bool failed=false)=>analysing?"Analysing…":analysed?"Analysed · review in PlotDirector":failed?"Could not analyse · select to retry":"Ready to analyse";
}