예제 #1
0
        public static void StartSpotify()
        {
            if (IsRunning())
            {
                return;
            }

            // spotify installs a protocol handler, "spotify:", use that to launch spotify

            Process.Start("spotify:");

            if (SettingsXml.Current.MinimizeSpotifyOnStartup)
            {
                Minimize();
            }
            else
            {
                // we need to let Spotify start up before interacting with it fully. 2 seconds is a relatively
                // safe amount of time to wait, even if the pattern is gross. (Minimize() doesn't need it since
                // it waits for the Window to appear before minimizing)
                var remainingSleep = 2000;

                while (Spotify.GetSpotify() == IntPtr.Zero && remainingSleep > 0)
                {
                    Thread.Sleep(100);
                    remainingSleep -= 100;
                }
            }
        }
예제 #2
0
        private static void ShowSpotify()
        {
            if (Spotify.IsRunning())
            {
                var hWnd = Spotify.GetSpotify();

                // check Spotify's current window state
                var placement = new Win32.WINDOWPLACEMENT();
                Win32.GetWindowPlacement(hWnd, ref placement);

                int showCommand = Win32.Constants.SW_SHOW;

                // if Spotify is minimzed we need to send a restore so that the window
                // will come back exactly like it was before being minimized (i.e. maximized
                // or otherwise) otherwise if we call SW_RESTORE on a currently maximized window
                // then instead of staying maximized it will return to normal size.
                if (placement.showCmd == Win32.Constants.SW_SHOWMINIMIZED)
                {
                    showCommand = Win32.Constants.SW_RESTORE;
                }

                Win32.ShowWindow(hWnd, showCommand);

                Win32.SetForegroundWindow(hWnd);
                Win32.SetFocus(hWnd);
            }
        }
예제 #3
0
 private static void ShowSpotify()
 {
     if (Spotify.IsAvailable())
     {
         Win32.ShowWindow(Spotify.GetSpotify(), 1);
         Win32.SetForegroundWindow(Spotify.GetSpotify());
         Win32.SetFocus(Spotify.GetSpotify());
     }
 }
예제 #4
0
        private static void ShowSpotifyWithNoActivate()
        {
            var hWnd = Spotify.GetSpotify();

            // check Spotify's current window state
            var placement = new Win32.WINDOWPLACEMENT();

            Win32.GetWindowPlacement(hWnd, ref placement);

            var flags = Win32.SetWindowPosFlags.DoNotActivate | Win32.SetWindowPosFlags.DoNotChangeOwnerZOrder | Win32.SetWindowPosFlags.ShowWindow;

            Win32.SetWindowPos(hWnd, (IntPtr)0, placement.rcNormalPosition.Left, placement.rcNormalPosition.Top, 0, 0, flags);
        }
예제 #5
0
        private static bool IsMinimized()
        {
            if (!Spotify.IsRunning())
            {
                return(false);
            }

            var hWnd = Spotify.GetSpotify();

            // check Spotify's current window state
            var placement = new Win32.WINDOWPLACEMENT();

            Win32.GetWindowPlacement(hWnd, ref placement);

            return(placement.showCmd == Win32.Constants.SW_SHOWMINIMIZED);
        }
예제 #6
0
        private static void Minimize()
        {
            var remainingSleep = 2000;

            IntPtr hWnd;

            // Since Minimize is often called during startup, the hWnd is often not created yet
            // wait a maximum of remainingSleep for it to appear and then minimize it if it did.
            while ((hWnd = Spotify.GetSpotify()) == IntPtr.Zero && remainingSleep > 0)
            {
                Thread.Sleep(100);
                remainingSleep -= 100;
            }

            if (hWnd != IntPtr.Zero)
            {
                // disgusting but sadly neccessary. Let Spotify initialize a bit before minimizing it
                // otherwise the window hides itself and doesn't respond to taskbar clicks.
                // I tried to work around this by waiting for the window size to initialize (via GetWindowRect)
                // but that didn't work, there is some internal initialization that needs to occur.
                Thread.Sleep(500);
                Win32.ShowWindow(hWnd, Win32.Constants.SW_SHOWMINIMIZED);
            }
        }
예제 #7
0
파일: Spotify.cs 프로젝트: xorguy/Toastify
        private static void Minimize()
        {
            var hWnd = Spotify.GetSpotify();

            Win32.ShowWindow(hWnd, Win32.Constants.SW_SHOWMINIMIZED);
        }