mirror of
https://github.com/achiez/NebulaAuth-Steam-Desktop-Authenticator-by-Achies.git
synced 2026-07-25 14:24:32 +00:00
8ff960189e
- Update: Added "Copy Password" to Mafile context menu (if available) - Update: "Save Password" now pre-fills the current password in the "Login Again" dialog when encryption is enabled - Fix: Prevented overlapping confirmation cycles in AutoConfirmer - Fix: Added a Snackbar notification when a confirmation cycle is skipped due to a too frequent timer interval - Fix: Fixed a rare bug where the previous proxy was used instead of the current one during session refresh - Fix: Corrected "Session Permanently Expired" message showing on unrelated errors (e.g. network issues) - UI-Fix: Fixed visual glitch where proxy input appeared non-empty when switching to a mafile-specific proxy - Cleanup: Refactored and cleaned up codebase, improved styling and formatting via ReSharper
83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Drawing;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
using NebulaAuth.Model;
|
|
using Application = System.Windows.Application;
|
|
|
|
namespace NebulaAuth.Core;
|
|
|
|
public static class TrayManager
|
|
{
|
|
private static NotifyIcon? _notifyIcon;
|
|
private static readonly Window MainWindow = Application.Current.MainWindow!;
|
|
private static bool IsEnabled => Settings.Instance.HideToTray;
|
|
|
|
[MemberNotNullWhen(true, nameof(_notifyIcon))]
|
|
private static bool Init { get; set; }
|
|
|
|
public static void InitializeTray()
|
|
{
|
|
_notifyIcon = new NotifyIcon();
|
|
_notifyIcon.Text = "NebulaAuth";
|
|
|
|
var iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/Theme/lock.ico"))!.Stream;
|
|
_notifyIcon.Icon = new Icon(iconStream);
|
|
|
|
_notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
|
|
|
|
var contextMenu = new ContextMenuStrip();
|
|
|
|
contextMenu.Items.Add("Выйти", null!, OnExitClick);
|
|
|
|
_notifyIcon.ContextMenuStrip = contextMenu;
|
|
|
|
MainWindow.StateChanged += MainWindow_StateChanged;
|
|
Init = true;
|
|
}
|
|
|
|
private static void OnExitClick(object? sender, EventArgs e)
|
|
{
|
|
ExitApplication();
|
|
}
|
|
|
|
private static void NotifyIcon_MouseDoubleClick(object? sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
ShowMainWindow();
|
|
}
|
|
}
|
|
|
|
private static void MainWindow_StateChanged(object? sender, EventArgs e)
|
|
{
|
|
if (MainWindow.WindowState == WindowState.Minimized)
|
|
{
|
|
HideMainWindow();
|
|
}
|
|
}
|
|
|
|
private static void ShowMainWindow()
|
|
{
|
|
if (!Init) return;
|
|
MainWindow.Show();
|
|
MainWindow.WindowState = WindowState.Normal;
|
|
_notifyIcon.Visible = false;
|
|
}
|
|
|
|
private static void HideMainWindow()
|
|
{
|
|
if (!Init) return;
|
|
if (IsEnabled == false) return;
|
|
_notifyIcon.Visible = true;
|
|
MainWindow.Hide();
|
|
}
|
|
|
|
private static void ExitApplication()
|
|
{
|
|
if (!Init) return;
|
|
_notifyIcon.Dispose();
|
|
Application.Current.Shutdown();
|
|
}
|
|
} |