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); } }
public MainWindow() { InitializeComponent(); HeaderBlock.CloseButton.MouseLeftButtonDown += new MouseButtonEventHandler((o, s) => Application.Current.Shutdown()); HeaderBlock.CollapseButton.MouseLeftButtonDown += new MouseButtonEventHandler((o, s) => WindowState = WindowState.Minimized); _spotify = new SpotifyRequestsManager("7633771350404368ac3e05c9cf73d187", "29bd9ec2676c4bf593f3cc2858099838", @"http://localhost:8888/"); _steamService = new SteamServiceWindows(); _pathResolver = new PathResolver(); _keySender = new InputSenderWindows(); _appConfigWorker = new UserSettingsWorker(); _appConfig = _appConfigWorker.ReadConfigFile(); _userContext = _steamService.GetSteamContext(); _accounts = _userContext.GetAccounts(); _gameProcess = new GameProcess(); _gameProcess.Start(); int steamid3 = _accounts.FirstOrDefault((x) => x.Name == _userContext.LastAccount).SteamId3; string writePath = _pathResolver.GetWritePath(_gameProcess.CurrentProcess, _userContext.UserdataPath, steamid3.ToString()); _configWriter = new ConfigWriter(writePath, _appConfig.CfgText); _playbackStateUpdater = new SpotifyTrackUpdater(_spotify); _playbackStateUpdater.OnPlaybackStateUpdate += UpdateTrackInfo; UserSettingsBlock.CurrentAccountText.Text = _userContext.LastAccount; UserSettingsBlock.UpdateKey(_appConfig.LastUsedKey); if (_appConfig.IsAutoSendEnabled) { UserSettingsBlock.AutosendCheck.Toggle(); } }