Exemplo n.º 1
0
        private string _lastTrackFullName; //local files handling
        private void UpdateTrackInfo(IPlaybackResponse playbackState)
        {
            if (playbackState == null)
            {
                return;
            }

            PlayingTrackControl.Update(playbackState);

            string gameName = _gameProcess.CurrentProcess?.WindowName ?? "";

            UserSettingsBlock.Update(_userContext.LastAccount, gameName);

            if (_lastTrackFullName == playbackState.FullName)
            {
                return;
            }

            BackgroundCover.Update(playbackState.CoverUrl);
            _configWriter.RewriteKeyBinding(playbackState);

            _lastTrackFullName = playbackState.FullName;

            if (UserSettingsBlock.AutosendCheck.IsToggled && _gameProcess.IsValid)
            {
                _keySender.SendSystemInput(UserSettingsBlock.CurrentVirtualKey);
            }
        }
Exemplo n.º 2
0
        private void ButtonDo_Click(object sender, RoutedEventArgs e)
        {
            if (AppInfo.State.TokenExpireTime < DateTime.Now)
            {
                this.ButtonDo.Content = "spotify token expired!";
                return;
            }

            var trackResp = _spotify.GetCurrentTrack(AppInfo.State.SpotifyAccessToken);

            if (trackResp == null)
            {
                return;
            }

            this.UpdateInterfaceTrackInfo(trackResp);

            if (AccountsList.SelectedItem == null)
            {
                return;
            }

            var cfgWriter = new ConfigWriter(
                $@"{SteamIdLooker.UserdataPath}\{this.GetSelectedAccountId().ToString()}\730\local\cfg\audio.cfg",
                this.NowPlayingConfig.Config.CfgText);

            cfgWriter.RewriteKeyBinding(trackResp);
        }
Exemplo n.º 3
0
        private static void onPlaybackStateUpdate(IPlaybackResponse resp)
        {
            if (resp == null)
            {
                Console.Clear();
                Console.WriteLine("Nothing is playing!");
                return;
            }

            Console.Clear();
            Console.WriteLine($"{resp.FullName} ({resp.ProgressMinutes}:{resp.ProgressSeconds:00})");
            Console.WriteLine("Current account: " + steamContext.LastAccount);
            Console.WriteLine("Current key: " + currentKey);

            if (resp.Id != lastTrackId)
            {
                if (process.IsValid)
                {
                    keySender.SendSystemInput(currentKeyVirtual);
                }

                lastTrackId = resp.Id;
                configWriter.RewriteKeyBinding(resp);
            }
        }
Exemplo n.º 4
0
        private async void ToggleSwitch_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (!this.SpotifySwitch.Toggled)
            {
                this._cancellationGetSpotifyUpdates?.Cancel();
                Program.TrayMenu.NpcWorkTrayCheckBox.Checked = false;
                return;
            }

            //if (AppInfo.State.WindowName == string.Empty)
            //{
            //    this.SpotifySwitch.TurnOff();
            //    MessageBox.Show("make game window active at least once");
            //    return;
            //}

            if (!SourceKeysExtensions.SourceEngineAllowedKeys.Contains(this.TextBoxKeyBind.CurrentText))
            {
                this.SpotifySwitch.TurnOff();
                MessageBox.Show("there is no such button in source engine");
                return;
            }

            TextBoxToConsole.Text = $"bind \"{this.TextBoxKeyBind.CurrentText}\" \"exec audio.cfg\"";

            this.ButtonDo_Click(this, null); // force first request to not wait for the Thread.Sleep(1000)

            int _SelectedAccount = GetSelectedAccountIndex();

            this._cancellationGetSpotifyUpdates = new CancellationTokenSource();

            var cfgWriter = new ConfigWriter(
                $@"{SteamIdLooker.UserdataPath}\{this.GetSelectedAccountId().ToString()}\730\local\cfg\audio.cfg",
                this.NowPlayingConfig.Config.CfgText);

            await Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if (SelectionChanged(_SelectedAccount))
                    {
                        this.Dispatcher.Invoke(() => OnAccountsListSelectionChanged());
                    }

                    Thread.Sleep(1000);

                    if (AppInfo.State.TokenExpireTime < DateTime.Now)
                    {
                        var refreshedTokenResp = _spotify.GetRefreshedToken(AppInfo.State.SpotifyRefreshToken);
                        AppInfo.State.UpdateToken(refreshedTokenResp);
                        cfgWriter.RewriteKeyBinding("say \"spotify token expired!\"");
                    }

                    var trackResp = _spotify.GetCurrentTrack(AppInfo.State.SpotifyAccessToken);

                    if (trackResp != null && trackResp.Id != this.PlayingTrackId)
                    {
                        cfgWriter.RewriteKeyBinding(trackResp);

                        if (trackResp.FormattedArtists.Length > 27)
                        {
                            Dispatcher.Invoke(() => LabelArtistAnimation());
                        }
                        else
                        {
                            Dispatcher.Invoke(() => LabelArtist.BeginAnimation(Canvas.RightProperty, null));
                        }

                        if (IsAutoTrackChangeEnabled && Program.GameProcess.IsValid)
                        {
                            KeySender.SendInputWithAPI(CurrentKeyBind);
                        }
                    }

                    this.Dispatcher.Invoke(() => this.UpdateInterfaceTrackInfo(trackResp));

                    if (this._cancellationGetSpotifyUpdates.IsCancellationRequested)
                    {
                        return;
                    }
                }
            });
        }