99 lines
3.2 KiB
C#
99 lines
3.2 KiB
C#
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)
|
|
{
|
|
return RegisterAsyncFrameHandler(handler,handlerName,10000);
|
|
}
|
|
public ExtensionFeatures RegisterFileSystem(TimelapseFileSystem fs,string name)
|
|
{
|
|
if(!Valid || Instance == null) return this;
|
|
Instance._fs.Add((fs,name,Extension));
|
|
return this;
|
|
}
|
|
public ExtensionFeatures RegisterAsyncFrameHandler(Func<Image<Rgb24>,Task<bool>> handler,string handlerName,int priority)
|
|
{
|
|
if(!Valid || Instance == null) return this;
|
|
Instance._frameHandlers.Add((handler,handlerName,Extension,priority));
|
|
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 RegisterFrameHandler(Func<Image<Rgb24>,bool> handler,string handlerName,int priority)
|
|
{
|
|
if(!Valid) return this;
|
|
RegisterAsyncFrameHandler(async(e)=>{
|
|
if(handler !=null)
|
|
{
|
|
return await Task.Run<bool>(()=>{
|
|
return handler(e);
|
|
});
|
|
}
|
|
return true;
|
|
},handlerName,priority);
|
|
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;
|
|
}
|
|
} |