diff --git a/code/AddToolDialog.cs b/code/AddToolDialog.cs index 3745947..59504e3 100644 --- a/code/AddToolDialog.cs +++ b/code/AddToolDialog.cs @@ -123,6 +123,8 @@ private async Task DownloadTool() var configPath = System.IO.Path.Combine( folder, ".addon" ); Utility.Projects.TryAddFromFile( configPath ); } + + ToolsManager.Instance.Refresh(); } private void PaintAddonItem( VirtualWidget v ) diff --git a/code/ToolInfoPage.cs b/code/ToolInfoPage.cs index 14b050a..9a6209a 100644 --- a/code/ToolInfoPage.cs +++ b/code/ToolInfoPage.cs @@ -1,5 +1,6 @@ using Sandbox; using System.IO; +using System.Threading.Tasks; namespace Tools; @@ -23,6 +24,13 @@ public ToolInfoPage( LocalProject project, Widget parent = null, bool isDarkWind Layout.Spacing = 8; Layout.Margin = 24; + UpdateFromProject( project ); + } + + private void UpdateFromProject( LocalProject project ) + { + DestroyChildren(); + Project = project; Manifest = project.GetManifest(); @@ -52,13 +60,22 @@ private void AddManifestWidgets() Layout.AddSpacingCell( 8f ); - Layout.Add( new Label.Body( $"{Manifest.Description}" ) ); + Layout.Add( new Label( $"{Manifest.Description}" ) { WordWrap = true } ); // Installed release info - Layout.Add( new Subheading( $"{Manifest.ReleaseName}" ) ); - Layout.Add( new Label.Body( $"{Manifest.ReleaseDescription}" ) ); + { + var scroll = new ScrollArea( this ); + var canvas = new Widget( this ); + canvas.SetLayout( LayoutMode.TopToBottom ); - Layout.AddStretchCell(); + canvas.Layout.Add( new Subheading( $"{Manifest.ReleaseName}" ) ); + canvas.Layout.Add( new Label( $"{Manifest.ReleaseDescription}" ) { WordWrap = true } ); + canvas.Layout.AddStretchCell(); + + scroll.Canvas = canvas; + + Layout.Add( scroll ); + } // Update info (if available) if ( Manifest.CheckUpdateAvailable() ) @@ -68,12 +85,21 @@ private void AddManifestWidgets() group.Layout.Margin = 10; Layout.Add( group ); - group.Layout.Add( new Heading( "Update Available" ) ); - LatestReleaseName = group.Layout.Add( new Subheading( $"Loading..." ) ); - LatestReleaseBody = group.Layout.Add( new Label( $"Loading..." ) ); + { + group.Layout.Add( new Heading( "Update Available" ) ); - group.Layout.AddSpacingCell( 8f ); + var scroll = new ScrollArea( this ); + var canvas = new Widget( this ); + canvas.SetLayout( LayoutMode.TopToBottom ); + LatestReleaseName = canvas.Layout.Add( new Subheading( $"Loading..." ) ); + LatestReleaseBody = canvas.Layout.Add( new Label( $"Loading..." ) ); + + scroll.Canvas = canvas; + group.Layout.Add( scroll ); + } + + group.Layout.AddSpacingCell( 8f ); group.Layout.Add( new Button( "Download Update", "download" ) { Clicked = DownloadUpdate } ); } } @@ -83,22 +109,33 @@ private void AddManifestWidgets() /// private void DownloadUpdate() { - GithubApi.FetchLatestRelease( $"{Manifest.Repo}" ).ContinueWith( async t => - { - var release = t.Result ?? default; + var release = GithubApi.FetchLatestRelease( $"{Manifest.Repo}" ).Result; - var folder = Project.GetRootPath(); + var folder = Project.GetRootPath(); - Log.Trace( folder ); + Log.Trace( folder ); - await GitUtils.Git( $"reset --hard HEAD" ); - await GitUtils.Git( $"pull" ); - await GitUtils.Git( $"checkout \"{release.TagName}\" --force", folder ); + using var progress = Progress.Start( $"Updating {Project.Config.Title}" ); - // Update Manifest - Manifest.SetRelease( release ); - Manifest.WriteToFolder( folder ); - } ); + Progress.Update( "Removing local changes", 5, 100 ); + _ = GitUtils.Git( $"reset --hard HEAD" ); + _ = Task.Delay( 50 ); + + + Progress.Update( "Pulling remote changes", 25, 100 ); + _ = GitUtils.Git( $"pull" ); + _ = Task.Delay( 50 ); + + Progress.Update( "Checking out release...", 90, 100 ); + _ = GitUtils.Git( $"checkout \"{release.TagName}\" --force", folder ); + _ = Task.Delay( 50 ); + + // Update Manifest + Manifest.SetRelease( release ); + Manifest.WriteToFolder( folder ); + + // Refresh UI + UpdateFromProject( Project ); } /// diff --git a/code/ToolsManager.cs b/code/ToolsManager.cs index 79828a2..e1717a1 100644 --- a/code/ToolsManager.cs +++ b/code/ToolsManager.cs @@ -6,8 +6,12 @@ [Tool( "Tools Manager", "hardware", "Manages your tools." )] public class ToolsManager : BaseWindow { + public static ToolsManager Instance { get; set; } + public ToolsManager() { + Instance = this; + Size = new Vector2( 600, 400 ); MinimumSize = Size; WindowTitle = "Tools Manager"; @@ -16,6 +20,7 @@ public ToolsManager() WriteDummyManifest(); + SetLayout( LayoutMode.LeftToRight ); CreateUI(); Show(); } @@ -46,12 +51,15 @@ private void WriteDummyManifest() manifest.WriteToFile( manifestPath ); } - public void CreateUI() + public void Refresh() { - SetLayout( LayoutMode.LeftToRight ); - var layout = Layout; + DestroyChildren(); + CreateUI(); + } - var toolsList = layout.Add( new NavigationView( this ) ); + public void CreateUI() + { + var toolsList = Layout.Add( new NavigationView( this ) ); foreach ( var project in Utility.Projects.GetAll() ) { diff --git a/code/Utils/GitUtils.cs b/code/Utils/GitUtils.cs index b17a30b..29dfba4 100644 --- a/code/Utils/GitUtils.cs +++ b/code/Utils/GitUtils.cs @@ -14,7 +14,7 @@ public static async Task Git( string command, string workingDir = null ) ProcessStartInfo info = new( "git", command ); info.UseShellExecute = false; - info.CreateNoWindow = false; + info.CreateNoWindow = true; if ( workingDir != null ) info.WorkingDirectory = workingDir;