Beispiel #1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
            string title   = "Command4";

            // Show a message box to prove we were here
            //VsShellUtilities.ShowMessageBox(
            //    this.ServiceProvider,
            //    message,
            //    title,
            //    OLEMSGICON.OLEMSGICON_INFO,
            //    OLEMSGBUTTON.OLEMSGBUTTON_OK,
            //    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

            //Process process = Process.Start("Spotify.exe");
            //int id = process.Id;
            //Process tempProc = Process.GetProcessById(id);
            //this.Visible = false;
            //tempProc.WaitForExit();
            //this.Visible = true;

            //myOleCommand.Text = "Test.";

            Process[] retrevedProc = Process.GetProcessesByName("Spotify");
            Process   spotMain     = null;

            foreach (Process item in retrevedProc)
            {
                if (item.MainWindowTitle != "")
                {
                    spotMain = item;
                    break;
                }
            }

            if (spotMain != null)
            {
                WindowHelper.BringProcessToFront(spotMain);
            }
            else
            {
                Console.WriteLine("Spotify not running.");
                if (!SpotifyAPI.Local.SpotifyLocalAPI.IsSpotifyRunning())
                {
                    SpotifyAPI.Local.SpotifyLocalAPI.RunSpotify();
                    System.Threading.Thread.Sleep(300);
                    Command1Package.SpotifyConnect();
                    SpotClientRegisterTrackChange();
                    Command1Package.UpdateCommandsHiddenState();
                }
                else
                {
                    Console.WriteLine("Something went wrong..\n "
                                      + "Spotify seems to be running but cant focus.");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            //string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
            //string title = "Command1";

            string message = string.Format(CultureInfo.CurrentCulture, "Spotify is not running");
            string title   = "SpotifyRemote";

            if (!SpotifyAPI.Local.SpotifyLocalAPI.IsSpotifyRunning())
            {
#if SPOT_WARN_NOT_RUNNING
                VsShellUtilities.ShowMessageBox(
                    this.ServiceProvider,
                    message,
                    title,
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
#endif
                SpotifyAPI.Local.SpotifyLocalAPI.RunSpotify();
                System.Threading.Thread.Sleep(300);
                Command1Package.SpotifyConnect();
                Command4.gCommand4Instance.SpotClientRegisterTrackChange();
                Command1Package.UpdateCommandsHiddenState();
                return;
            }

            if (Command1Package.spotClient == null)
            {
#if DEBUG
                MessageBox.Show("spotClient is null.");
                System.Diagnostics.Debug.Assert(false);

                return;
#endif
            }

            //Play/Pause
            SpotifyAPI.Local.Models.StatusResponse sr;
            sr = Command1Package.spotClient.GetStatus();
            if (!sr.Playing)
            {
                Console.WriteLine("Spotify Play.");
                Command1Package.spotClient.Play();
            }
            else
            {
                Console.WriteLine("Spotify Pause.");
                Command1Package.spotClient.Pause();
            }
        }