Skip to content

Commit

Permalink
Fix bug with launch closing not cancelling
Browse files Browse the repository at this point in the history
so apparently this is just a problem that has always existed lol
  • Loading branch information
pizzaboxer committed Aug 26, 2023
1 parent 1998425 commit 0cca373
Show file tree
Hide file tree
Showing 15 changed files with 415 additions and 194 deletions.
3 changes: 3 additions & 0 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ public void CancelInstall()
return;
}

if (_cancelFired)
return;

App.Logger.WriteLine(LOG_IDENT, "Cancelling install...");

_cancelTokenSource.Cancel();
Expand Down
17 changes: 14 additions & 3 deletions Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class WinFormsDialogBase : Form, IBootstrapperDialog
{
public Bloxstrap.Bootstrapper? Bootstrapper { get; set; }

private bool _isClosing;

#region UI Elements
protected virtual string _message { get; set; } = "Please wait...";
protected virtual ProgressBarStyle _progressStyle { get; set; }
Expand Down Expand Up @@ -81,21 +83,30 @@ public void SetupDialog()
Icon = App.Settings.Prop.BootstrapperIcon.GetIcon();
}

public void ButtonCancel_Click(object? sender, EventArgs e)
#region WinForms event handlers
public void ButtonCancel_Click(object? sender, EventArgs e) => Close();

public void Dialog_FormClosing(object sender, FormClosingEventArgs e)
{
Bootstrapper?.CancelInstall();
Close();
if (!_isClosing)
Bootstrapper?.CancelInstall();
}
#endregion

#region IBootstrapperDialog Methods
public void ShowBootstrapper() => ShowDialog();

public virtual void CloseBootstrapper()
{
if (InvokeRequired)
{
Invoke(CloseBootstrapper);
}
else
{
_isClosing = true;
Close();
}
}

public virtual void ShowSuccess(string message, Action? callback) => BaseFunctions.ShowSuccess(message, callback);
Expand Down
3 changes: 2 additions & 1 deletion Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
WindowStyle="None"
WindowStartupLocation="CenterScreen"
AllowsTransparency="True"
Background="Transparent">
Background="Transparent"
Closing="Window_Closing">
<Border CornerRadius="10" BorderBrush="#33393B3D" Background="{Binding Background}" BorderThickness="{Binding DialogBorder}">
<Grid>
<Image Source="{Binding ByfronLogoLocation}" Width="114" Height="108" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="17,13,0,0" />
Expand Down
14 changes: 13 additions & 1 deletion Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
Expand All @@ -17,6 +18,8 @@ public partial class ByfronDialog : IBootstrapperDialog

public Bloxstrap.Bootstrapper? Bootstrapper { get; set; }

private bool _isClosing;

#region UI Elements
public string Message
{
Expand Down Expand Up @@ -84,12 +87,21 @@ public ByfronDialog()

InitializeComponent();
}
private void Window_Closing(object sender, CancelEventArgs e)
{
if (!_isClosing)
Bootstrapper?.CancelInstall();
}

#region IBootstrapperDialog Methods
// Referencing FluentDialog
public void ShowBootstrapper() => this.ShowDialog();

public void CloseBootstrapper() => Dispatcher.BeginInvoke(this.Close);
public void CloseBootstrapper()
{
_isClosing = true;
Dispatcher.BeginInvoke(this.Close);
}

public void ShowSuccess(string message, Action? callback) => BaseFunctions.ShowSuccess(message, callback);
#endregion
Expand Down
3 changes: 2 additions & 1 deletion Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterScreen"
Closing="UiWindow_Closing">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down
18 changes: 15 additions & 3 deletions Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Forms;
using System.ComponentModel;
using System.Windows.Forms;

using Wpf.Ui.Appearance;
using Wpf.Ui.Mvvm.Contracts;
Expand All @@ -20,6 +21,8 @@ public partial class FluentDialog : IBootstrapperDialog

public Bloxstrap.Bootstrapper? Bootstrapper { get; set; }

private bool _isClosing;

#region UI Elements
public string Message
{
Expand Down Expand Up @@ -77,11 +80,20 @@ public FluentDialog()
InitializeComponent();
}

#region IBootstrapperDialog Methods
private void UiWindow_Closing(object sender, CancelEventArgs e)
{
if (!_isClosing)
Bootstrapper?.CancelInstall();
}

#region IBootstrapperDialog Methods
public void ShowBootstrapper() => this.ShowDialog();

public void CloseBootstrapper() => Dispatcher.BeginInvoke(this.Close);
public void CloseBootstrapper()
{
_isClosing = true;
Dispatcher.BeginInvoke(this.Close);
}

public void ShowSuccess(string message, Action? callback) => BaseFunctions.ShowSuccess(message, callback);
#endregion
Expand Down
86 changes: 43 additions & 43 deletions Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2008.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2008.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace Bloxstrap.UI.Elements.Bootstrapper

public partial class LegacyDialog2008 : WinFormsDialogBase
{
protected override string _message
{
get => labelMessage.Text;
set => labelMessage.Text = value;
protected override string _message
{
get => labelMessage.Text;
set => labelMessage.Text = value;
}

protected override ProgressBarStyle _progressStyle
Expand All @@ -27,10 +27,10 @@ protected override int _progressValue
set => ProgressBar.Value = value;
}

protected override bool _cancelEnabled
{
get => this.buttonCancel.Enabled;
set => this.buttonCancel.Enabled = value;
protected override bool _cancelEnabled
{
get => this.buttonCancel.Enabled;
set => this.buttonCancel.Enabled = value;
}

public LegacyDialog2008()
Expand Down
62 changes: 61 additions & 1 deletion Bloxstrap/UI/Elements/Bootstrapper/LegacyDialog2008.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down
Loading

0 comments on commit 0cca373

Please sign in to comment.