-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.axaml.cs
More file actions
99 lines (80 loc) · 3.12 KB
/
Copy pathMainWindow.axaml.cs
File metadata and controls
99 lines (80 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using SerialVolumeControl.Services;
namespace SerialVolumeControl
{
/// <summary>
/// Represents the main window of the SerialVolumeControl application.
/// Manages the user interface, serial communication, settings, and UI interactions.
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// The list of ComboBoxes for application selection per slider.
/// </summary>
private readonly List<ComboBox> _appComboBoxes = new();
/// <summary>
/// The list of sliders that control volume levels.
/// </summary>
private readonly List<Slider> _volumeSliders = new();
/// <summary>
/// Maps each slider index to its assigned application.
/// </summary>
private readonly Dictionary<int, string?> _sliderAppAssignments = new();
/// <summary>
/// Serial reader instance for handling communication with the hardware.
/// </summary>
private readonly SerialReader _reader = new();
/// <summary>
/// Stores saved volume levels for each application.
/// </summary>
private Dictionary<string, float> _savedAppVolumes = new();
/// <summary>
/// The last used COM port.
/// </summary>
private string? _lastComPort;
/// <summary>
/// Stores assignments for each slider from previous sessions.
/// </summary>
private List<string?> _sliderAppAssignmentsList = new() { null, null, null, null, null };
/// <summary>
/// Reference to the UI toggle button for switching between light and dark themes.
/// </summary>
private ToggleButton? _themeToggle;
/// <summary>
/// Indicates whether the current theme is dark mode.
/// </summary>
private bool _isDarkMode = false;
/// <summary>
/// The system tray icon for the application.
/// </summary>
private TrayIcon? _trayIcon;
/// <summary>
/// The context menu associated with the system tray icon.
/// </summary>
private NativeMenu? _trayMenu;
/// <summary>
/// Indicates whether an exit request has been made (used to prevent redundant actions on shutdown).
/// </summary>
private bool _isExitRequested = false;
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// Sets up the UI, loads saved settings, initializes controls and hardware communication.
/// </summary>
public MainWindow()
{
InitializeComponent();
LoadSettings();
_themeToggle = this.FindControl<ToggleButton>("ThemeToggleButton");
InitializeComboBoxesAndSliders();
InitializePortControls();
InitializeDropdowns();
InitializeSliderAssignments();
InitializeSerialReader();
SetupThemeToggle();
SetTheme(_isDarkMode);
SetupTrayIcon();
}
}
}