using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Windows; using System.Windows.Threading; namespace WarframeClock { /// /// Interaction logic for App.xaml /// public partial class App : Application { public static readonly string VersionString = "Warframe Clock Overlay 2019-07-20"; public static readonly string WebsiteUriString = "https://poepoe.org/warframe/clock/"; private static readonly bool DEBUG = false; public static readonly Uri WebsiteUri = new Uri(WebsiteUriString); public static readonly AppData AppData = new AppData(); private string _debugTracePath; private OverlayWindowViewModel _vm; private DispatcherTimer _updateTimer; private System.Windows.Forms.NotifyIcon _notifyIcon; protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); if (DEBUG) { _debugTracePath = Path.GetTempFileName(); Trace.Listeners.Add(new TextWriterTraceListener(File.Create(_debugTracePath))); } // Prepare ViewModel(?) and a timer updating it _vm = new OverlayWindowViewModel(); _updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Background, (_, __) => _vm.Refresh(), Dispatcher.CurrentDispatcher); _updateTimer.Start(); // Prepare System Tray icon var iconMenu = new System.Windows.Forms.ContextMenu(); iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem(App.VersionString) { Enabled = false }); iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Configure", (_, __) => new SettingsWindow(_vm).Show())); iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Quit", (_, __) => ((App)Application.Current).Terminate())); _notifyIcon = new System.Windows.Forms.NotifyIcon { ContextMenu = iconMenu, Icon = WarframeClock.Properties.Resources.TrayIcon, Text = $"Warframe Clock - {App.VersionString}", Visible = true }; _notifyIcon.Click += (_, __) => MainWindow.Show(); // Last, start the main window if (Settings.Standalone) new StandaloneOverlayWindow(_vm).Show(); else new OverlayWindow(_vm).Show(); } internal void Terminate() { _updateTimer.Stop(); MainWindow?.Close(); if (DEBUG) { Trace.Flush(); MessageBox.Show("Debug log file is located at: " + _debugTracePath); } } } }