Skip to content

Commit

Permalink
Merge pull request #74 from GoodSign2017/fix-exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug authored Dec 18, 2023
2 parents 3ae8af8 + ed8c4a0 commit a00de79
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion SoftU2FDaemon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ private void SetupApplication()
}

_cancellation = new CancellationTokenSource();

_cancellation.Token.Register(() => {
_cancellation.Dispose();
if (_exitRequested) { Environment.Exit(0); }
});
}


Expand Down Expand Up @@ -142,6 +147,8 @@ private void ConfigureServices(IServiceCollection service)

#region System Tray Icon

private bool _exitRequested = false;

private void InitializeTrayIcon()
{
_trayMenu = new ContextMenu();
Expand All @@ -152,7 +159,10 @@ private void InitializeTrayIcon()

_trayMenu.Items.Add("Reset", null, OnResetClickedOnClick);
_trayMenu.Items.Add("-");
_trayMenu.Items.Add("Exit", null, (sender, args) => Application.Exit());
_trayMenu.Items.Add("Exit", null, (sender, args) => {
_exitRequested = true;
Application.Exit();
});

_trayIcon = new NotifyIcon
{
Expand All @@ -176,6 +186,13 @@ private void InitializeTrayIcon()
lastActiveWin = GetForegroundWindow();
};
_trayIcon.BalloonTipClosed += (sender, args) => _notificationOpen = false;

this.FormClosing += (sender, e) =>
{
// Hide and dispose the icon
_trayIcon.Visible = false;
_trayIcon.Dispose();
};
}

private void OnAutoStartClick(object sender, EventArgs e)
Expand Down

0 comments on commit a00de79

Please sign in to comment.