timelapsenow/TimelapseApi/ExtensionFeatures.cs

81 lines
2.6 KiB
C#
Raw Normal View History

2022-05-20 02:06:35 +00:00
namespace TimelapseApi;
using Eto.Forms;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
public sealed class ExtensionFeatures
{
internal Api? Instance {get { return Extension.Instance;}}
internal TimelapseExtension Extension {get;private set;}
internal bool Valid {get;private set;}
internal ExtensionFeatures(TimelapseExtension ext)
{
Extension=ext;
Valid=true;
}
public ExtensionFeatures RegisterSettingsDialog(Func<Dialog> dialog,string text)
{
if(!Valid || Instance == null) return this;
Instance._extSettings.Add((dialog,text,Extension));
return this;
}
public ExtensionFeatures RegisterAsyncFrameHandler(Func<Image<Rgb24>,Task<bool>> handler,string handlerName)
{
if(!Valid || Instance == null) return this;
Instance._frameHandlers.Add((handler,handlerName,Extension));
return this;
}
public ExtensionFeatures RegisterFileSystem(TimelapseFileSystem fs,string name)
{
if(!Valid || Instance == null) return this;
Instance._fs.Add((fs,name,Extension));
return this;
}
public ExtensionFeatures RegisterFrameHandler(Func<Image<Rgb24>,bool> handler,string handlerName)
{
if(!Valid) return this;
RegisterAsyncFrameHandler(async(e)=>{
if(handler !=null)
{
return await Task.Run<bool>(()=>{
return handler(e);
});
}
return true;
},handlerName);
return this;
}
public ExtensionFeatures RegisterExport(Func<IEnumerable<Image<Rgb24>>,string,CancellationToken,Task> export,FileFilter[] filter,string text)
{
if(!Valid || Instance == null) return this;
if(export != null)
Instance._export.Add((export,text,Extension,filter));
return this;
}
public ExtensionFeatures RegisterAsyncShareTarget(Func<Window,string,Task> share,string text)
{
if(!Valid || Instance == null) return this;
if(share != null)
Instance._share.Add((share,text,Extension));
return this;
}
public ExtensionFeatures RegisterShareTarget(Action<Window,string> share,string text)
{
if(!Valid) return this;
return RegisterAsyncShareTarget(async(s,e)=>{
await Task.Run(
()=>{
if(share !=null)
{
share(s,e);
}
}
);
},text);
}
public void Close()
{
Valid=false;
}
}