diff --git a/Timelapse.Api/Class1.cs b/Timelapse.Api/Class1.cs index 0e47662..426f512 100644 --- a/Timelapse.Api/Class1.cs +++ b/Timelapse.Api/Class1.cs @@ -40,27 +40,41 @@ namespace Timelapse.Api } public class Extensions { + public static IReadOnlyDictionary Components {get {return _components;}} + internal static Dictionary _components = new Dictionary(); public static string GetId(TimelapseExtension e) { return e.__id; } - public static async Task OnGetPage(string extId,string subPage) - { - foreach(var item in Attributes) - { - if(item.Key.Id == extId) - { - return await item.Value.OnHandleRequest(subPage); - } - } - return new NotFoundResult(); - } + /// + /// Callbacks back to TimelapseUI + /// + /// public static Callbacks Callbacks {get;set;} - public static string UserData =Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),".TimelapseNow"); + /// + /// UserData + /// + /// TimelapseNow Folder for user + public static string UserData =Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"TimelapseNow"); + /// + /// UserExtensions + /// + /// Location for Extensions public static string UserExtensions = Path.Combine(UserData,"Extensions"); + /// + /// Global Data for app + /// + /// Timelapse Folder for all users public static string GlobalData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),"TimelapseNow"); + /// + /// GlobalExtensions + /// + /// Location for extensions for all users public static string GlobalExtensions = Path.Combine(GlobalData,"Extensions"); + /// + /// Dont call this + /// public static void EnumerateExtensions() { TimelapseExtensions = new List(); @@ -89,6 +103,10 @@ namespace Timelapse.Api } } } + /// + /// Only call this to load extension manually + /// + /// path to dll public static void LoadDll(string dll) { Assembly asm=Assembly.LoadFrom(dll); @@ -113,10 +131,25 @@ namespace Timelapse.Api } Assemblies.Add(asm,dll); } + /// + /// Assemblies + /// + /// Dictionary of assembly,string public static Dictionary Assemblies {get;set;} + /// + /// Stores Attributes for extension + /// + /// returns timelapseExtension based on attribute public static Dictionary Attributes {get;set;} + /// + /// List of extensions + /// + /// List of extensions public static List TimelapseExtensions {get;set;} - + /// + /// Dont call this (this gets called from The UI) + /// + public static async Task OnNewFrame(Image image) { foreach(var extension in TimelapseExtensions) @@ -124,6 +157,9 @@ namespace Timelapse.Api await extension.OnNewFrame(image); } } + /// + /// Dont call this (this gets called from The UI) + /// public static void OnLoadProject(TimelapseProject project) { foreach(var extension in TimelapseExtensions) @@ -131,6 +167,9 @@ namespace Timelapse.Api extension.OnLoadProject(project); } } + /// + /// Dont call this (this gets called from The UI) + /// public static void OnStopRecording() { foreach(var extension in TimelapseExtensions) @@ -138,6 +177,9 @@ namespace Timelapse.Api extension.OnStopRecording(); } } + /// + /// Dont call this (this gets called from The UI) + /// public static void OnStartRecording() { foreach(var extension in TimelapseExtensions) @@ -145,6 +187,9 @@ namespace Timelapse.Api extension.OnStartRecording(); } } + /// + /// Dont call this (this gets called from The UI) + /// public static void OnEnableOneX() { foreach(var extension in TimelapseExtensions) @@ -153,6 +198,9 @@ namespace Timelapse.Api extension.OnEnableOneX(); } } + /// + /// Dont call this (this gets called from The UI) + /// public static void OnDisableOneX() { foreach(var extension in TimelapseExtensions) diff --git a/Timelapse.Api/Extension.cs b/Timelapse.Api/Extension.cs index bbea473..9002ddb 100644 --- a/Timelapse.Api/Extension.cs +++ b/Timelapse.Api/Extension.cs @@ -9,41 +9,158 @@ using System.Net; namespace Timelapse.Api { - + public class ProjectUnloadedException : Exception + { + public ProjectUnloadedException() : base("Project not Loaded") + { + + } + } public abstract class TimelapseExtension { internal string __id; internal bool _recording; internal bool _onex; + /// + /// Recording bit + /// + /// Whether project is recording protected bool Recording {get {return _recording;}set{if(value){StartRecording();} else{StopRecording();}}} - protected bool OneX {get {return _onex;}set{if(value) {EnableOneX();} else {DisableOneX();} }} + /// + /// OneX bit + /// + /// Whether project is recording + protected bool OneX {get {return _onex;}set{if(value) {EnableOneX();} else {DisableOneX();} }} + /// + /// Called when Extension is Loaded + /// public abstract void OnInit(); + /// + /// Name of Extension (retreved from Attribute) + /// + /// The Name public string Name {get;internal set;} + /// + /// When a frame is taken by webcam and is about to be saved (async) + /// + /// a mutable SixLabors.ImageSharp object + /// Task but no data public virtual async Task OnNewFrame(Image frame) { } + /// + /// You could manipulate the project and detect project load + /// + /// TimelapseProject object public virtual void OnLoadProject(TimelapseProject project) { } - /// - ///URL for in html pages + + /// + /// Register Razor Component + /// + /// the url for the razor component + /// The type + public void RegisterComponentAsPage(string href) + { + Type typ= typeof(T); + Extensions._components.Add(GET_URL(href),typ); + } + /// + ///URL for in razor pages /// public string GET_URL(string href) { - return $"/api/Extension/GetExtensionPage?extId={WebUtility.UrlEncode(__id)}&subPage={WebUtility.UrlEncode(href)}"; + return $"/ExtensionPage/{WebUtility.UrlEncode(__id)}/{WebUtility.UrlEncode(href)}"; } + /// + /// Write Object (as json) + /// + /// Path to file (must use forward slash '/' and can start with '/' + /// whether you want to get project specific path + /// data to be writen to file + public void WriteObject(string key,object contents,bool project=false) + { + + WriteAllText(key,Newtonsoft.Json.JsonConvert.SerializeObject(contents),project); + } + /// + /// Read Object (as json) + /// + /// Path to file (must use forward slash '/' and can start with '/' + /// whether you want to get project specific path + /// object type + /// object filled with data + public T ReadObject(string key,bool project) + { + + return Newtonsoft.Json.JsonConvert.DeserializeObject(ReadAllText(key,project)); + } + /// + /// Write all text + /// + /// Path to file (must use forward slash '/' and can start with '/' + /// whether you want to get project specific path + /// data to be writen to file + + public void WriteAllText(string key,string contents,bool project=false) + { + string file=GetPath(key,project); + File.WriteAllText(file,contents); + } + /// + /// Read all text + /// + /// Path to file (must use forward slash '/' and can start with '/' + /// whether you want to get project specific path + /// file contents + public string ReadAllText(string key,bool project=false) + { + string file=GetPath(key,project); + + return File.ReadAllText(file); + } + /// + /// Get Path to data file for extension + /// + /// Path to file (must use forward slash '/' and can start with '/' + /// whether you want to get project specific path + /// Path to file + public string GetPath(string key,bool project=false) + { + string v = key.TrimStart('/'); + if(Path.DirectorySeparatorChar == '\\') + { + v = v.Replace('/','\\'); + } + if(project) + { + + return Path.Combine(GetExtensionProjectData(),v); + }else{ + return Path.Combine(GetExtensionData(),v); + } + } + /// + /// Get Project Specific Data for extension (Directory Path) + /// + /// Path protected string GetExtensionProjectData() { if(!Extensions.Callbacks.ProjectLoaded()) { - return null; + throw new ProjectUnloadedException(); } string p = Path.Combine(Extensions.Callbacks.GetProjectDirectoryLocation(),"ExtensionData",__id); Directory.CreateDirectory(p); return p; } + /// + /// Get Data for extension (Directory Path) + /// + /// Path protected string GetExtensionData() { @@ -51,45 +168,69 @@ namespace Timelapse.Api Directory.CreateDirectory(p); return p; } + /// + /// Project Loaded + /// + /// returns true if project is loaded otherwise false public bool IsProjectLoaded() { return Extensions.Callbacks.ProjectLoaded(); } + /// + /// Triggered when timelapse starts recording + /// public virtual void OnStartRecording() { } + /// + /// Triggered when timelapse stops recording + /// public virtual void OnStopRecording() { } + /// + /// Call this to start recording + /// protected void StartRecording() { Extensions.Callbacks.StartRecording(); } + /// + /// Call this to stop recording + /// protected void StopRecording() { Extensions.Callbacks.StopRecording(); } + /// + /// Call this to Enable OneX (interval of 1) + /// protected void EnableOneX() { Extensions.Callbacks.EnableOneX(); } + /// + /// Call this to Disable OneX (no longer the interval of 1) + /// protected void DisableOneX() { Extensions.Callbacks.DisableOneX(); } + /// + /// Triggered when timelapse starts onex mode + /// public virtual void OnEnableOneX() { } + /// + /// Triggered when timelapse exits onex mode + /// public virtual void OnDisableOneX() { } - public virtual async Task OnHandleRequest(string path) - { - return new NotFoundResult(); - } } } \ No newline at end of file diff --git a/Timelapse.Api/Project.cs b/Timelapse.Api/Project.cs index 5d14043..5235475 100644 --- a/Timelapse.Api/Project.cs +++ b/Timelapse.Api/Project.cs @@ -4,18 +4,40 @@ namespace Timelapse.Api { public class TimelapseProject { + /// + /// Estimated Video Length for project + /// + /// Video Length of project (guess) public TimeSpan EstimatedVideoLength {get;set;} + /// + /// Estimated length of project (time till complete) + /// + /// Length of project (guess) public TimeSpan EstimatedProjectLength {get;set;} - + /// + /// Estimated or Interval + /// + /// Estimated or Raw interval public bool Estimated {get;set;} /// /// Only if Estimated is false /// public TimeSpan Interval {get;set;} + /// + /// Width, Should not be changed after creation + /// + /// width public int Width {get;set;} + /// + /// Height, Should not be changed after creation + /// + /// height public int Height {get;set;} - // No Camera Needed + /// + /// Section of project + /// + /// name of section public string CurrentSection {get;set;} } diff --git a/Timelapse.Api/Timelapse.Api.csproj b/Timelapse.Api/Timelapse.Api.csproj index addb995..a74bcc2 100644 --- a/Timelapse.Api/Timelapse.Api.csproj +++ b/Timelapse.Api/Timelapse.Api.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net5.0 diff --git a/Timelapse/Controllers/ExtensionController.cs b/Timelapse/Controllers/ExtensionController.cs deleted file mode 100644 index a088983..0000000 --- a/Timelapse/Controllers/ExtensionController.cs +++ /dev/null @@ -1,40 +0,0 @@ - -using System; - -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Timelapse.Api; -using System.Text; -using System.Net.Http.Headers; -using System.Net.Http; -using System.IO; - -using System.Net; -using System.Text.RegularExpressions; -using System.Drawing; - -using System.Runtime.InteropServices; - -namespace Timelapse.Controllers -{ - [Route("api/[controller]")] - [ApiController] - - public class ExtensionController : ControllerBase - { - [HttpGet] - public async Task GetExtensionPage(string extId,string subPage) - { - return await Extensions.OnGetPage(WebUtility.UrlDecode(extId),WebUtility.UrlDecode(subPage)); - } - - } - -} - - - - diff --git a/Timelapse/Pages/Index.razor b/Timelapse/Pages/Index.razor index 725f679..6a2dfcb 100644 --- a/Timelapse/Pages/Index.razor +++ b/Timelapse/Pages/Index.razor @@ -15,6 +15,7 @@ @if(RecentFiles == null) { +

Loading...

}else{
    diff --git a/Timelapse/Startup.cs b/Timelapse/Startup.cs index cdd48eb..a01e3c0 100644 --- a/Timelapse/Startup.cs +++ b/Timelapse/Startup.cs @@ -62,6 +62,7 @@ namespace Timelapse endpoints.MapFallbackToPage("/_Host"); }); Electron.Tray.Show("/Assets/desktop.png"); + Electron.Menu.SetApplicationMenu(new ElectronNET.API.Entities.MenuItem[]{}); Task.Run(async () =>{ diff --git a/Timelapse/Timelapse.csproj b/Timelapse/Timelapse.csproj index 24d45a5..615cc19 100644 --- a/Timelapse/Timelapse.csproj +++ b/Timelapse/Timelapse.csproj @@ -16,7 +16,7 @@ - false + diff --git a/create.sh b/create.sh index a3ad92a..958b543 100755 --- a/create.sh +++ b/create.sh @@ -3,14 +3,14 @@ export ARCHITECTURE=amd64 cd Timelapse electronize build /target win /p:PublishReadyToRun=false electronize build /target osx /p:PublishReadyToRun=false -electronize build /target linux /p:PublishReadyToRun=false +electronize build /target linux rm -rf ../deb/usr/share/TimelapseNow/bin/ cp -r bin/Desktop/linux-unpacked/ ../deb/usr/share/TimelapseNow/bin/ echo "Package: timelapsenow" > ../deb/DEBIAN/control -echo "Version: 1.0" >> ../deb/DEBIAN/control +echo "Version: 1.0.1" >> ../deb/DEBIAN/control echo "Architecture: $ARCHITECTURE" >> ../deb/DEBIAN/control echo "Maintainer: Michael Nolan " >> ../deb/DEBIAN/control echo "Description: Record In Steps" >> ../deb/DEBIAN/control dpkg-deb --build --root-owner-group ../deb -mv ../deb.deb ../timelapsenow_1.0.1_$ARCHITECTURE.deb \ No newline at end of file +mv ../deb.deb ../timelapsenow_1.0.1_$ARCHITECTURE.deb diff --git a/deb/DEBIAN/control b/deb/DEBIAN/control index f9d2694..77d4d29 100644 --- a/deb/DEBIAN/control +++ b/deb/DEBIAN/control @@ -1,5 +1,5 @@ Package: timelapsenow -Version: 1.0 +Version: 1.0.0 Architecture: amd64 Maintainer: Michael Nolan Description: Record In Steps