Skip to content

Commit

Permalink
Handle git errors more gracefully in the same way base s&box does
Browse files Browse the repository at this point in the history
  • Loading branch information
xezno committed Nov 28, 2022
1 parent d0b7206 commit 05e736f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
68 changes: 68 additions & 0 deletions code/PopupWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;

namespace Tools;

public class PopupWindow : BaseWindow
{
Label Label;

public PopupWindow( string title, string text, string buttonTxt = "OK", IDictionary<string, Action> extraButtons = null )
{
//FixedWidth = 500;
//FixedHeight = 150;

SetWindowIcon( "info" );

WindowTitle = title;

AdjustSize();

SetModal( true, true );

SetLayout( LayoutMode.TopToBottom );
Layout.Margin = 24;
Layout.Spacing = 24;

Label = new Label( this );
Label.Text = text;
Layout.Add( Label );

var okButton = new Button( this );
okButton.Text = buttonTxt;
okButton.MinimumWidth = 64;
okButton.MouseLeftPress += () => this.Destroy();
okButton.AdjustSize();

var buttonLayout = Layout.Row( true );
buttonLayout.Spacing = 5;
Layout.Add( buttonLayout );
buttonLayout.Add( okButton );

if ( extraButtons != null )
{
foreach ( var KVs in extraButtons )
{
var customBtn = new Button( this );
customBtn.Text = KVs.Key;
customBtn.MinimumWidth = 64;
customBtn.MouseLeftPress += KVs.Value;
customBtn.MouseLeftPress += () => this.Destroy();
customBtn.AdjustSize();

buttonLayout.Add( customBtn );
}
}

buttonLayout.AddStretchCell();
}

protected override void OnPaint()
{
base.OnPaint();

Paint.ClearPen();
Paint.SetBrush( Theme.WidgetBackground );
Paint.DrawRect( LocalRect, 0.0f );
}
}
18 changes: 16 additions & 2 deletions code/Utils/GitUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Tools;
Expand All @@ -21,7 +23,19 @@ public static async Task Git( string command, string workingDir = null )

var process = new Process();
process.StartInfo = info;
process.Start();

try
{
process.Start();
}
catch ( Exception e )
{
var test = new PopupWindow( "Error executing git command!",
$"Failed to initialize git, do you have it installed?\n\nThe error was:\n{e.Message}", "OK",
new Dictionary<string, Action>() { { "Open download link", () => Utility.OpenFolder( "https://git-scm.com/" ) } } );
test.Show();
return;
}

await process.WaitForExitAsync();
}
Expand Down

0 comments on commit 05e736f

Please sign in to comment.