mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-19 09:01:32 +01:00
Add feedback to indicate that the application will automatically terminate (github issue #1).
This commit is contained in:
1 parent
49520eb2f6
commit
c5aa5efca4
5 files changed
+96
-5
No files matched your search
@@ -57,6 +57,8 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
public event System.EventHandler<ApplicationTerminateArgs> OnApplicationTerminate;
|
||||
|
||||
public ReadOnlyCollection<ConversionJob> ConvertionJobs
|
||||
{
|
||||
get;
|
||||
@@ -90,6 +92,11 @@ namespace FileConverter
|
||||
public void CancelAutoExit()
|
||||
{
|
||||
this.cancelAutoExit = true;
|
||||
|
||||
if (this.OnApplicationTerminate != null)
|
||||
{
|
||||
this.OnApplicationTerminate.Invoke(this, new ApplicationTerminateArgs(float.NaN));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
@@ -390,13 +397,33 @@ namespace FileConverter
|
||||
allConversionsSucceed &= this.conversionJobs[index].State == ConversionJob.ConversionState.Done;
|
||||
}
|
||||
|
||||
if (this.cancelAutoExit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (allConversionsSucceed)
|
||||
{
|
||||
System.Threading.Thread.Sleep((int)this.Settings.DurationBetweenEndOfConversionsAndApplicationExit * 1000);
|
||||
|
||||
if (this.cancelAutoExit)
|
||||
float remainingTime = this.Settings.DurationBetweenEndOfConversionsAndApplicationExit;
|
||||
while (remainingTime > 0f)
|
||||
{
|
||||
return;
|
||||
if (this.OnApplicationTerminate != null)
|
||||
{
|
||||
this.OnApplicationTerminate.Invoke(this, new ApplicationTerminateArgs(remainingTime));
|
||||
}
|
||||
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
remainingTime--;
|
||||
|
||||
if (this.cancelAutoExit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.OnApplicationTerminate != null)
|
||||
{
|
||||
this.OnApplicationTerminate.Invoke(this, new ApplicationTerminateArgs(remainingTime));
|
||||
}
|
||||
|
||||
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// <copyright file="ApplicationTerminateArgs.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
public class ApplicationTerminateArgs : System.EventArgs
|
||||
{
|
||||
public ApplicationTerminateArgs(float remainingTimeBeforeTermination)
|
||||
{
|
||||
this.RemainingTimeBeforeTermination = remainingTimeBeforeTermination;
|
||||
}
|
||||
|
||||
public float RemainingTimeBeforeTermination
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,7 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="ApplicationTerminateArgs.cs" />
|
||||
<Compile Include="Controls\EncodingQualitySliderControl.xaml.cs">
|
||||
<DependentUpon>EncodingQualitySliderControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -27,7 +27,10 @@
|
||||
<ColumnDefinition Width="100" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label x:Name="Title" Grid.Column="0" Content="Files to convert" VerticalAlignment="Top" Height="30" FontSize="16" FontWeight="Bold"/>
|
||||
<DockPanel Grid.Column="0">
|
||||
<Label Content="Files to convert" VerticalAlignment="Top" Height="30" FontSize="16" FontWeight="Bold"/>
|
||||
<Label Content="{Binding InformationMessage, ElementName=FileConverterMainWindow}" VerticalAlignment="Top" Height="30" FontSize="13.333" HorizontalAlignment="Right"/>
|
||||
</DockPanel>
|
||||
<Button x:Name="DiagnosticsButton" Grid.Column="1" Content="Logs" Margin="3,3" Click="DiagnosticsButton_OnClick"/>
|
||||
<Button x:Name="SettingsButton" Grid.Column="2" Content="Settings" Margin="3,3" Click="SettingsButton_OnClick"/>
|
||||
</Grid>
|
||||
|
||||
@@ -15,12 +15,16 @@ namespace FileConverter
|
||||
private SettingsWindow settingsWindow;
|
||||
private UpgradeWindow upgradeWindow;
|
||||
|
||||
private string informationMessage;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
Application application = Application.Current as Application;
|
||||
|
||||
application.OnApplicationTerminate += Application_OnApplicationTerminate;
|
||||
|
||||
this.ConverterJobsList.ItemsSource = application.ConvertionJobs;
|
||||
|
||||
if (application.HideMainWindow)
|
||||
@@ -42,6 +46,20 @@ namespace FileConverter
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public string InformationMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.informationMessage;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
this.informationMessage = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNewVersionReleased(UpgradeVersionDescription upgradeVersionDescription)
|
||||
{
|
||||
this.ShowUpgradeWindow();
|
||||
@@ -121,5 +139,29 @@ namespace FileConverter
|
||||
application?.CancelAutoExit();
|
||||
this.upgradeWindow.Show();
|
||||
}
|
||||
|
||||
private void Application_OnApplicationTerminate(object sender, ApplicationTerminateArgs eventArgs)
|
||||
{
|
||||
if (float.IsNaN(eventArgs.RemainingTimeBeforeTermination))
|
||||
{
|
||||
this.InformationMessage = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
int remaingingSeconds = (int)eventArgs.RemainingTimeBeforeTermination;
|
||||
|
||||
if (remaingingSeconds >= 2)
|
||||
{
|
||||
this.InformationMessage = string.Format("The application will automatically terminate in {0} seconds.", remaingingSeconds);
|
||||
}
|
||||
else if (remaingingSeconds == 1)
|
||||
{
|
||||
this.InformationMessage = string.Format("The application will automatically terminate in {0} second.", remaingingSeconds);
|
||||
}
|
||||
if (remaingingSeconds <= 0)
|
||||
{
|
||||
this.InformationMessage = string.Format("The application is terminating.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user