From cf74ec8503b4163a08a4ed38587618ddbe2be803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ayta=C3=A7=20Kayadelen?= Date: Thu, 23 Feb 2023 22:07:42 +0300 Subject: [PATCH] refactor media watch code revert button detections to older, non-focused session behavior --- Artemis.MediaInfo/Artemis.MediaInfo.csproj | 1 + .../DataModels/MediaInfoDataModel.cs | 12 -- Artemis.MediaInfo/MediaInfoModule.cs | 195 ++++++------------ Artemis.MediaInfo/MediaWatch/MediaEvents.cs | 41 ++++ Artemis.MediaInfo/MediaWatch/MediaWatcher.cs | 140 +++++++++++++ .../{ => Utils}/MediaInfoHelper.cs | 7 +- Artemis.MediaInfo/Utils/RegistryWatcher.cs | 55 +++-- Artemis.MediaInfo/WindowsInfoModule.cs | 8 +- 8 files changed, 298 insertions(+), 161 deletions(-) create mode 100644 Artemis.MediaInfo/MediaWatch/MediaEvents.cs create mode 100644 Artemis.MediaInfo/MediaWatch/MediaWatcher.cs rename Artemis.MediaInfo/{ => Utils}/MediaInfoHelper.cs (77%) diff --git a/Artemis.MediaInfo/Artemis.MediaInfo.csproj b/Artemis.MediaInfo/Artemis.MediaInfo.csproj index 2a2d6e2..fc977ac 100644 --- a/Artemis.MediaInfo/Artemis.MediaInfo.csproj +++ b/Artemis.MediaInfo/Artemis.MediaInfo.csproj @@ -4,6 +4,7 @@ x64 x64 false + enable diff --git a/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs b/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs index 2b1dd2f..e0cacfb 100644 --- a/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs +++ b/Artemis.MediaInfo/DataModels/MediaInfoDataModel.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; -using Windows.Media; using Windows.Media.Control; -using Artemis.Core; using Artemis.Core.ColorScience; using Artemis.Core.Modules; using WindowsMediaController; @@ -36,16 +34,6 @@ public class MediaInfoDataModel : DataModel public string SessionName { get; set; } - public DataModelEvent MediaChanged { get; } = new(); public ISet MediaSessions { get; set; } public ISet ArtMediaSessions { get; set; } -} - -public class MediaChangedEventArgs : DataModelEventArgs -{ - public string SessionId { get; set; } - public string Title { get; set; } - public string Artist { get; set; } - public MediaPlaybackType MediaType { get; set; } - public bool HasArt { get; set; } } \ No newline at end of file diff --git a/Artemis.MediaInfo/MediaInfoModule.cs b/Artemis.MediaInfo/MediaInfoModule.cs index df3303c..5e724b6 100644 --- a/Artemis.MediaInfo/MediaInfoModule.cs +++ b/Artemis.MediaInfo/MediaInfoModule.cs @@ -1,12 +1,11 @@ -using Artemis.Core; +using System; +using Artemis.Core; using Artemis.Core.Modules; using System.Collections.Generic; using System.Linq; using Artemis.MediaInfo.DataModels; -using WindowsMediaController; -using Windows.Media; using Windows.Media.Control; -using Artemis.Core.Properties; +using Artemis.MediaInfo.MediaWatch; using static WindowsMediaController.MediaManager; using static Artemis.MediaInfo.MediaInfoHelper; @@ -15,186 +14,118 @@ namespace Artemis.MediaInfo; [PluginFeature(Name = "MediaInfo")] public class MediaInfoModule : Module { - private MediaManager _mediaManager; + private static readonly bool FocusedUpdate = false; //because window's focus events don't work well for everyone :/ public override List ActivationRequirements { get; } = new(); - private readonly ISet _mediaSessions = new HashSet(new MediaSessionComparer()); - private readonly ISet _albumArtSessions = new HashSet(new MediaSessionComparer()); - - [CanBeNull] - private MediaSession _currentSession; + private readonly MediaWatcher _mediaWatcher = new(); public override void Enable() { - _mediaSessions.Clear(); - _albumArtSessions.Clear(); - - _mediaManager = new MediaManager(); - _mediaManager.OnAnySessionOpened += MediaManager_OnSessionOpened; - _mediaManager.OnAnySessionClosed += MediaManager_OnAnySessionClosed; - _mediaManager.OnFocusedSessionChanged += MediaManagerOnOnFocusedSessionChanged; - _mediaManager.OnAnyMediaPropertyChanged += MediaManager_OnAnyMediaPropertyChanged; //listen for media arts - - _mediaManager.Start(); - - foreach (var (_, mediaSession) in _mediaManager.CurrentMediaSessions) - { - _mediaSessions.Add(mediaSession); - } - } - - private void MediaManagerOnOnFocusedSessionChanged(MediaSession mediaSession) - { - if (_currentSession != null) - { - _currentSession.OnPlaybackStateChanged -= MediaSession_OnPlaybackStateChanged; - } - _mediaSessions.Add(mediaSession); - _currentSession = mediaSession; - _mediaManager.OnAnyPlaybackStateChanged += MediaSession_OnPlaybackStateChanged; - MediaSession_OnPlaybackStateChanged(mediaSession, mediaSession.ControlSession.GetPlaybackInfo()); + DataModel.MediaSessions = _mediaWatcher.MediaSessions; + DataModel.ArtMediaSessions = _mediaWatcher.AlbumArtSessions; } public override void Disable() { - _albumArtSessions.Clear(); - _mediaSessions.Clear(); - - if (_currentSession != null) - { - _currentSession.OnPlaybackStateChanged -= MediaSession_OnPlaybackStateChanged; - } - - _mediaManager.OnAnyMediaPropertyChanged -= MediaManager_OnAnyMediaPropertyChanged; - _mediaManager.OnFocusedSessionChanged -= MediaManagerOnOnFocusedSessionChanged; - _mediaManager.OnAnySessionClosed -= MediaManager_OnAnySessionClosed; - _mediaManager.OnAnySessionOpened -= MediaManager_OnSessionOpened; - _mediaManager.Dispose(); - _mediaManager = null; + //unused } public override void Update(double deltaTime) {} public override void ModuleActivated(bool isOverride) { - DataModel.MediaSessions = _mediaSessions; - DataModel.ArtMediaSessions = _albumArtSessions; + _mediaWatcher.FocusedMediaChanged += MediaWatcherOnFocusedMediaChanged; + _mediaWatcher.ArtStateChanged += MediaWatcherOnArtStateChanged; + _mediaWatcher.StartListening().Wait(); } public override void ModuleDeactivated(bool isOverride) { - //unused - } - - private void MediaManager_OnSessionOpened(MediaSession mediaSession) - { - DataModel.HasMedia = true; - _mediaSessions.Add(mediaSession); + _mediaWatcher.StopListening(); + _mediaWatcher.FocusedMediaChanged -= MediaWatcherOnFocusedMediaChanged; + _mediaWatcher.ArtStateChanged -= MediaWatcherOnArtStateChanged; } - private void MediaManager_OnAnySessionClosed(MediaSession mediaSession) + private void MediaWatcherOnFocusedMediaChanged(object? sender, FocusedMediaChangedEventArgs e) { - _currentSession.OnPlaybackStateChanged -= MediaSession_OnPlaybackStateChanged; - _mediaSessions.Remove(mediaSession); - _albumArtSessions.Remove(mediaSession); - if (_currentSession.Id == mediaSession.Id) - { - _currentSession = _mediaManager.GetFocusedSession(); - } - UpdateButtons(_currentSession); - UpdateArtState(); + var mediaSession = e.MediaSession; + UpdateButtons(mediaSession, e.PlaybackInfo); } - private async void MediaManager_OnAnyMediaPropertyChanged(MediaSession mediaSession, - GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties) + private void UpdateButtons(MediaSession? mediaSession, + GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackInfo) { - if (mediaSession.ControlSession == null) + if (mediaSession == null) { - MediaManager_OnAnySessionClosed(mediaSession); + DataModel.HasMedia = false; + DataModel.HasNextMedia = false; + DataModel.HasPreviousMedia = false; + DataModel.MediaPlaying = false; + DataModel.MediaState = GlobalSystemMediaTransportControlsSessionPlaybackStatus.Closed; + DataModel.SessionName = ""; return; } - try - { - if (mediaProperties.Thumbnail is null) - { - _albumArtSessions.Remove(mediaSession); - return; - } + DataModel.HasMedia = true; - DataModel.ArtColors = await ReadMediaColors(mediaProperties); - _albumArtSessions.Add(mediaSession); - } - catch + if (FocusedUpdate) { - _albumArtSessions.Remove(mediaSession); + FocusedModelUpdate(mediaSession, playbackInfo); } - finally + else { - UpdateArtState(); - DataModel.MediaChanged.Trigger(new MediaChangedEventArgs - { - SessionId = mediaSession.Id, - Title = mediaProperties.Title, - Artist = mediaProperties.Artist, - MediaType = mediaProperties.PlaybackType ?? MediaPlaybackType.Unknown, - HasArt = mediaProperties.Thumbnail is not null - }); + AnySessionModelUpdate(mediaSession, playbackInfo); } } - private void MediaSession_OnPlaybackStateChanged(MediaSession mediaSession, - GlobalSystemMediaTransportControlsSessionPlaybackInfo playbackInfo) + private void FocusedModelUpdate(MediaSession mediaSession, + GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackInfo) { - if (playbackInfo == null || playbackInfo.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Closed) + if (playbackInfo == null) { - MediaManager_OnAnySessionClosed(mediaSession); - return; + playbackInfo = mediaSession.ControlSession.GetPlaybackInfo(); } - _mediaSessions.Add(mediaSession); // Some app like chrome use same id for different tabs. - // So, closing the tab may cause all chroma sessions to be removed. This re-adds them - - UpdateButtons(mediaSession); - UpdateArtState(); - } - - private void UpdateButtons(MediaSession mediaSession) - { - if (mediaSession == null) - { - DataModel.HasMedia = false; - DataModel.HasNextMedia = false; - DataModel.HasPreviousMedia = false; - DataModel.MediaPlaying = false; - DataModel.MediaState = GlobalSystemMediaTransportControlsSessionPlaybackStatus.Closed; - DataModel.SessionName = ""; - return; - } - DataModel.HasMedia = true; - - var playbackInfo = mediaSession.ControlSession.GetPlaybackInfo(); var playbackControls = playbackInfo.Controls; + DataModel.HasNextMedia = playbackControls.IsNextEnabled; DataModel.HasPreviousMedia = playbackControls.IsPreviousEnabled; - DataModel.MediaPlaying = playbackInfo.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing; + DataModel.MediaPlaying = + playbackInfo.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing; DataModel.MediaState = playbackInfo.PlaybackStatus; DataModel.SessionName = mediaSession.Id; } - private void UpdateArtState() + private void AnySessionModelUpdate(MediaSession focusedMediaSession, + GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackInfo) { - DataModel.HasArt = _albumArtSessions.Any(); + DataModel.HasPreviousMedia = false; + DataModel.MediaPlaying = false; + DataModel.HasNextMedia = false; + DataModel.MediaState = playbackInfo?.PlaybackStatus ?? GlobalSystemMediaTransportControlsSessionPlaybackStatus.Closed; + DataModel.SessionName = focusedMediaSession.Id; + foreach (var mediaSession in _mediaWatcher.MediaSessions) + { + var controls = mediaSession.ControlSession.GetPlaybackInfo().Controls; + DataModel.HasPreviousMedia |= controls.IsPreviousEnabled; + DataModel.MediaPlaying |= !controls.IsPlayEnabled; + DataModel.HasNextMedia |= controls.IsNextEnabled; + } } - private sealed class MediaSessionComparer : IEqualityComparer + private async void MediaWatcherOnArtStateChanged(object? sender, ArtStateChangedEventArgs e) { - public bool Equals(MediaSession x, MediaSession y) + if (e.Thumbnail != null) { - return x?.Id == y?.Id; + DataModel.ArtColors = await ReadMediaColors(e.Thumbnail); } - - public int GetHashCode(MediaSession obj) + else { - return obj.Id.GetHashCode(); + var mediaSession = _mediaWatcher.AlbumArtSessions.LastOrDefault(); + if (mediaSession!= null) + { + var mediaProperties = mediaSession.ControlSession.TryGetMediaPropertiesAsync().GetAwaiter().GetResult(); + DataModel.ArtColors = await ReadMediaColors(mediaProperties); + } } + 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 new file mode 100644 index 0000000..a43654b --- /dev/null +++ b/Artemis.MediaInfo/MediaWatch/MediaEvents.cs @@ -0,0 +1,41 @@ +using System; +using Windows.Media.Control; +using Windows.Storage.Streams; +using WindowsMediaController; + +namespace Artemis.MediaInfo.MediaWatch; + +public class MediaAddedEventArgs : EventArgs +{ + public MediaManager.MediaSession MediaSession { get; } + + public MediaAddedEventArgs(MediaManager.MediaSession mediaSession) + { + MediaSession = mediaSession; + } +} + +public class ArtStateChangedEventArgs : EventArgs +{ + public MediaManager.MediaSession MediaSession { get; } + public IRandomAccessStreamReference? Thumbnail { get; } + + public ArtStateChangedEventArgs(MediaManager.MediaSession mediaSession, IRandomAccessStreamReference? thumbnail) + { + MediaSession = mediaSession; + Thumbnail = thumbnail; + } +} + +public class FocusedMediaChangedEventArgs : EventArgs +{ + public MediaManager.MediaSession? MediaSession { get; } + public GlobalSystemMediaTransportControlsSessionPlaybackInfo? PlaybackInfo { get; } + + public FocusedMediaChangedEventArgs(MediaManager.MediaSession? mediaSession, + GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackInfo) + { + MediaSession = mediaSession; + PlaybackInfo = playbackInfo; + } +} \ No newline at end of file diff --git a/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs b/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs new file mode 100644 index 0000000..0756b4d --- /dev/null +++ b/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Windows.Media.Control; +using WindowsMediaController; +using static WindowsMediaController.MediaManager; + +namespace Artemis.MediaInfo.MediaWatch; + +public class MediaWatcher +{ + private readonly MediaManager _mediaManager = new(); + + public ISet MediaSessions { get; } = new HashSet(new MediaSessionComparer()); + public ISet AlbumArtSessions { get; } = new HashSet(new MediaSessionComparer()); + + private MediaSession? _currentSession; + + public event EventHandler? FocusedMediaChanged; + public event EventHandler? ArtStateChanged; + + public async Task StartListening() + { + _mediaManager.OnAnySessionOpened += MediaManager_OnSessionOpened; + _mediaManager.OnAnySessionClosed += MediaManager_OnAnySessionClosed; + _mediaManager.OnFocusedSessionChanged += MediaManagerOnOnFocusedSessionChanged; + _mediaManager.OnAnyMediaPropertyChanged += MediaManager_OnAnyMediaPropertyChanged; //listen for media arts + + await _mediaManager.StartAsync(); + + foreach (var (_, mediaSession) in _mediaManager.CurrentMediaSessions) + { + MediaSessions.Add(mediaSession); + } + } + + public void StopListening() + { + MediaSessions.Clear(); + AlbumArtSessions.Clear(); + + if (_currentSession != null) + { + _currentSession.OnPlaybackStateChanged -= MediaSession_OnPlaybackStateChanged; + } + _currentSession = null; + + _mediaManager.OnAnyMediaPropertyChanged -= MediaManager_OnAnyMediaPropertyChanged; + _mediaManager.OnFocusedSessionChanged -= MediaManagerOnOnFocusedSessionChanged; + _mediaManager.OnAnySessionClosed -= MediaManager_OnAnySessionClosed; + _mediaManager.OnAnySessionOpened -= MediaManager_OnSessionOpened; + _mediaManager.Dispose(); + } + + private void MediaManagerOnOnFocusedSessionChanged(MediaSession? mediaSession) + { + if (_currentSession != null) + { + _currentSession.OnPlaybackStateChanged -= MediaSession_OnPlaybackStateChanged; + } + + if (mediaSession != null) + { + _currentSession = mediaSession; + _currentSession.OnPlaybackStateChanged += MediaSession_OnPlaybackStateChanged; + } + FocusedMediaChanged?.Invoke(this, new FocusedMediaChangedEventArgs(mediaSession, null)); + } + + private void MediaManager_OnSessionOpened(MediaSession mediaSession) + { + MediaSessions.Add(mediaSession); + _mediaManager.ForceUpdate(); + } + + private void MediaManager_OnAnySessionClosed(MediaSession mediaSession) + { + AlbumArtSessions.Remove(mediaSession); + MediaSessions.Remove(mediaSession); + _mediaManager.ForceUpdate(); + } + + private void MediaManager_OnAnyMediaPropertyChanged(MediaSession mediaSession, + GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties) + { + if (mediaSession.ControlSession == null) + { + MediaManager_OnAnySessionClosed(mediaSession); + return; + } + try + { + if (mediaProperties.Thumbnail is null) + { + AlbumArtSessions.Remove(mediaSession); + ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaSession, null)); + return; + } + + AlbumArtSessions.Add(mediaSession); + ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaSession, mediaProperties.Thumbnail)); + } + catch + { + AlbumArtSessions.Remove(mediaSession); + ArtStateChanged?.Invoke(this, new ArtStateChangedEventArgs(mediaSession, null)); + } + } + + private void MediaSession_OnPlaybackStateChanged(MediaSession mediaSession, + GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackInfo) + { + if (playbackInfo == null || mediaSession.ControlSession == null || + playbackInfo.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Closed || + playbackInfo.Controls == null) + { + MediaManager_OnAnySessionClosed(mediaSession); + return; + } + + // Some app like chrome use same id for different tabs. + // So, closing the tab may cause all chroma sessions to be removed. This re-adds them + MediaSessions.Add(mediaSession); + + FocusedMediaChanged?.Invoke(this, new FocusedMediaChangedEventArgs(mediaSession, playbackInfo)); + } + + private sealed class MediaSessionComparer : IEqualityComparer + { + public bool Equals(MediaSession? x, MediaSession? y) + { + return x?.Id == y?.Id; + } + + public int GetHashCode(MediaSession obj) + { + return obj.Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Artemis.MediaInfo/MediaInfoHelper.cs b/Artemis.MediaInfo/Utils/MediaInfoHelper.cs similarity index 77% rename from Artemis.MediaInfo/MediaInfoHelper.cs rename to Artemis.MediaInfo/Utils/MediaInfoHelper.cs index 8a49bfd..5dcd7c7 100644 --- a/Artemis.MediaInfo/MediaInfoHelper.cs +++ b/Artemis.MediaInfo/Utils/MediaInfoHelper.cs @@ -11,7 +11,12 @@ public static class MediaInfoHelper { internal static async Task ReadMediaColors(GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties) { - var imageStream = await mediaProperties.Thumbnail.OpenReadAsync(); + return await ReadMediaColors(mediaProperties.Thumbnail); + } + + internal static async Task ReadMediaColors(IRandomAccessStreamReference thumbnail) + { + var imageStream = await thumbnail.OpenReadAsync(); var fileBytes = new byte[imageStream.Size]; using (var reader = new DataReader(imageStream)) diff --git a/Artemis.MediaInfo/Utils/RegistryWatcher.cs b/Artemis.MediaInfo/Utils/RegistryWatcher.cs index 4c0e9a7..7c4eb09 100644 --- a/Artemis.MediaInfo/Utils/RegistryWatcher.cs +++ b/Artemis.MediaInfo/Utils/RegistryWatcher.cs @@ -7,37 +7,64 @@ namespace Artemis.MediaInfo.Utils; public class RegistryChangedEventArgs : EventArgs { - public readonly object Data; + public readonly object? Data; - public RegistryChangedEventArgs(object data) + public RegistryChangedEventArgs(object? data) { Data = data; } } +public enum WatchedRegistry +{ + CurrentUser, + LocalMachine, +} + public sealed class RegistryWatcher : IDisposable { - public event EventHandler RegistryChanged; + public event EventHandler? RegistryChanged; + private readonly RegistryKey _registry; private readonly string _key; private readonly string _value; - private ManagementEventWatcher _eventWatcher; + private ManagementEventWatcher? _eventWatcher; + private readonly WqlEventQuery _query; - public RegistryWatcher(string key, string value) + public RegistryWatcher(WatchedRegistry watchedRegistry, string key, string value) { _key = key; _value = value; + + var currentUser = WindowsIdentity.GetCurrent(); + var keyPath = _key.Replace("\\", "\\\\"); + var queryString = watchedRegistry switch + { + WatchedRegistry.LocalMachine => + $"SELECT * FROM RegistryValueChangeEvent " + + $"WHERE Hive='HKEY_LOCAL_MACHINE' AND " + + $"KeyPath='{keyPath}' AND " + + $"ValueName='{_value}'", + WatchedRegistry.CurrentUser => + "SELECT * FROM RegistryValueChangeEvent " + + "WHERE Hive='HKEY_USERS' AND " + + $"KeyPath='{currentUser.User!.Value}\\\\{keyPath}' AND " + + $"ValueName='{_value}'", + _ => throw new ArgumentOutOfRangeException(nameof(watchedRegistry), watchedRegistry, "This part of registry is not implemented") + }; + _query = new WqlEventQuery(queryString); + _registry = watchedRegistry switch + { + WatchedRegistry.LocalMachine => Registry.LocalMachine, + WatchedRegistry.CurrentUser => Registry.CurrentUser, + _ => throw new ArgumentException("This part of registry is not implemented") + }; } public void StartWatching() { - var currentUser = WindowsIdentity.GetCurrent(); ManagementScope scope = new ManagementScope("\\\\.\\root\\default"); - var queryString = string.Format( - "SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_USERS' AND KeyPath='{0}\\\\{1}' AND ValueName='{2}'", - currentUser.User.Value, _key.Replace("\\", "\\\\"), _value); - var query = new WqlEventQuery(queryString); - _eventWatcher = new ManagementEventWatcher(scope, query); + _eventWatcher = new ManagementEventWatcher(scope, _query); _eventWatcher.EventArrived += KeyWatcherOnEventArrived; _eventWatcher.Start(); @@ -46,6 +73,10 @@ public void StartWatching() public void StopWatching() { + if (_eventWatcher == null) + { + return; + } _eventWatcher.EventArrived -= KeyWatcherOnEventArrived; _eventWatcher.Stop(); _eventWatcher.Dispose(); @@ -59,7 +90,7 @@ private void KeyWatcherOnEventArrived(object sender, EventArrivedEventArgs e) private void SendData() { - using var key = Registry.CurrentUser.OpenSubKey(_key); + using var key = _registry.OpenSubKey(_key); var data = key?.GetValue(_value); RegistryChanged?.Invoke(this, new RegistryChangedEventArgs(data)); } diff --git a/Artemis.MediaInfo/WindowsInfoModule.cs b/Artemis.MediaInfo/WindowsInfoModule.cs index 5b3598d..84244f1 100644 --- a/Artemis.MediaInfo/WindowsInfoModule.cs +++ b/Artemis.MediaInfo/WindowsInfoModule.cs @@ -9,11 +9,11 @@ namespace Artemis.MediaInfo; public class WindowsInfoModule : Module { - private readonly RegistryWatcher _nightLightStateWatcher = new( + private readonly RegistryWatcher _nightLightStateWatcher = new(WatchedRegistry.CurrentUser, @"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CloudStore\\" + @"Store\\DefaultAccount\\Current\\default$windows.data.bluelightreduction.bluelightreductionstate\\" + @"windows.data.bluelightreduction.bluelightreductionstate", "Data"); - private readonly RegistryWatcher _accentColorWatcher = new( + private readonly RegistryWatcher _accentColorWatcher = new(WatchedRegistry.CurrentUser, @"SOFTWARE\\Microsoft\\Windows\\DWM", "AccentColor"); public override void Enable() @@ -59,7 +59,7 @@ private void OnSessionSwitch(object sender, SessionSwitchEventArgs e) }; } - private void UpdateNightLight(object sender, RegistryChangedEventArgs registryChangedEventArgs) + private void UpdateNightLight(object? sender, RegistryChangedEventArgs registryChangedEventArgs) { var data = registryChangedEventArgs.Data; if (data is null) @@ -72,7 +72,7 @@ private void UpdateNightLight(object sender, RegistryChangedEventArgs registryCh DataModel.NightLightsEnabled = byteData.Length > 24 && byteData[23] == 0x10 && byteData[24] == 0x00; } - private void UpdateAccentColor(object sender, RegistryChangedEventArgs registryChangedEventArgs) + private void UpdateAccentColor(object? sender, RegistryChangedEventArgs registryChangedEventArgs) { var data = registryChangedEventArgs.Data; switch (data)