private void UpdateSpotify(GeneralProfileDataModel dataModel)
        {
            // Spotify
            if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning())
            {
                SetupSpotify();
            }

            var status = _spotify.GetStatus();

            if (status == null)
            {
                return;
            }

            dataModel.Spotify.Playing = status.Playing;
            dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning();

            if (status.Track != null)
            {
                dataModel.Spotify.Artist     = status.Track.ArtistResource?.Name;
                dataModel.Spotify.SongName   = status.Track.TrackResource?.Name;
                dataModel.Spotify.Album      = status.Track.AlbumResource?.Name;
                dataModel.Spotify.SongLength = status.Track.Length;
            }

            if (dataModel.Spotify.SongLength > 0)
            {
                dataModel.Spotify.SongPercentCompleted =
                    (int)(status.PlayingPosition / dataModel.Spotify.SongLength * 100.0);
            }
        }
        public GeneralProfileModel(DeviceManager deviceManager, LuaManager luaManager,
                                   AudioCaptureManager audioCaptureManager) : base(deviceManager, luaManager)
        {
            _lastMusicUpdate = DateTime.Now;

            Settings  = SettingsProvider.Load <GeneralProfileSettings>();
            DataModel = new GeneralProfileDataModel();

            audioCaptureManager.AudioDeviceChanged += AudioDeviceChanged;
        }
        private void UpdateDay(GeneralProfileDataModel dataModel)
        {
            var now = DateTime.Now;

            dataModel.CurrentTime.Hours24 = now.Hour;
            dataModel.CurrentTime.Minutes = now.Minute;
            dataModel.CurrentTime.Seconds = now.Second;
            dataModel.CurrentTime.Hours12 = now.Hour >= 13
                ? now.Hour - 12
                : now.Hour;
        }
        public void UpdateMusicPlayers(GeneralProfileDataModel dataModel)
        {
            // This is quite resource hungry so only update it once every two seconds
            if (DateTime.Now - _lastMusicUpdate < TimeSpan.FromSeconds(2))
            {
                return;
            }
            _lastMusicUpdate = DateTime.Now;

            UpdateSpotify(dataModel);
            UpdateGooglePlayMusic(dataModel);
        }
        private void UpdateGooglePlayMusic(GeneralProfileDataModel dataModel)
        {
            // Google Play Music
            var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var json    = appData + @"\Google Play Music Desktop Player\json_store\playback.json";

            if (!File.Exists(json))
            {
                return;
            }

            dataModel.GooglePlayMusic = JsonConvert.DeserializeObject <GooglePlayMusic>(File.ReadAllText(json));
        }
        private void UpdateAudio(GeneralProfileDataModel dataModel)
        {
            // Update microphone, only bother with OverallPeak
            if (_defaultRecording != null)
            {
                dataModel.Audio.Recording.OverallPeak = _recordingInfo.PeakValue;
            }

            if (_defaultPlayback == null)
            {
                return;
            }

            // Update volume if a default device is found
            dataModel.Audio.Volume = AudioEndpointVolume.FromDevice(_defaultPlayback).GetMasterVolumeLevelScalar();

            // Update speakers, only do overall, left and right for now
            // TODO: When adding list support lets do all channels
            var peakValues = _playbackInfo.GetChannelsPeakValues();

            dataModel.Audio.Playback.OverallPeak = _playbackInfo.PeakValue;
            dataModel.Audio.Playback.LeftPeak    = peakValues[0];
            dataModel.Audio.Playback.RightPeak   = peakValues[1];
        }
 private void UpdateActiveWindow(GeneralProfileDataModel dataModel)
 {
     dataModel.ActiveWindow.ProcessName = ActiveWindowHelper.ActiveWindowProcessName;
     dataModel.ActiveWindow.WindowTitle = ActiveWindowHelper.ActiveWindowWindowTitle;
 }
 private void UpdateKeyStates(GeneralProfileDataModel dataModel)
 {
     dataModel.Keyboard.NumLock    = ((ushort)GetKeyState(0x90) & 0xffff) != 0;
     dataModel.Keyboard.CapsLock   = ((ushort)GetKeyState(0x14) & 0xffff) != 0;
     dataModel.Keyboard.ScrollLock = ((ushort)GetKeyState(0x91) & 0xffff) != 0;
 }
        private void UpdateCpu(GeneralProfileDataModel dataModel)
        {
            if (_cores == null || _overallCpu == null)
            {
                return;
            }

            // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often
            _cpuFrames++;
            if (_cpuFrames < 16)
            {
                return;
            }

            _cpuFrames = 0;

            // Update cores, not ideal but data models don't support lists.
            if (_cores[0] != null)
            {
                dataModel.Cpu.Core1Usage = (int)_cores[0].NextValue();
            }
            if (_cores[1] != null)
            {
                dataModel.Cpu.Core2Usage = (int)_cores[1].NextValue();
            }
            if (_cores[2] != null)
            {
                dataModel.Cpu.Core3Usage = (int)_cores[2].NextValue();
            }
            if (_cores[3] != null)
            {
                dataModel.Cpu.Core4Usage = (int)_cores[3].NextValue();
            }
            if (_cores[4] != null)
            {
                dataModel.Cpu.Core5Usage = (int)_cores[4].NextValue();
            }
            if (_cores[5] != null)
            {
                dataModel.Cpu.Core6Usage = (int)_cores[5].NextValue();
            }
            if (_cores[6] != null)
            {
                dataModel.Cpu.Core7Usage = (int)_cores[6].NextValue();
            }
            if (_cores[7] != null)
            {
                dataModel.Cpu.Core8Usage = (int)_cores[7].NextValue();
            }
            dataModel.Cpu.TotalUsage = (int)_overallCpu.NextValue();

            // Get RAM usage
            var memoryStatus    = new PerformanceInfo.MEMORYSTATUSEX();
            var gotMemoryStatus = PerformanceInfo.GlobalMemoryStatusEx(memoryStatus);

            if (!gotMemoryStatus)
            {
                return;
            }
            dataModel.Performance.RamTotal = (memoryStatus.ullTotalPhys / 1024f) / 1024f;
            dataModel.Performance.RamFree  = (memoryStatus.ullAvailPhys / 1024f) / 1024f;
            dataModel.Performance.RamUsed  = dataModel.Performance.RamTotal - dataModel.Performance.RamFree;
        }