예제 #1
0
        private Settings(Toast toast)
        {
            Telemetry.TrackEvent(TelemetryCategory.General, Telemetry.TelemetryEvent.SettingsLaunched);

            this.settings = SettingsXml.Current.Clone();
            this.toast    = toast;

            InitializeComponent();

            //Data context initialisation
            GeneralGrid.DataContext = this.settings;

            //Slider initialisation
            try
            {
                slTopColor.Value    = byte.Parse(settings.ToastColorTop.Substring(1, 2), NumberStyles.AllowHexSpecifier);
                slBottomColor.Value = byte.Parse(settings.ToastColorBottom.Substring(1, 2), NumberStyles.AllowHexSpecifier);
                slBorderColor.Value = byte.Parse(settings.ToastBorderColor.Substring(1, 2), NumberStyles.AllowHexSpecifier);
            }
            catch { }

            if (_current == null)
            {
                _current = this;
            }
        }
예제 #2
0
        private void FadeIn(bool force = false)
        {
            SettingsXml settings = SettingsXml.Current;

            if ((settings.DisableToast || settings.OnlyShowToastOnHotkey) && !force)
            {
                return;
            }

            if (coverUrl != "")
            {
                cover = new BitmapImage();
                cover.BeginInit();
                cover.UriSource = new Uri(coverUrl, UriKind.RelativeOrAbsolute);
                cover.EndInit();
                LogoToast.Source = cover;
            }

            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 = workingArea.Right - this.ActualWidth - settings.OffsetRight;
            this.Top  = workingArea.Bottom - this.ActualHeight - settings.OffsetBottom;

            DoubleAnimation anim = new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(250));

            anim.Completed += (s, e) => { FadeOut(); };
            this.BeginAnimation(Window.OpacityProperty, anim);
        }
예제 #3
0
        private void FadeIn(bool force = false, bool isUpdate = false)
        {
            if (dragging)
            {
                return;
            }

            SettingsXml settings = SettingsXml.Current;

            if ((settings.DisableToast || settings.OnlyShowToastOnHotkey) && !force)
            {
                return;
            }

            LogoToast.Source = (BitmapImage)(new System.Windows.Media.ImageConverter().Convert(currentTrack.AlbumArt, null, null, null));

            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;
        }
예제 #4
0
        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;

            this.Left = settings.PositionLeft;
            this.Top  = settings.PositionTop;

            ResetPositionIfOffScreen();

            DoubleAnimation anim = new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(250));
            anim.Completed += (s, e) => { FadeOut(); };
            this.BeginAnimation(Window.OpacityProperty, anim);

            this.Topmost = true;
        }
예제 #5
0
        public SettingsXml Clone()
        {
            SettingsXml clone = MemberwiseClone() as SettingsXml;

            clone.HotKeys = new List <Hotkey>();

            foreach (Hotkey key in HotKeys)
            {
                clone.HotKeys.Add(key.Clone());
            }

            return(clone);
        }
예제 #6
0
        private void Window_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (dragging)
            {
                dragging = false;

                // save the new window position
                SettingsXml settings = SettingsXml.Current;

                settings.PositionLeft = this.Left;
                settings.PositionTop  = this.Top;

                settings.Save();
            }
        }
예제 #7
0
        private void AskUserToStartSpotify()
        {
            SettingsXml settings = SettingsXml.Current;

            // Thanks to recent changes in Spotify that removed the song Artist + Title from the titlebar
            // we are forced to launch Spotify ourselves (under WebDriver), so we no longer ask the user
            try
            {
                Spotify.StartSpotify();
            }
            catch (Exception e)
            {
                MessageBox.Show("An unknown error occurred when trying to start Spotify.\nPlease start Spotify manually.\n\nTechnical Details: " + e.Message, "Toastify", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
예제 #8
0
        public Settings(Toast toast)
        {
            this.settings = SettingsXml.Current.Clone();
            this.toast    = toast;

            InitializeComponent();

            //Data context initialisation
            GeneralGrid.DataContext = this.settings;

            //Slider initialisation
            slTopColor.Value    = byte.Parse(settings.ToastColorTop.Substring(1, 2), NumberStyles.AllowHexSpecifier);
            slBottomColor.Value = byte.Parse(settings.ToastColorBottom.Substring(1, 2), NumberStyles.AllowHexSpecifier);
            slBorderColor.Value = byte.Parse(settings.ToastBorderColor.Substring(1, 2), NumberStyles.AllowHexSpecifier);
        }
예제 #9
0
        private void EnsureSpotify()
        {
            SettingsXml settings = SettingsXml.Current;

            //Make sure Spotify is running when starting Toastify.
            //If not ask the user and try to start it.

            if (!Spotify.IsAvailable())
            {
                if ((settings.AlwaysStartSpotify.HasValue && settings.AlwaysStartSpotify.Value) || (MessageBox.Show("Spotify doesn't seem to be running.\n\nDo you want Toastify to try and start it for you?", "Toastify", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes))
                {
                    string spotifyPath = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Spotify", string.Empty, string.Empty) as string;  //string.Empty = (Default) value

                    // try in the secondary location
                    if (string.IsNullOrEmpty(spotifyPath))
                    {
                        spotifyPath = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Spotify", "InstallLocation", string.Empty) as string;  //string.Empty = (Default) value
                    }

                    if (string.IsNullOrEmpty(spotifyPath))
                    {
                        MessageBox.Show("Unable to find Spotify. Make sure it is installed and/or start it manually.", "Toastify", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        try
                        {
                            System.Diagnostics.Process.Start(System.IO.Path.Combine(spotifyPath, "Spotify.exe"));

                            if (!settings.AlwaysStartSpotify.HasValue)
                            {
                                var ret = MessageBox.Show("Do you always want to start Spotify if it's not already running?", "Toastify", MessageBoxButton.YesNo, MessageBoxImage.Question);
                                settings.AlwaysStartSpotify = (ret == MessageBoxResult.Yes);
                                settings.Save();
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("An unknown error occurd when trying to start Spotify.\nPlease start Spotify manually.", "Toastify", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                }
            }
        }
예제 #10
0
        public SettingsXml Load()
        {
            if (!System.IO.File.Exists(SettingsFile))
            {
                SettingsXml.Current.Default();
                SettingsXml.Current.Save();
            }
            else
            {
                using (StreamReader sr = new StreamReader(SettingsFile))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(SettingsXml));
                    SettingsXml   xml           = xmlSerializer.Deserialize(sr) as SettingsXml;

                    Current = xml;
                }
            }

            return(Current);
        }
예제 #11
0
        public void InitToast()
        {
            const double MIN_WIDTH  = 200.0;
            const double MIN_HEIGHT = 65.0;

            //If we find any invalid settings in the xml we skip it and use default.
            //User notification of bad settings will be implemented with the settings dialog.

            //This method is UGLY but we'll keep it until the settings dialog is implemented.
            SettingsXml settings = SettingsXml.Current;

            ToastBorder.BorderThickness = new Thickness(settings.ToastBorderThickness);

            ColorConverter cc = new ColorConverter();

            if (!string.IsNullOrEmpty(settings.ToastBorderColor) && cc.IsValid(settings.ToastBorderColor))
            {
                ToastBorder.BorderBrush = new SolidColorBrush((Color)cc.ConvertFrom(settings.ToastBorderColor));
            }

            if (!string.IsNullOrEmpty(settings.ToastColorTop) && !string.IsNullOrEmpty(settings.ToastColorBottom) && cc.IsValid(settings.ToastColorTop) && cc.IsValid(settings.ToastColorBottom))
            {
                Color top    = (Color)cc.ConvertFrom(settings.ToastColorTop);
                Color botton = (Color)cc.ConvertFrom(settings.ToastColorBottom);

                ToastBorder.Background = new LinearGradientBrush(top, botton, 90.0);
            }

            if (settings.ToastWidth >= MIN_WIDTH)
            {
                this.Width = settings.ToastWidth;
            }
            if (settings.ToastHeight >= MIN_HEIGHT)
            {
                this.Height = settings.ToastHeight;
            }

            //If we made it this far we have all the values needed.
            ToastBorder.CornerRadius = new CornerRadius(settings.ToastBorderCornerRadiusTopLeft, settings.ToastBorderCornerRadiusTopRight, settings.ToastBorderCornerRadiusBottomRight, settings.ToastBorderCornerRadiusBottomLeft);
        }
예제 #12
0
        public SettingsXml Load()
        {
            if (!System.IO.File.Exists(SettingsFile))
            {
                SettingsXml.Current.Default(setHotKeys: true);
                SettingsXml.Current.Save();
            }
            else
            {
                using (StreamReader sr = new StreamReader(SettingsFile))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(SettingsXml));
                    SettingsXml   xml           = xmlSerializer.Deserialize(sr) as SettingsXml;

                    xml.CheckForNewSettings();

                    Current = xml;
                }
            }

            Current.SanitizeSettingsFile();

            return(Current);
        }