Skip to content

Commit 2748ef5

Browse files
committed
add NightLight strength value, refactors
1 parent e05c729 commit 2748ef5

7 files changed

Lines changed: 52 additions & 29 deletions

File tree

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
3+
<TargetFramework>net7.0-windows10.0.17763.0</TargetFramework>
44
<Platforms>x64</Platforms>
55
<PlatformTarget>x64</PlatformTarget>
66
<IncludeBuildOutput>false</IncludeBuildOutput>
77
<Nullable>enable</Nullable>
8+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
89
</PropertyGroup>
910

1011
<ItemGroup>
11-
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
12-
<PackageReference Include="ArtemisRGB.UI.Shared" IncludeAssets="compile;build;buildTransitive" Version="1.2023.111.4" />
13-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
14-
15-
<PackageReference Update="@(PackageReference)" IncludeAssets="compile;build" />
16-
17-
<PackageReference Include="Dubya.WindowsMediaController" Version="2.4.0" IncludeAssets="compile;lib:runtime" />
18-
<Reference Include="Artemis.Core">
19-
<HintPath>..\..\Artemis\src\Artemis.Core\bin\net6.0\Artemis.Core.dll</HintPath>
20-
<Private>false</Private>
21-
</Reference>
12+
<PackageReference Include="ArtemisRGB.UI.Shared" IncludeAssets="compile" Version="1.2023.522.4" />
13+
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.4" />
14+
<PackageReference Include="Dubya.WindowsMediaController" Version="2.5.0" />
15+
<PackageReference Include="System.Windows.Extensions" IncludeAssets="native" Version="7.0.0" />
2216
</ItemGroup>
2317

2418
<ItemGroup>
2519
<Content Include="plugin.json" CopyToOutputDirectory="PreserveNewest" />
26-
<PackageReference Include="ArtemisRGB.Plugins.BuildTask" Version="1.1.0" />
20+
<PackageReference Include="ArtemisRGB.Plugins.BuildTask" Version="2.0.0">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
2724
</ItemGroup>
2825
</Project>

Artemis.MediaInfo/DataModels/WindowsInfoDataModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Artemis.Core.ColorScience;
2-
using Artemis.Core.Modules;
1+
using Artemis.Core.Modules;
32
using SkiaSharp;
43

54
namespace Artemis.MediaInfo.DataModels;
@@ -11,6 +10,9 @@ public class WindowsInfoDataModel : DataModel
1110

1211
[DataModelProperty(Name = "Night Lights Enabled")]
1312
public bool NightLightsEnabled { get; set; }
13+
14+
[DataModelProperty(Name = "Night Light Strength")]
15+
public double NightLightsStrength { get; set; }
1416

1517
[DataModelProperty(Name = "Desktop Accent Color")]
1618
public SKColor AccentColor { get; set; } = SKColor.Empty;

Artemis.MediaInfo/MediaInfoModule.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
using System;
2-
using Artemis.Core;
1+
using Artemis.Core;
32
using Artemis.Core.Modules;
43
using System.Collections.Generic;
5-
using System.Linq;
64
using Artemis.MediaInfo.DataModels;
75
using Windows.Media.Control;
86
using Artemis.MediaInfo.MediaWatch;
97
using static WindowsMediaController.MediaManager;
10-
using static Artemis.MediaInfo.MediaInfoHelper;
8+
using static Artemis.MediaInfo.Utils.MediaInfoHelper;
119

1210
namespace Artemis.MediaInfo;
1311

Artemis.MediaInfo/MediaWatch/MediaWatcher.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Artemis.MediaInfo.MediaWatch;
1010

11+
/// <summary>
12+
/// Wrapping class that it's only dependency is Dubya.WindowsMediaController
13+
/// </summary>
1114
public class MediaWatcher
1215
{
1316
private readonly MediaManager _mediaManager = new();
@@ -65,7 +68,7 @@ private void MediaManagerOnOnFocusedSessionChanged(MediaSession? mediaSession)
6568
_currentSession = mediaSession;
6669
_currentSession.OnPlaybackStateChanged += MediaSession_OnPlaybackStateChanged;
6770
}
68-
FocusedMediaChanged?.Invoke(this, new FocusedMediaChangedEventArgs(mediaSession, null));
71+
FocusedMediaChanged?.Invoke(this, new FocusedMediaChangedEventArgs(mediaSession, mediaSession?.ControlSession.GetPlaybackInfo()));
6972
}
7073

7174
private void MediaManager_OnSessionOpened(MediaSession mediaSession)

Artemis.MediaInfo/Utils/MediaInfoHelper.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
using System;
22
using System.Threading.Tasks;
3-
using Windows.Media.Control;
43
using Windows.Storage.Streams;
54
using Artemis.Core.ColorScience;
65
using SkiaSharp;
76

8-
namespace Artemis.MediaInfo;
7+
namespace Artemis.MediaInfo.Utils;
98

109
public static class MediaInfoHelper
1110
{
12-
internal static async Task<ColorSwatch> ReadMediaColors(GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties)
13-
{
14-
return await ReadMediaColors(mediaProperties.Thumbnail);
15-
}
16-
1711
internal static async Task<ColorSwatch> ReadMediaColors(IRandomAccessStreamReference thumbnail)
1812
{
1913
var imageStream = await thumbnail.OpenReadAsync();

Artemis.MediaInfo/WindowsInfoModule.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using Artemis.Core.Modules;
34
using Artemis.MediaInfo.DataModels;
45
using Artemis.MediaInfo.Utils;
@@ -13,13 +14,20 @@ public class WindowsInfoModule : Module<WindowsInfoDataModel>
1314
@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CloudStore\\" +
1415
@"Store\\DefaultAccount\\Current\\default$windows.data.bluelightreduction.bluelightreductionstate\\" +
1516
@"windows.data.bluelightreduction.bluelightreductionstate", "Data");
17+
private readonly RegistryWatcher _nightLightSettingsWatcher = new(WatchedRegistry.CurrentUser,
18+
@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CloudStore\\" +
19+
@"Store\\DefaultAccount\\Current\\default$windows.data.bluelightreduction.settings\\" +
20+
@"windows.data.bluelightreduction.settings", "Data");
1621
private readonly RegistryWatcher _accentColorWatcher = new(WatchedRegistry.CurrentUser,
1722
@"SOFTWARE\\Microsoft\\Windows\\DWM", "AccentColor");
1823

1924
public override void Enable()
2025
{
2126
_nightLightStateWatcher.RegistryChanged += UpdateNightLight;
2227
_nightLightStateWatcher.StartWatching();
28+
29+
_nightLightSettingsWatcher.RegistryChanged += NightLightSettingsWatcherOnRegistryChanged;
30+
_nightLightSettingsWatcher.StartWatching();
2331

2432
_accentColorWatcher.RegistryChanged += UpdateAccentColor;
2533
_accentColorWatcher.StartWatching();
@@ -86,6 +94,19 @@ private void UpdateAccentColor(object? sender, RegistryChangedEventArgs registry
8694
}
8795
}
8896

97+
private void NightLightSettingsWatcherOnRegistryChanged(object? sender, RegistryChangedEventArgs e)
98+
{
99+
var data = e.Data;
100+
if (data is null)
101+
{
102+
DataModel.NightLightsStrength = 0;
103+
return;
104+
}
105+
106+
var byteData = (byte[])data;
107+
DataModel.NightLightsStrength = ParseNightLightStrength(byteData);
108+
}
109+
89110
private static SKColor ParseDWordColor(int color)
90111
{
91112
var a = (byte)((color >> 24) & 0xFF);
@@ -95,4 +116,12 @@ private static SKColor ParseDWordColor(int color)
95116

96117
return new SKColor(r, g, b, a);
97118
}
119+
120+
private static double ParseNightLightStrength(byte[] data)
121+
{
122+
const int min = 4832;
123+
const int max = 26056;
124+
var value = BitConverter.ToInt16(data, 35);
125+
return 1 - (double)(value - min) / (max - min);
126+
}
98127
}

Artemis.MediaInfo/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"Main": "Artemis.MediaInfo.dll",
77
"Name": "Media Info",
88
"Repository": "https://github.com/Aytackydln/Artemis.MediaInfo",
9-
"Version": "1.2.1.0",
9+
"Version": "1.3.0.0",
1010
"Platforms":"Windows"
1111
}

0 commit comments

Comments
 (0)