Skip to content

Commit

Permalink
Merge pull request #16 from xNetrunner/TrayFix
Browse files Browse the repository at this point in the history
Assert dispose on close window
  • Loading branch information
Netrunner authored May 2, 2023
2 parents 18cefdb + 5e37e15 commit be55d19
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
3 changes: 2 additions & 1 deletion App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:NWNLogRotator"
StartupUri="NWNLogRotator.xaml">
StartupUri="NWNLogRotator.xaml"
Exit="DisposeNotifyIcon">
<Application.Resources></Application.Resources>
</Application>
7 changes: 6 additions & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using NWNLogRotator.Classes;
using System.Windows;

namespace NWNLogRotator
{
Expand All @@ -7,5 +8,9 @@ namespace NWNLogRotator
/// </summary>
public partial class App : Application
{
public void DisposeNotifyIcon(object sender, ExitEventArgs e)
{
NWNLogRotator.MainWindow.ExitEvent();
}
}
}
31 changes: 25 additions & 6 deletions NWNLogRotator.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class MainWindow : Window
{
FileHandler FileHandlerInstance = new FileHandler();
Settings _settings;
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
static System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
Notification notification = new Notification();
private int ClientLauncherState = 0;
private string ProcessName = "nwmain";
Expand All @@ -37,6 +37,7 @@ public MainWindow()
if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1)
{
MessageBox.Show("There is already an instance of NWNLogRotator running!");
ExitEvent();
Process.GetCurrentProcess().Kill();
}
InitializeComponent();
Expand Down Expand Up @@ -244,7 +245,10 @@ private async void IterateNWN_Watcher(bool PreviousStatus)
else
{
if(_settings.CloseOnLogGenerated == true )
{
ExitEvent();
Process.GetCurrentProcess().Kill();
}
}

}
Expand Down Expand Up @@ -489,8 +493,11 @@ private bool NWNLog_Save(Settings _settings, bool _automatic)
}

if (_settings.SaveOnLaunch == false)
if (_automatic && _settings.CloseOnLogGenerated == true) Process.GetCurrentProcess().Kill();

if (_automatic && _settings.CloseOnLogGenerated == true)
{
ExitEvent();
Process.GetCurrentProcess().Kill();
}
if (_settings.Silent == false)
{
MessageBoxResult _messageBoxResult = MessageBox.Show("The log file has been generated successfully. Would you like to open the log file now?",
Expand All @@ -510,8 +517,12 @@ private bool NWNLog_Save(Settings _settings, bool _automatic)
}
else
{
if(_settings.SaveOnLaunch == false)
if (_automatic && _settings.CloseOnLogGenerated == true) Process.GetCurrentProcess().Kill();
if (_settings.SaveOnLaunch == false)
if (_automatic && _settings.CloseOnLogGenerated == true)
{
ExitEvent();
Process.GetCurrentProcess().Kill();
}
}

return false;
Expand Down Expand Up @@ -719,9 +730,17 @@ protected override void OnStateChanged(EventArgs e)
base.OnStateChanged(e);
}

private void WindowClosed_Event(object sender, CancelEventArgs e)
public void WindowClosed_Event(object sender, CancelEventArgs e)
{
ExitEvent();
}

public static void ExitEvent()
{
ni.Visible = false;
ni.Icon = null;
ni.Dispose();
System.Windows.Forms.Application.DoEvents();
}

/*
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.1")]
[assembly: AssemblyFileVersion("0.1.0.1")]
[assembly: AssemblyVersion("0.1.0.2")]
[assembly: AssemblyFileVersion("0.1.0.2")]

0 comments on commit be55d19

Please sign in to comment.