diff --git a/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs b/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs index e0cacfb..d4e7912 100644 --- a/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs +++ b/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs @@ -31,9 +31,9 @@ public class MediaInfoDataModel : DataModel public bool HasArt { get; set; } public ColorSwatch ArtColors { get; set; } - - public string SessionName { get; set; } - public ISet MediaSessions { get; set; } - public ISet ArtMediaSessions { get; set; } + public string SessionName { get; set; } = ""; + + public ISet MediaSessions { get; set; } = new HashSet(); + public ISet ArtMediaSessions { get; set; } = new HashSet(); } \ No newline at end of file diff --git a/Artemis.MediaInfo/MediaInfoModule.cs b/Artemis.MediaInfo/MediaInfoModule.cs index 5e724b6..4cff828 100644 --- a/Artemis.MediaInfo/MediaInfoModule.cs +++ b/Artemis.MediaInfo/MediaInfoModule.cs @@ -115,17 +115,12 @@ private async void MediaWatcherOnArtStateChanged(object? sender, ArtStateChanged { if (e.Thumbnail != null) { + DataModel.HasArt = true; DataModel.ArtColors = await ReadMediaColors(e.Thumbnail); } else { - var mediaSession = _mediaWatcher.AlbumArtSessions.LastOrDefault(); - if (mediaSession!= null) - { - var mediaProperties = mediaSession.ControlSession.TryGetMediaPropertiesAsync().GetAwaiter().GetResult(); - DataModel.ArtColors = await ReadMediaColors(mediaProperties); - } + DataModel.HasArt = false; } - DataModel.HasArt = _mediaWatcher.AlbumArtSessions.Any(); } } \ No newline at end of file diff --git a/Artemis.MediaInfo/MediaWatch/MediaEvents.cs b/Artemis.MediaInfo/MediaWatch/MediaEvents.cs index a43654b..509ca88 100644 --- a/Artemis.MediaInfo/MediaWatch/MediaEvents.cs +++ b/Artemis.MediaInfo/MediaWatch/MediaEvents.cs @@ -17,12 +17,10 @@ public MediaAddedEventArgs(MediaManager.MediaSession mediaSession) public class ArtStateChangedEventArgs : EventArgs { - public MediaManager.MediaSession MediaSession { get; } public IRandomAccessStreamReference? Thumbnail { get; } - public ArtStateChangedEventArgs(MediaManager.MediaSession mediaSession, IRandomAccessStreamReference? thumbnail) + public ArtStateChangedEventArgs(IRandomAccessStreamReference? thumbnail) { - MediaSession = mediaSession; Thumbnail = thumbnail; } } diff --git a/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs b/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs index 0756b4d..f83dd23 100644 --- a/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs +++ b/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Windows.Media.Control; using WindowsMediaController; @@ -75,7 +76,11 @@ private void MediaManager_OnSessionOpened(MediaSession mediaSession) private void MediaManager_OnAnySessionClosed(MediaSession mediaSession) { - AlbumArtSessions.Remove(mediaSession); + var artSessionRemoved = AlbumArtSessions.Remove(mediaSession); + if (artSessionRemoved) + { + NotifyNextMediaSession(); + } MediaSessions.Remove(mediaSession); _mediaManager.ForceUpdate(); } @@ -93,17 +98,31 @@ private void MediaManager_OnAnyMediaPropertyChanged(MediaSession mediaSession, if (mediaProperties.Thumbnail is null) { AlbumArtSessions.Remove(mediaSession); - ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaSession, null)); + NotifyNextMediaSession(); return; } AlbumArtSessions.Add(mediaSession); - ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaSession, mediaProperties.Thumbnail)); + ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaProperties.Thumbnail)); } catch { AlbumArtSessions.Remove(mediaSession); - ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaSession, null)); + NotifyNextMediaSession(); + } + } + + private void NotifyNextMediaSession() + { + var nextArtSession = AlbumArtSessions.LastOrDefault(); + if (nextArtSession != null) + { + var mediaProperties = nextArtSession.ControlSession.TryGetMediaPropertiesAsync().GetAwaiter().GetResult(); + ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaProperties.Thumbnail)); + } + else + { + ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(null)); } } diff --git a/Artemis.MediaInfo/Utils/RegistryWatcher.cs b/Artemis.MediaInfo/Utils/RegistryWatcher.cs index 7c4eb09..538679b 100644 --- a/Artemis.MediaInfo/Utils/RegistryWatcher.cs +++ b/Artemis.MediaInfo/Utils/RegistryWatcher.cs @@ -63,7 +63,7 @@ public RegistryWatcher(WatchedRegistry watchedRegistry, string key, string value public void StartWatching() { - ManagementScope scope = new ManagementScope("\\\\.\\root\\default"); + var scope = new ManagementScope("\\\\.\\root\\default"); _eventWatcher = new ManagementEventWatcher(scope, _query); _eventWatcher.EventArrived += KeyWatcherOnEventArrived; _eventWatcher.Start(); diff --git a/Artemis.MediaInfo/plugin.json b/Artemis.MediaInfo/plugin.json index d8e255a..94441c7 100644 --- a/Artemis.MediaInfo/plugin.json +++ b/Artemis.MediaInfo/plugin.json @@ -6,6 +6,6 @@ "Main": "Artemis.MediaInfo.dll", "Name": "Media Info", "Repository": "https://github.com/Aytackydln/Artemis.MediaInfo", - "Version": "1.1.0.0", + "Version": "1.2.1.0", "Platforms":"Windows" }