diff --git a/Artemis.MediaInfo/Artemis.MediaInfo.csproj b/Artemis.MediaInfo/Artemis.MediaInfo.csproj index fc977ac..7ccb53d 100644 --- a/Artemis.MediaInfo/Artemis.MediaInfo.csproj +++ b/Artemis.MediaInfo/Artemis.MediaInfo.csproj @@ -1,28 +1,25 @@ - net6.0-windows10.0.17763.0 + net7.0-windows10.0.17763.0 x64 x64 false enable + true - - - - - - - - - ..\..\Artemis\src\Artemis.Core\bin\net6.0\Artemis.Core.dll - false - + + + + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Artemis.MediaInfo/DataModels/WindowsInfoDataModel.cs b/Artemis.MediaInfo/DataModels/WindowsInfoDataModel.cs index f5a5036..8173566 100644 --- a/Artemis.MediaInfo/DataModels/WindowsInfoDataModel.cs +++ b/Artemis.MediaInfo/DataModels/WindowsInfoDataModel.cs @@ -1,5 +1,4 @@ -using Artemis.Core.ColorScience; -using Artemis.Core.Modules; +using Artemis.Core.Modules; using SkiaSharp; namespace Artemis.MediaInfo.DataModels; @@ -11,6 +10,9 @@ public class WindowsInfoDataModel : DataModel [DataModelProperty(Name = "Night Lights Enabled")] public bool NightLightsEnabled { get; set; } + + [DataModelProperty(Name = "Night Light Strength")] + public double NightLightsStrength { get; set; } [DataModelProperty(Name = "Desktop Accent Color")] public SKColor AccentColor { get; set; } = SKColor.Empty; diff --git a/Artemis.MediaInfo/MediaInfoModule.cs b/Artemis.MediaInfo/MediaInfoModule.cs index 4cff828..6371b58 100644 --- a/Artemis.MediaInfo/MediaInfoModule.cs +++ b/Artemis.MediaInfo/MediaInfoModule.cs @@ -1,13 +1,11 @@ -using System; -using Artemis.Core; +using Artemis.Core; using Artemis.Core.Modules; using System.Collections.Generic; -using System.Linq; using Artemis.MediaInfo.DataModels; using Windows.Media.Control; using Artemis.MediaInfo.MediaWatch; using static WindowsMediaController.MediaManager; -using static Artemis.MediaInfo.MediaInfoHelper; +using static Artemis.MediaInfo.Utils.MediaInfoHelper; namespace Artemis.MediaInfo; diff --git a/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs b/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs index f83dd23..92a6c06 100644 --- a/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs +++ b/Artemis.MediaInfo/MediaWatch/MediaWatcher.cs @@ -8,6 +8,9 @@ namespace Artemis.MediaInfo.MediaWatch; +/// +/// Wrapping class that it's only dependency is Dubya.WindowsMediaController +/// public class MediaWatcher { private readonly MediaManager _mediaManager = new(); @@ -65,7 +68,7 @@ private void MediaManagerOnOnFocusedSessionChanged(MediaSession? mediaSession) _currentSession = mediaSession; _currentSession.OnPlaybackStateChanged += MediaSession_OnPlaybackStateChanged; } - FocusedMediaChanged?.Invoke(this, new FocusedMediaChangedEventArgs(mediaSession, null)); + FocusedMediaChanged?.Invoke(this, new FocusedMediaChangedEventArgs(mediaSession, mediaSession?.ControlSession.GetPlaybackInfo())); } private void MediaManager_OnSessionOpened(MediaSession mediaSession) diff --git a/Artemis.MediaInfo/Utils/MediaInfoHelper.cs b/Artemis.MediaInfo/Utils/MediaInfoHelper.cs index 5dcd7c7..0865aee 100644 --- a/Artemis.MediaInfo/Utils/MediaInfoHelper.cs +++ b/Artemis.MediaInfo/Utils/MediaInfoHelper.cs @@ -1,19 +1,13 @@ using System; using System.Threading.Tasks; -using Windows.Media.Control; using Windows.Storage.Streams; using Artemis.Core.ColorScience; using SkiaSharp; -namespace Artemis.MediaInfo; +namespace Artemis.MediaInfo.Utils; public static class MediaInfoHelper { - internal static async Task ReadMediaColors(GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties) - { - return await ReadMediaColors(mediaProperties.Thumbnail); - } - internal static async Task ReadMediaColors(IRandomAccessStreamReference thumbnail) { var imageStream = await thumbnail.OpenReadAsync(); diff --git a/Artemis.MediaInfo/WindowsInfoModule.cs b/Artemis.MediaInfo/WindowsInfoModule.cs index 84244f1..810db62 100644 --- a/Artemis.MediaInfo/WindowsInfoModule.cs +++ b/Artemis.MediaInfo/WindowsInfoModule.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Artemis.Core.Modules; using Artemis.MediaInfo.DataModels; using Artemis.MediaInfo.Utils; @@ -13,6 +14,10 @@ public class WindowsInfoModule : Module @"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CloudStore\\" + @"Store\\DefaultAccount\\Current\\default$windows.data.bluelightreduction.bluelightreductionstate\\" + @"windows.data.bluelightreduction.bluelightreductionstate", "Data"); + private readonly RegistryWatcher _nightLightSettingsWatcher = new(WatchedRegistry.CurrentUser, + @"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CloudStore\\" + + @"Store\\DefaultAccount\\Current\\default$windows.data.bluelightreduction.settings\\" + + @"windows.data.bluelightreduction.settings", "Data"); private readonly RegistryWatcher _accentColorWatcher = new(WatchedRegistry.CurrentUser, @"SOFTWARE\\Microsoft\\Windows\\DWM", "AccentColor"); @@ -20,6 +25,9 @@ public override void Enable() { _nightLightStateWatcher.RegistryChanged += UpdateNightLight; _nightLightStateWatcher.StartWatching(); + + _nightLightSettingsWatcher.RegistryChanged += NightLightSettingsWatcherOnRegistryChanged; + _nightLightSettingsWatcher.StartWatching(); _accentColorWatcher.RegistryChanged += UpdateAccentColor; _accentColorWatcher.StartWatching(); @@ -86,6 +94,19 @@ private void UpdateAccentColor(object? sender, RegistryChangedEventArgs registry } } + private void NightLightSettingsWatcherOnRegistryChanged(object? sender, RegistryChangedEventArgs e) + { + var data = e.Data; + if (data is null) + { + DataModel.NightLightsStrength = 0; + return; + } + + var byteData = (byte[])data; + DataModel.NightLightsStrength = ParseNightLightStrength(byteData); + } + private static SKColor ParseDWordColor(int color) { var a = (byte)((color >> 24) & 0xFF); @@ -95,4 +116,12 @@ private static SKColor ParseDWordColor(int color) return new SKColor(r, g, b, a); } + + private static double ParseNightLightStrength(byte[] data) + { + const int min = 4832; + const int max = 26056; + var value = BitConverter.ToInt16(data, 35); + return 1 - (double)(value - min) / (max - min); + } } \ No newline at end of file diff --git a/Artemis.MediaInfo/plugin.json b/Artemis.MediaInfo/plugin.json index 94441c7..df144b9 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.2.1.0", + "Version": "1.3.0.0", "Platforms":"Windows" }