private void Window_Loaded(object sender, RoutedEventArgs e) { //Load settings from XML LoadSettings(); //Init toast(color settings) InitToast(); //Init tray icon trayIcon = new System.Windows.Forms.NotifyIcon(); trayIcon.Icon = SOVND.Client.Properties.Resources.SOVND; trayIcon.Text = "SOVND"; trayIcon.Visible = true; trayIcon.ContextMenu = new System.Windows.Forms.ContextMenu(); //Init tray icon menu System.Windows.Forms.MenuItem menuSettings = new System.Windows.Forms.MenuItem(); menuSettings.Text = "Settings"; menuSettings.Click += (s, ev) => { Settings.Launch(this); }; //trayIcon.ContextMenu.MenuItems.Add(menuSettings); //trayIcon.ContextMenu.MenuItems.Add("-"); System.Windows.Forms.MenuItem menuExit = new System.Windows.Forms.MenuItem(); menuExit.Text = "Exit"; menuExit.Click += (s, ev) => { Application.Current.Shutdown(); }; //this.Close(); }; trayIcon.ContextMenu.MenuItems.Add(menuExit); //trayIcon.MouseClick += (s, ev) => { if (ev.Button == System.Windows.Forms.MouseButtons.Left) DisplayAction(SpotifyAction.ShowToast, null); }; //trayIcon.DoubleClick += (s, ev) => { Settings.Launch(this); }; this.Deactivated += Toast_Deactivated; //Remove from ALT+TAB WinHelper.AddToolWindowStyle(this); }
private void Window_Loaded(object sender, RoutedEventArgs e) { //Load settings from XML LoadSettings(); string version = VersionChecker.Version; Telemetry.TrackEvent(TelemetryCategory.General, Telemetry.TelemetryEvent.AppLaunch, version); if (SettingsXml.Current.PreviousOS != version) { Telemetry.TrackEvent(TelemetryCategory.General, Telemetry.TelemetryEvent.AppUpgraded, version); SettingsXml.Current.PreviousOS = version; } //Init toast(color settings) InitToast(); //Init tray icon trayIcon = new System.Windows.Forms.NotifyIcon(); trayIcon.Icon = Toastify.Properties.Resources.spotifyicon; trayIcon.Text = "Toastify"; trayIcon.Visible = true; trayIcon.ContextMenu = new System.Windows.Forms.ContextMenu(); //Init tray icon menu System.Windows.Forms.MenuItem menuSettings = new System.Windows.Forms.MenuItem(); menuSettings.Text = "Settings"; menuSettings.Click += (s, ev) => { Settings.Launch(this); }; trayIcon.ContextMenu.MenuItems.Add(menuSettings); System.Windows.Forms.MenuItem menuAbout = new System.Windows.Forms.MenuItem(); menuAbout.Text = "About Toastify..."; menuAbout.Click += (s, ev) => { new About().ShowDialog(); }; trayIcon.ContextMenu.MenuItems.Add(menuAbout); trayIcon.ContextMenu.MenuItems.Add("-"); System.Windows.Forms.MenuItem menuExit = new System.Windows.Forms.MenuItem(); menuExit.Text = "Exit"; menuExit.Click += (s, ev) => { Application.Current.Shutdown(); }; //this.Close(); }; trayIcon.ContextMenu.MenuItems.Add(menuExit); trayIcon.MouseClick += (s, ev) => { if (ev.Button == System.Windows.Forms.MouseButtons.Left) { DisplayAction(SpotifyAction.ShowToast, null); } }; trayIcon.DoubleClick += (s, ev) => { Settings.Launch(this); }; //Init watch timer watchTimer = new Timer(1000); watchTimer.Elapsed += (s, ev) => { watchTimer.Stop(); CheckTitle(); watchTimer.Start(); }; this.Deactivated += Toast_Deactivated; //Remove from ALT+TAB WinHelper.AddToolWindowStyle(this); //Check if Spotify is running. AskUserToStartSpotify(); LoadPlugins(); //Let the plugins know we're started. foreach (var p in this.Plugins) { try { p.Started(); } catch (Exception) { //For now we swallow any plugin errors. } } if (!SettingsXml.Current.DisableToast) { watchTimer.Enabled = true; //Only need to be enabled if we are going to show the toast. } versionChecker = new VersionChecker(); versionChecker.CheckVersionComplete += new EventHandler <CheckVersionCompleteEventArgs>(versionChecker_CheckVersionComplete); versionChecker.BeginCheckVersion(); // TODO: right now this is pretty dumb - kick off update notifications every X hours, this might get annoying // and really we should just pop a notification once per version and probably immediately after a song toast var updateTimer = new System.Windows.Threading.DispatcherTimer(); updateTimer.Tick += (timerSender, timerE) => { versionChecker.BeginCheckVersion(); }; updateTimer.Interval = new TimeSpan(6, 0, 0); updateTimer.Start(); }
private void FadeIn(bool force = false, bool isUpdate = false) { if (minimizeTimer != null) { minimizeTimer.Stop(); } if (dragging) { return; } SettingsXml settings = SettingsXml.Current; // this is a convenient place to reset the idle timer (if so asked) // as this will be triggered when a song is played. The primary problem is if there is a // particularly long song then this will not work. That said, this is the safest (in terms of // not causing a user's computer from never sleeping). if (settings.PreventSleepWhilePlaying) { #if DEBUG var rv = #endif WinHelper.SetThreadExecutionState(WinHelper.EXECUTION_STATE.ES_SYSTEM_REQUIRED); #if DEBUG System.Diagnostics.Debug.WriteLine("** SetThreadExecutionState returned: " + rv); #endif } if ((settings.DisableToast || settings.OnlyShowToastOnHotkey) && !force) { return; } isUpdateToast = isUpdate; if (!string.IsNullOrEmpty(toastIcon)) { cover = new BitmapImage(); cover.BeginInit(); cover.UriSource = new Uri(toastIcon, UriKind.RelativeOrAbsolute); cover.EndInit(); LogoToast.Source = cover; } this.WindowState = WindowState.Normal; System.Drawing.Rectangle workingArea = new System.Drawing.Rectangle((int)this.Left, (int)this.Height, (int)this.ActualWidth, (int)this.ActualHeight); workingArea = System.Windows.Forms.Screen.GetWorkingArea(workingArea); this.Left = settings.PositionLeft; this.Top = settings.PositionTop; ResetPositionIfOffScreen(workingArea); DoubleAnimation anim = new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(250)); anim.Completed += (s, e) => { FadeOut(); }; this.BeginAnimation(Window.OpacityProperty, anim); this.Topmost = true; }