public MainWindow() { InitializeComponent(); // Prevent multiple instances _mutex = new Mutex(true, Properties.Resources.AppName, out bool createdNew); if (!createdNew) { System.Windows.MessageBox.Show( System.Windows.Application.Current.MainWindow, "This application is already running!", Properties.Resources.AppName, MessageBoxButton.OK, MessageBoxImage.Information ); System.Windows.Application.Current.Shutdown(); } // Tray icon var icon = Properties.Resources.Icon.Clone() as System.Drawing.Icon; _notifyIcon = new System.Windows.Forms.NotifyIcon(); _notifyIcon.Click += NotifyIcon_Click; _notifyIcon.Text = $"Click to show the {Properties.Resources.AppName} window"; _notifyIcon.Icon = icon; _notifyIcon.Visible = true; Title = Properties.Resources.AppName; LoadSettings(); #if DEBUG Label_Version.Content = $"{Properties.Resources.Version}d"; #else Label_Version.Content = Properties.Resources.Version; #endif // Controller _controller = new MainController((status, state) => { Dispatcher.Invoke(() => { switch (status) { case SuperServer.ServerStatus.Connected: label_ServerStatus.Background = Brushes.OliveDrab; label_ServerStatus.Content = "Connected"; break; case SuperServer.ServerStatus.Disconnected: label_ServerStatus.Background = Brushes.Tomato; label_ServerStatus.Content = "Disconnected"; break; case SuperServer.ServerStatus.Error: label_ServerStatus.Background = Brushes.Gray; label_ServerStatus.Content = "Error"; break; } }); }, (status) => { Dispatcher.Invoke(() => { if (status) { label_OpenVRStatus.Background = Brushes.OliveDrab; label_OpenVRStatus.Content = "Connected"; } else { label_OpenVRStatus.Background = Brushes.Tomato; label_OpenVRStatus.Content = "Disconnected"; if (_settings.ExitWithSteam) { _controller.Shutdown(); if (_notifyIcon != null) { _notifyIcon.Dispose(); } System.Windows.Application.Current.Shutdown(); } } }); } ); if (_settings.LaunchMinimized) { Hide(); WindowState = WindowState.Minimized; ShowInTaskbar = !_settings.Tray; } _controller.SetPort(_settings.Port); }