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,string text) { if(!Valid || Instance == null) return this; Instance._extSettings.Add((dialog,text,Extension)); return this; } public ExtensionFeatures RegisterAsyncFrameHandler(Func,Task> 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,bool> handler,string handlerName) { if(!Valid) return this; RegisterAsyncFrameHandler(async(e)=>{ if(handler !=null) { return await Task.Run(()=>{ return handler(e); }); } return true; },handlerName); return this; } public ExtensionFeatures RegisterExport(Func>,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 share,string text) { if(!Valid || Instance == null) return this; if(share != null) Instance._share.Add((share,text,Extension)); return this; } public ExtensionFeatures RegisterShareTarget(Action 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; } }