返回提交历史
Modified
HaloPixelToolBox/HaloPixelToolBox/App.xaml.cs
+1
-0
Modified
HaloPixelToolBox/HaloPixelToolBox/Profiles/CrossVersionProfiles/CloudMusicLyricsProfile.cs
+49
-1
Modified
HaloPixelToolBox/HaloPixelToolBox/Profiles/CrossVersionProfiles/SpotifyLyricsProfile.cs
+49
-1
Modified
HaloPixelToolBox/HaloPixelToolBox/Utilities/SpotifyLyricsReader.cs
+39
-17
Modified
HaloPixelToolBox/HaloPixelToolBox/ViewModels/CloudMusicLyricsToolPageViewModel.cs
+191
-36
Added
HaloPixelToolBox/HaloPixelToolBox/ViewModels/DefaultSettingsPageViewModel.cs
+130
-0
Modified
HaloPixelToolBox/HaloPixelToolBox/ViewModels/SpotifyLyricsToolPageViewModel.cs
+235
-25
Modified
HaloPixelToolBox/HaloPixelToolBox/Views/AppShellPage.xaml
+5
-0
Modified
HaloPixelToolBox/HaloPixelToolBox/Views/CloudMusicLyricsToolPage.xaml
+21
-25
Modified
HaloPixelToolBox/HaloPixelToolBox/Views/CloudMusicLyricsToolPage.xaml.cs
+38
-1
Added
HaloPixelToolBox/HaloPixelToolBox/Views/DefaultSettingsPage.xaml
+126
-0
Added
HaloPixelToolBox/HaloPixelToolBox/Views/DefaultSettingsPage.xaml.cs
+98
-0
Modified
HaloPixelToolBox/HaloPixelToolBox/Views/SpotifyLyricsToolPage.xaml
+17
-21
Modified
HaloPixelToolBox/HaloPixelToolBox/Views/SpotifyLyricsToolPage.xaml.cs
+36
-1
XFEstudio/HaloPixelToolBox
add ambient lights and pixel color editing
63cfc1b
代码差异
14 个文件
+1035
-128
@@ -46,6 +46,7 @@ public partial class App : Application
46
46
PageManager.RegisterPage(typeof(SpotifyLyricsToolPage));
47
47
PageManager.RegisterPage(typeof(MainPage));
48
48
PageManager.RegisterPage(typeof(SettingPage));
49
PageManager.RegisterPage(typeof(DefaultSettingsPage));
49
50
UnhandledException += App_UnhandledException;
50
51
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
51
52
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
@@ -44,7 +44,7 @@ public partial class CloudMusicLyricsProfile : XFEProfile
44
44
private HaloPixelUIModel defaultHaloPixelUIModel = HaloPixelUIModel.Clock;
45
45
46
46
/// <summary>
47
/// 是否开启屏幕颜色同步
47
/// 是否开启像素屏颜色同步
48
48
/// </summary>
49
49
[ProfileProperty]
50
50
private bool enableScreenColorSync = false;
@@ -54,4 +54,52 @@ public partial class CloudMusicLyricsProfile : XFEProfile
54
54
/// </summary>
55
55
[ProfileProperty]
56
56
private bool enableAmbientColorSync = false;
57
58
/// <summary>
59
/// 歌词同步时的氛围灯效果
60
/// </summary>
61
[ProfileProperty]
62
private Core.Models.Lighting.AmbientLightEffect syncAmbientLightEffect = Core.Models.Lighting.AmbientLightEffect.Static;
63
64
/// <summary>
65
/// 默认/暂停时的氛围灯效果
66
/// </summary>
67
[ProfileProperty]
68
private Core.Models.Lighting.AmbientLightEffect defaultAmbientLightEffect = Core.Models.Lighting.AmbientLightEffect.Breathing;
69
70
/// <summary>
71
/// 歌词同步时的氛围灯亮度
72
/// </summary>
73
[ProfileProperty]
74
private Core.Models.Lighting.AmbientLightBrightness syncAmbientLightBrightness = Core.Models.Lighting.AmbientLightBrightness.High;
75
76
/// <summary>
77
/// 歌词同步时的氛围灯速度
78
/// </summary>
79
[ProfileProperty]
80
private int syncAmbientLightSpeed = 5;
81
82
/// <summary>
83
/// 暂停时的氛围灯亮度
84
/// </summary>
85
[ProfileProperty]
86
private Core.Models.Lighting.AmbientLightBrightness defaultAmbientLightBrightness = Core.Models.Lighting.AmbientLightBrightness.High;
87
88
/// <summary>
89
/// 暂停时的氛围灯速度
90
/// </summary>
91
[ProfileProperty]
92
private int defaultAmbientLightSpeed = 5;
93
94
/// <summary>
95
/// 暂停时的氛围灯颜色 Hex
96
/// </summary>
97
[ProfileProperty]
98
private string defaultAmbientLightColor = "#F0B4C8";
99
100
/// <summary>
101
/// 暂停时的像素屏颜色 Hex
102
/// </summary>
103
[ProfileProperty]
104
private string defaultScreenColor = "#F0B4C8";
57
105
}
@@ -39,7 +39,7 @@ public partial class SpotifyLyricsProfile : XFEProfile
39
39
private HaloPixelUIModel defaultHaloPixelUIModel = HaloPixelUIModel.Clock;
40
40
41
41
/// <summary>
42
/// 是否开启屏幕颜色同步
42
/// 是否开启像素屏颜色同步
43
43
/// </summary>
44
44
[ProfileProperty]
45
45
private bool enableScreenColorSync = false;
@@ -49,4 +49,52 @@ public partial class SpotifyLyricsProfile : XFEProfile
49
49
/// </summary>
50
50
[ProfileProperty]
51
51
private bool enableAmbientColorSync = false;
52
53
/// <summary>
54
/// 歌词同步时的氛围灯效果
55
/// </summary>
56
[ProfileProperty]
57
private Core.Models.Lighting.AmbientLightEffect syncAmbientLightEffect = Core.Models.Lighting.AmbientLightEffect.Static;
58
59
/// <summary>
60
/// 默认/暂停时的氛围灯效果
61
/// </summary>
62
[ProfileProperty]
63
private Core.Models.Lighting.AmbientLightEffect defaultAmbientLightEffect = Core.Models.Lighting.AmbientLightEffect.Breathing;
64
65
/// <summary>
66
/// 歌词同步时的氛围灯亮度
67
/// </summary>
68
[ProfileProperty]
69
private Core.Models.Lighting.AmbientLightBrightness syncAmbientLightBrightness = Core.Models.Lighting.AmbientLightBrightness.High;
70
71
/// <summary>
72
/// 歌词同步时的氛围灯速度
73
/// </summary>
74
[ProfileProperty]
75
private int syncAmbientLightSpeed = 5;
76
77
/// <summary>
78
/// 暂停时的氛围灯亮度
79
/// </summary>
80
[ProfileProperty]
81
private Core.Models.Lighting.AmbientLightBrightness defaultAmbientLightBrightness = Core.Models.Lighting.AmbientLightBrightness.High;
82
83
/// <summary>
84
/// 暂停时的氛围灯速度
85
/// </summary>
86
[ProfileProperty]
87
private int defaultAmbientLightSpeed = 5;
88
89
/// <summary>
90
/// 暂停时的氛围灯颜色 Hex
91
/// </summary>
92
[ProfileProperty]
93
private string defaultAmbientLightColor = "#F0B4C8";
94
95
/// <summary>
96
/// 暂停时的像素屏颜色 Hex
97
/// </summary>
98
[ProfileProperty]
99
private string defaultScreenColor = "#F0B4C8";
52
100
}
@@ -118,9 +118,27 @@ public class SpotifyLyricsReader
118
118
119
119
private DateTimeOffset _songStartTime = DateTimeOffset.Now;
120
120
private bool _isSmtcSynced = false;
121
private string _lastColorTitle = string.Empty;
121
122
122
123
public (byte R, byte G, byte B)? CurrentAlbumColor { get; private set; }
123
124
125
public bool IsPlaying
126
{
127
get
128
{
129
if (_currentSession != null)
130
{
131
try
132
{
133
var playback = _currentSession.GetPlaybackInfo();
134
return playback.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing;
135
}
136
catch { }
137
}
138
return false;
139
}
140
}
141
124
142
public static async Task<(byte R, byte G, byte B)?> GetDominantColorAsync(Windows.Storage.Streams.IRandomAccessStreamReference thumbnail)
125
143
{
126
144
try
@@ -355,23 +373,27 @@ public class SpotifyLyricsReader
355
373
_isSmtcSynced = true;
356
374
Console.WriteLine($"SMTC Sync Achieved for: {_currentArtist} - {_currentTitle} (Duration: {_currentDuration}s)");
357
375
358
if (media.Thumbnail != null)
359
{
360
var color = await GetDominantColorAsync(media.Thumbnail);
361
if (color.HasValue)
362
{
363
CurrentAlbumColor = color.Value;
364
Console.WriteLine($"Extracted album dominant color: RGB({color.Value.R}, {color.Value.G}, {color.Value.B})");
365
}
366
else
367
{
368
Console.WriteLine("GetDominantColorAsync returned null for the thumbnail.");
369
}
370
}
371
else
372
{
373
Console.WriteLine("media.Thumbnail is null for this track.");
374
}
376
if (media.Thumbnail != null)
377
{
378
if (_lastColorTitle != media.Title)
379
{
380
_lastColorTitle = media.Title;
381
var color = await GetDominantColorAsync(media.Thumbnail);
382
if (color.HasValue)
383
{
384
CurrentAlbumColor = color.Value;
385
Console.WriteLine($"Extracted album dominant color: RGB({color.Value.R}, {color.Value.G}, {color.Value.B})");
386
}
387
else
388
{
389
Console.WriteLine("GetDominantColorAsync returned null for the thumbnail.");
390
}
391
}
392
}
393
else
394
{
395
Console.WriteLine("media.Thumbnail is null for this track.");
396
}
375
397
}
376
398
else
377
399
{
@@ -31,6 +31,12 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
31
31
[ObservableProperty]
32
32
private bool enableAmbientColorSync = CloudMusicLyricsProfile.EnableAmbientColorSync;
33
33
[ObservableProperty]
34
private Core.Models.Lighting.AmbientLightEffect syncAmbientLightEffect = CloudMusicLyricsProfile.SyncAmbientLightEffect;
35
[ObservableProperty]
36
private Core.Models.Lighting.AmbientLightBrightness syncAmbientLightBrightness = CloudMusicLyricsProfile.SyncAmbientLightBrightness;
37
[ObservableProperty]
38
private int syncAmbientLightSpeed = CloudMusicLyricsProfile.SyncAmbientLightSpeed;
39
[ObservableProperty]
34
40
private string cloudMusicVersion = string.Empty;
35
41
[ObservableProperty]
36
42
private string supportedVersion = CloudMusicLyricsReader.VersionResolverDictionary.Keys.FirstOrDefault() ?? string.Empty;
@@ -59,12 +65,61 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
59
65
}
60
66
61
67
private bool _forceRefresh;
68
private bool _forcePauseLightRefresh;
69
private bool _forcePauseScreenRefresh;
70
private bool _forcePauseUIModelRefresh;
71
private bool _isClockUI;
62
72
63
73
public void OnNavigatedTo()
64
74
{
65
75
_forceRefresh = true;
66
76
}
67
77
78
public static (byte R, byte G, byte B) ParseHexColor(string hex)
79
{
80
try
81
{
82
if (hex.StartsWith("#"))
83
hex = hex.Substring(1);
84
if (hex.Length == 6)
85
{
86
byte r = Convert.ToByte(hex.Substring(0, 2), 16);
87
byte g = Convert.ToByte(hex.Substring(2, 2), 16);
88
byte b = Convert.ToByte(hex.Substring(4, 2), 16);
89
return (r, g, b);
90
}
91
}
92
catch { }
93
return (0xf0, 0xb4, 0xc8); // default fallback color
94
}
95
96
public void ForcePauseLightRefresh()
97
{
98
if (_isClockUI)
99
{
100
_forcePauseLightRefresh = true;
101
Console.WriteLine("[DEBUG] NetEase ForcePauseLightRefresh invoked");
102
}
103
}
104
105
public void ForcePauseScreenRefresh()
106
{
107
if (_isClockUI)
108
{
109
_forcePauseScreenRefresh = true;
110
Console.WriteLine("[DEBUG] NetEase ForcePauseScreenRefresh invoked");
111
}
112
}
113
114
public void ForcePauseUIModelRefresh()
115
{
116
if (_isClockUI)
117
{
118
_forcePauseUIModelRefresh = true;
119
Console.WriteLine("[DEBUG] NetEase ForcePauseUIModelRefresh invoked");
120
}
121
}
122
68
123
partial void OnEnableCloudMusicLyricsChanged(bool value)
69
124
{
70
125
CloudMusicLyricsProfile.EnableCloudMusicLyrics = value;
@@ -85,22 +140,66 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
85
140
}
86
141
87
142
partial void OnSwitchBackWhenPauseChanged(bool value) => CloudMusicLyricsProfile.SwitchBackWhenPause = value;
88
89
143
partial void OnSwitchBackTimeoutChanged(int value) => CloudMusicLyricsProfile.SwitchBackTimeout = value;
144
90
145
partial void OnEnableScreenColorSyncChanged(bool value)
91
146
{
92
147
CloudMusicLyricsProfile.EnableScreenColorSync = value;
93
_forceRefresh = true;
148
if (!_isClockUI)
149
_forceRefresh = true;
94
150
}
151
95
152
partial void OnEnableAmbientColorSyncChanged(bool value)
96
153
{
97
154
CloudMusicLyricsProfile.EnableAmbientColorSync = value;
98
_forceRefresh = true;
155
if (!_isClockUI)
156
_forceRefresh = true;
157
}
158
159
partial void OnSyncAmbientLightEffectChanged(Core.Models.Lighting.AmbientLightEffect value)
160
{
161
CloudMusicLyricsProfile.SyncAmbientLightEffect = value;
162
if (!_isClockUI)
163
_forceRefresh = true;
164
}
165
166
partial void OnSyncAmbientLightBrightnessChanged(Core.Models.Lighting.AmbientLightBrightness value)
167
{
168
CloudMusicLyricsProfile.SyncAmbientLightBrightness = value;
169
if (!_isClockUI)
170
_forceRefresh = true;
171
}
172
173
partial void OnSyncAmbientLightSpeedChanged(int value)
174
{
175
CloudMusicLyricsProfile.SyncAmbientLightSpeed = value;
176
if (!_isClockUI)
177
_forceRefresh = true;
99
178
}
100
179
101
180
private Windows.Media.Control.GlobalSystemMediaTransportControlsSessionManager? _smtcManager;
102
181
private Windows.Media.Control.GlobalSystemMediaTransportControlsSession? _cloudMusicSession;
103
182
public (byte R, byte G, byte B)? CurrentAlbumColor { get; private set; }
183
private string _currentTitle = string.Empty;
184
private string _currentArtist = string.Empty;
185
186
public bool IsPlaying
187
{
188
get
189
{
190
if (_cloudMusicSession == null) return false;
191
try
192
{
193
var playbackInfo = _cloudMusicSession.GetPlaybackInfo();
194
return playbackInfo?.PlaybackStatus == Windows.Media.Control.GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing;
195
}
196
catch {}
197
return false;
198
}
199
}
200
201
public string CurrentTitle => _currentTitle;
202
public string CurrentArtist => _currentArtist;
104
203
105
204
private async Task InitSmtcAsync()
106
205
{
@@ -120,16 +219,7 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
120
219
{
121
220
if (_smtcManager == null) return;
122
221
var sessions = _smtcManager.GetSessions();
123
Windows.Media.Control.GlobalSystemMediaTransportControlsSession? targetSession = null;
124
foreach (var s in sessions)
125
{
126
if (s.SourceAppUserModelId.Contains("cloudmusic", StringComparison.OrdinalIgnoreCase))
127
{
128
targetSession = s;
129
break;
130
}
131
}
132
222
var targetSession = sessions.FirstOrDefault(x => x.SourceAppUserModelId.Contains("cloudmusic", StringComparison.OrdinalIgnoreCase));
133
223
if (targetSession != _cloudMusicSession)
134
224
{
135
225
if (_cloudMusicSession != null)
@@ -156,13 +246,18 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
156
246
try
157
247
{
158
248
var media = await _cloudMusicSession.TryGetMediaPropertiesAsync();
159
if (media?.Thumbnail != null)
249
if (media != null)
160
250
{
161
var color = await SpotifyLyricsReader.GetDominantColorAsync(media.Thumbnail);
162
if (color.HasValue)
251
_currentTitle = media.Title ?? string.Empty;
252
_currentArtist = media.Artist ?? string.Empty;
253
if (media.Thumbnail != null)
163
254
{
164
CurrentAlbumColor = color.Value;
165
Console.WriteLine($"CloudMusic extracted album color: RGB({color.Value.R}, {color.Value.G}, {color.Value.B})");
255
var color = await SpotifyLyricsReader.GetDominantColorAsync(media.Thumbnail);
256
if (color.HasValue)
257
{
258
CurrentAlbumColor = color.Value;
259
Console.WriteLine($"CloudMusic extracted album color: RGB({color.Value.R}, {color.Value.G}, {color.Value.B})");
260
}
166
261
}
167
262
}
168
263
}
@@ -261,7 +356,7 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
261
356
}
262
357
while (true)
263
358
{
264
bool isClockUI = false;
359
_isClockUI = false;
265
360
int time = 0;
266
361
try
267
362
{
@@ -269,7 +364,10 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
269
364
{
270
365
Console.WriteLine("[DEBUG]设备均在线,准备进入主循环");
271
366
string lastRead = string.Empty;
367
string lastTrackTitle = string.Empty;
368
string lastTrackArtist = string.Empty;
272
369
bool scrolled = false;
370
bool wasPlaying = false;
273
371
(byte R, byte G, byte B) lastScreenColor = (0, 0, 0);
274
372
(byte R, byte G, byte B) lastAmbientColor = (0, 0, 0);
275
373
while (true)
@@ -279,6 +377,29 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
279
377
if (!DeviceReady || !CloudMusicReady || !EnableCloudMusicLyrics)
280
378
break;
281
379
380
bool isPlaying = IsPlaying;
381
bool trackChanged = lastTrackTitle != CurrentTitle || lastTrackArtist != CurrentArtist;
382
bool lyricsChanged = Reader.TryReadLyrics(out var lyrics) && lastRead != lyrics;
383
384
if (isPlaying && (_isClockUI || trackChanged))
385
{
386
if (!wasPlaying && isPlaying)
387
{
388
_isClockUI = false;
389
_forceRefresh = true;
390
time = 0;
391
}
392
else if (lyricsChanged || trackChanged)
393
{
394
_isClockUI = false;
395
_forceRefresh = true;
396
time = 0;
397
}
398
}
399
wasPlaying = isPlaying;
400
lastTrackTitle = CurrentTitle ?? string.Empty;
401
lastTrackArtist = CurrentArtist ?? string.Empty;
402
282
403
var albumColor = CurrentAlbumColor;
283
404
284
405
// 1. Determine screen text color
@@ -296,9 +417,8 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
296
417
}
297
418
298
419
bool colorChanged = lastScreenColor != screenColor || lastAmbientColor != ambientColor;
299
bool lyricsChanged = Reader.TryReadLyrics(out var lyrics) && lastRead != lyrics;
300
420
301
if (lyricsChanged || colorChanged || _forceRefresh)
421
if (!_isClockUI && (lyricsChanged || colorChanged || _forceRefresh))
302
422
{
303
423
_forceRefresh = false;
304
424
lastScreenColor = screenColor;
@@ -333,7 +453,11 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
333
453
{
334
454
Console.WriteLine($"已读取到歌词:{lyrics}");
335
455
lastRead = lyrics;
336
isClockUI = false;
456
if (_isClockUI)
457
{
458
_isClockUI = false;
459
_forceRefresh = true;
460
}
337
461
time = 0;
338
462
if (scrolled)
339
463
{
@@ -355,38 +479,69 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
355
479
}
356
480
await Task.Delay(50);
357
481
time += 50;
358
if (!isClockUI && time >= CloudMusicLyricsProfile.SwitchBackTimeout * 1000)
482
if (!_isClockUI && time >= CloudMusicLyricsProfile.SwitchBackTimeout * 1000)
359
483
{
360
isClockUI = true;
361
(byte R, byte G, byte B) finalScreenColor = ((byte)0xf0, (byte)0xb4, (byte)0xc8);
362
if (EnableScreenColorSync && CurrentAlbumColor.HasValue)
484
_isClockUI = true;
485
(byte R, byte G, byte B) finalScreenColor = ParseHexColor(CloudMusicLyricsProfile.DefaultScreenColor);
486
(byte R, byte G, byte B) finalAmbientColor = ParseHexColor(CloudMusicLyricsProfile.DefaultAmbientLightColor);
487
HidPacketBuilder.CurrentColor = finalScreenColor;
488
try
363
489
{
364
finalScreenColor = CurrentAlbumColor.Value;
490
Device.SetAmbientLight(new Core.Models.Lighting.AmbientLightOptions
491
{
492
Effect = CloudMusicLyricsProfile.DefaultAmbientLightEffect,
493
Color = new Core.Models.Display.HaloPixelColor(finalAmbientColor.R, finalAmbientColor.G, finalAmbientColor.B),
494
Brightness = CloudMusicLyricsProfile.DefaultAmbientLightBrightness,
495
Speed = (byte)CloudMusicLyricsProfile.DefaultAmbientLightSpeed
496
});
365
497
}
366
(byte R, byte G, byte B) finalAmbientColor = ((byte)0xf0, (byte)0xb4, (byte)0xc8);
367
if (EnableAmbientColorSync && CurrentAlbumColor.HasValue)
498
catch {}
499
try
368
500
{
369
finalAmbientColor = CurrentAlbumColor.Value;
501
Device.SetPixelScreenColor(new Core.Models.Display.HaloPixelColor(finalScreenColor.R, finalScreenColor.G, finalScreenColor.B));
370
502
}
371
HidPacketBuilder.CurrentColor = finalScreenColor;
503
catch {}
504
Device.SetUIModel(CloudMusicLyricsProfile.DefaultHaloPixelUIModel);
505
Console.WriteLine("已切换至时钟界面");
506
}
507
508
if (_isClockUI && _forcePauseLightRefresh)
509
{
510
_forcePauseLightRefresh = false;
511
(byte R, byte G, byte B) finalAmbientColor = ParseHexColor(CloudMusicLyricsProfile.DefaultAmbientLightColor);
372
512
try
373
513
{
374
514
Device.SetAmbientLight(new Core.Models.Lighting.AmbientLightOptions
375
515
{
376
Effect = Core.Models.Lighting.AmbientLightEffect.Static,
516
Effect = CloudMusicLyricsProfile.DefaultAmbientLightEffect,
377
517
Color = new Core.Models.Display.HaloPixelColor(finalAmbientColor.R, finalAmbientColor.G, finalAmbientColor.B),
378
Brightness = Core.Models.Lighting.AmbientLightBrightness.High,
379
Speed = 5
518
Brightness = CloudMusicLyricsProfile.DefaultAmbientLightBrightness,
519
Speed = (byte)CloudMusicLyricsProfile.DefaultAmbientLightSpeed
380
520
});
381
521
}
382
522
catch {}
523
}
524
525
if (_isClockUI && _forcePauseScreenRefresh)
526
{
527
_forcePauseScreenRefresh = false;
528
(byte R, byte G, byte B) finalScreenColor = ParseHexColor(CloudMusicLyricsProfile.DefaultScreenColor);
529
HidPacketBuilder.CurrentColor = finalScreenColor;
383
530
try
384
531
{
385
532
Device.SetPixelScreenColor(new Core.Models.Display.HaloPixelColor(finalScreenColor.R, finalScreenColor.G, finalScreenColor.B));
386
533
}
387
534
catch {}
388
Device.SetUIModel(CloudMusicLyricsProfile.DefaultHaloPixelUIModel);
389
Console.WriteLine("已切换至时钟界面");
535
}
536
537
if (_isClockUI && _forcePauseUIModelRefresh)
538
{
539
_forcePauseUIModelRefresh = false;
540
try
541
{
542
Device.SetUIModel(CloudMusicLyricsProfile.DefaultHaloPixelUIModel);
543
}
544
catch {}
390
545
}
391
546
}
392
547
catch (Exception ex)
@@ -0,0 +1,130 @@
1
using CommunityToolkit.Mvvm.ComponentModel;
2
using HaloPixelToolBox.Core.Models;
3
using HaloPixelToolBox.Core.Models.Lighting;
4
using HaloPixelToolBox.Profiles.CrossVersionProfiles;
5
using XFEExtension.NetCore.WinUIHelper.Interface.Services;
6
using XFEExtension.NetCore.WinUIHelper.Implements;
7
using XFEExtension.NetCore.WinUIHelper.Utilities;
8
using System;
9
10
namespace HaloPixelToolBox.ViewModels;
11
12
public partial class DefaultSettingsPageViewModel : ServiceBaseViewModelBase<string>
13
{
14
[ObservableProperty]
15
private bool switchBackWhenPause = SpotifyLyricsProfile.SwitchBackWhenPause;
16
17
[ObservableProperty]
18
private int switchBackTimeout = SpotifyLyricsProfile.SwitchBackTimeout;
19
20
[ObservableProperty]
21
private HaloPixelUIModel defaultHaloPixelUIModel = SpotifyLyricsProfile.DefaultHaloPixelUIModel;
22
23
[ObservableProperty]
24
private AmbientLightEffect defaultAmbientLightEffect = SpotifyLyricsProfile.DefaultAmbientLightEffect;
25
26
[ObservableProperty]
27
private AmbientLightBrightness defaultAmbientLightBrightness = SpotifyLyricsProfile.DefaultAmbientLightBrightness;
28
29
[ObservableProperty]
30
private int defaultAmbientLightSpeed = SpotifyLyricsProfile.DefaultAmbientLightSpeed;
31
32
[ObservableProperty]
33
private string defaultAmbientLightColor = SpotifyLyricsProfile.DefaultAmbientLightColor;
34
35
[ObservableProperty]
36
private string defaultScreenColor = SpotifyLyricsProfile.DefaultScreenColor;
37
38
public ISettingService SettingService { get; } = ServiceManager.GetService<ISettingService>();
39
40
partial void OnSwitchBackWhenPauseChanged(bool value)
41
{
42
SpotifyLyricsProfile.SwitchBackWhenPause = value;
43
CloudMusicLyricsProfile.SwitchBackWhenPause = value;
44
}
45
46
partial void OnSwitchBackTimeoutChanged(int value)
47
{
48
SpotifyLyricsProfile.SwitchBackTimeout = value;
49
CloudMusicLyricsProfile.SwitchBackTimeout = value;
50
}
51
52
partial void OnDefaultHaloPixelUIModelChanged(HaloPixelUIModel value)
53
{
54
SpotifyLyricsProfile.DefaultHaloPixelUIModel = value;
55
CloudMusicLyricsProfile.DefaultHaloPixelUIModel = value;
56
SpotifyLyricsToolPage.Current?.ViewModel?.ForcePauseUIModelRefresh();
57
CloudMusicLyricsToolPage.Current?.ViewModel?.ForcePauseUIModelRefresh();
58
}
59
60
partial void OnDefaultAmbientLightEffectChanged(AmbientLightEffect value)
61
{
62
SpotifyLyricsProfile.DefaultAmbientLightEffect = value;
63
CloudMusicLyricsProfile.DefaultAmbientLightEffect = value;
64
SpotifyLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
65
CloudMusicLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
66
}
67
68
partial void OnDefaultAmbientLightBrightnessChanged(AmbientLightBrightness value)
69
{
70
SpotifyLyricsProfile.DefaultAmbientLightBrightness = value;
71
CloudMusicLyricsProfile.DefaultAmbientLightBrightness = value;
72
OnPropertyChanged(nameof(DefaultAmbientLightBrightnessIndex));
73
SpotifyLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
74
CloudMusicLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
75
}
76
77
partial void OnDefaultAmbientLightSpeedChanged(int value)
78
{
79
SpotifyLyricsProfile.DefaultAmbientLightSpeed = value;
80
CloudMusicLyricsProfile.DefaultAmbientLightSpeed = value;
81
SpotifyLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
82
CloudMusicLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
83
}
84
85
partial void OnDefaultAmbientLightColorChanged(string value)
86
{
87
SpotifyLyricsProfile.DefaultAmbientLightColor = value;
88
CloudMusicLyricsProfile.DefaultAmbientLightColor = value;
89
SpotifyLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
90
CloudMusicLyricsToolPage.Current?.ViewModel?.ForcePauseLightRefresh();
91
}
92
93
partial void OnDefaultScreenColorChanged(string value)
94
{
95
SpotifyLyricsProfile.DefaultScreenColor = value;
96
CloudMusicLyricsProfile.DefaultScreenColor = value;
97
SpotifyLyricsToolPage.Current?.ViewModel?.ForcePauseScreenRefresh();
98
CloudMusicLyricsToolPage.Current?.ViewModel?.ForcePauseScreenRefresh();
99
}
100
101
public int DefaultAmbientLightBrightnessIndex
102
{
103
get => (int)DefaultAmbientLightBrightness - 1;
104
set
105
{
106
if (value >= 0 && value <= 2)
107
{
108
DefaultAmbientLightBrightness = (AmbientLightBrightness)(value + 1);
109
}
110
}
111
}
112
113
public static (byte R, byte G, byte B) ParseHexColor(string hex)
114
{
115
try
116
{
117
if (hex.StartsWith("#"))
118
hex = hex.Substring(1);
119
if (hex.Length == 6)
120
{
121
byte r = Convert.ToByte(hex.Substring(0, 2), 16);
122
byte g = Convert.ToByte(hex.Substring(2, 2), 16);
123
byte b = Convert.ToByte(hex.Substring(4, 2), 16);
124
return (r, g, b);
125
}
126
}
127
catch { }
128
return (0xf0, 0xb4, 0xc8); // default fallback color
129
}
130
}
@@ -29,6 +29,22 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
29
29
[ObservableProperty]
30
30
private bool enableAmbientColorSync = SpotifyLyricsProfile.EnableAmbientColorSync;
31
31
[ObservableProperty]
32
private Core.Models.Lighting.AmbientLightEffect syncAmbientLightEffect = SpotifyLyricsProfile.SyncAmbientLightEffect;
33
[ObservableProperty]
34
private Core.Models.Lighting.AmbientLightEffect defaultAmbientLightEffect = SpotifyLyricsProfile.DefaultAmbientLightEffect;
35
[ObservableProperty]
36
private Core.Models.Lighting.AmbientLightBrightness syncAmbientLightBrightness = SpotifyLyricsProfile.SyncAmbientLightBrightness;
37
[ObservableProperty]
38
private int syncAmbientLightSpeed = SpotifyLyricsProfile.SyncAmbientLightSpeed;
39
[ObservableProperty]
40
private Core.Models.Lighting.AmbientLightBrightness defaultAmbientLightBrightness = SpotifyLyricsProfile.DefaultAmbientLightBrightness;
41
[ObservableProperty]
42
private int defaultAmbientLightSpeed = SpotifyLyricsProfile.DefaultAmbientLightSpeed;
43
[ObservableProperty]
44
private string defaultAmbientLightColor = SpotifyLyricsProfile.DefaultAmbientLightColor;
45
[ObservableProperty]
46
private string defaultScreenColor = SpotifyLyricsProfile.DefaultScreenColor;
47
[ObservableProperty]
32
48
private string spotifyTrackInfo = "未检测到播放中的歌曲";
33
49
34
50
public HaloPixelDevice Device { get; set; } = new();
@@ -37,6 +53,28 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
37
53
public ISettingService SettingService { get; } = ServiceManager.GetService<ISettingService>();
38
54
39
55
private bool _forceRefresh;
56
private bool _forcePauseLightRefresh;
57
private bool _forcePauseScreenRefresh;
58
private bool _forcePauseUIModelRefresh;
59
private bool _isClockUI;
60
61
public static (byte R, byte G, byte B) ParseHexColor(string hex)
62
{
63
try
64
{
65
if (hex.StartsWith("#"))
66
hex = hex.Substring(1);
67
if (hex.Length == 6)
68
{
69
byte r = Convert.ToByte(hex.Substring(0, 2), 16);
70
byte g = Convert.ToByte(hex.Substring(2, 2), 16);
71
byte b = Convert.ToByte(hex.Substring(4, 2), 16);
72
return (r, g, b);
73
}
74
}
75
catch { }
76
return (0xf0, 0xb4, 0xc8); // default fallback color
77
}
40
78
41
79
public void OnNavigatedTo()
42
80
{
@@ -46,7 +84,7 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
46
84
partial void OnEnableSpotifyLyricsChanged(bool value)
47
85
{
48
86
SpotifyLyricsProfile.EnableSpotifyLyrics = value;
49
if (value)
87
if (value && !_isClockUI)
50
88
_forceRefresh = true;
51
89
}
52
90
partial void OnSwitchBackWhenPauseChanged(bool value) => SpotifyLyricsProfile.SwitchBackWhenPause = value;
@@ -54,12 +92,110 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
54
92
partial void OnEnableScreenColorSyncChanged(bool value)
55
93
{
56
94
SpotifyLyricsProfile.EnableScreenColorSync = value;
57
_forceRefresh = true;
95
if (!_isClockUI)
96
_forceRefresh = true;
58
97
}
59
98
partial void OnEnableAmbientColorSyncChanged(bool value)
60
99
{
61
100
SpotifyLyricsProfile.EnableAmbientColorSync = value;
62
_forceRefresh = true;
101
if (!_isClockUI)
102
_forceRefresh = true;
103
}
104
partial void OnSyncAmbientLightEffectChanged(Core.Models.Lighting.AmbientLightEffect value)
105
{
106
SpotifyLyricsProfile.SyncAmbientLightEffect = value;
107
if (!_isClockUI)
108
_forceRefresh = true;
109
}
110
partial void OnDefaultAmbientLightEffectChanged(Core.Models.Lighting.AmbientLightEffect value)
111
{
112
SpotifyLyricsProfile.DefaultAmbientLightEffect = value;
113
if (_isClockUI)
114
_forcePauseLightRefresh = true;
115
}
116
partial void OnSyncAmbientLightBrightnessChanged(Core.Models.Lighting.AmbientLightBrightness value)
117
{
118
SpotifyLyricsProfile.SyncAmbientLightBrightness = value;
119
if (!_isClockUI)
120
_forceRefresh = true;
121
}
122
partial void OnSyncAmbientLightSpeedChanged(int value)
123
{
124
SpotifyLyricsProfile.SyncAmbientLightSpeed = value;
125
if (!_isClockUI)
126
_forceRefresh = true;
127
}
128
partial void OnDefaultAmbientLightBrightnessChanged(Core.Models.Lighting.AmbientLightBrightness value)
129
{
130
SpotifyLyricsProfile.DefaultAmbientLightBrightness = value;
131
OnPropertyChanged(nameof(DefaultAmbientLightBrightnessIndex));
132
if (_isClockUI)
133
_forcePauseLightRefresh = true;
134
}
135
partial void OnDefaultAmbientLightSpeedChanged(int value)
136
{
137
SpotifyLyricsProfile.DefaultAmbientLightSpeed = value;
138
if (_isClockUI)
139
_forcePauseLightRefresh = true;
140
}
141
partial void OnDefaultAmbientLightColorChanged(string value)
142
{
143
Console.WriteLine($"[DEBUG] VM OnDefaultAmbientLightColorChanged called, value={value}, _isClockUI={_isClockUI}");
144
SpotifyLyricsProfile.DefaultAmbientLightColor = value;
145
if (_isClockUI)
146
{
147
_forcePauseLightRefresh = true;
148
Console.WriteLine("[DEBUG] Set _forcePauseLightRefresh = true");
149
}
150
}
151
partial void OnDefaultScreenColorChanged(string value)
152
{
153
Console.WriteLine($"[DEBUG] VM OnDefaultScreenColorChanged called, value={value}, _isClockUI={_isClockUI}");
154
SpotifyLyricsProfile.DefaultScreenColor = value;
155
if (_isClockUI)
156
{
157
_forcePauseScreenRefresh = true;
158
Console.WriteLine("[DEBUG] Set _forcePauseScreenRefresh = true");
159
}
160
}
161
162
public int DefaultAmbientLightBrightnessIndex
163
{
164
get => (int)DefaultAmbientLightBrightness - 1;
165
set
166
{
167
if (value >= 0 && value <= 2)
168
{
169
DefaultAmbientLightBrightness = (Core.Models.Lighting.AmbientLightBrightness)(value + 1);
170
}
171
}
172
}
173
174
public void ForcePauseLightRefresh()
175
{
176
if (_isClockUI)
177
{
178
_forcePauseLightRefresh = true;
179
Console.WriteLine("[DEBUG] ForcePauseLightRefresh invoked");
180
}
181
}
182
183
public void ForcePauseScreenRefresh()
184
{
185
if (_isClockUI)
186
{
187
_forcePauseScreenRefresh = true;
188
Console.WriteLine("[DEBUG] ForcePauseScreenRefresh invoked");
189
}
190
}
191
192
public void ForcePauseUIModelRefresh()
193
{
194
if (_isClockUI)
195
{
196
_forcePauseUIModelRefresh = true;
197
Console.WriteLine("[DEBUG] ForcePauseUIModelRefresh invoked");
198
}
63
199
}
64
200
65
201
public SpotifyLyricsToolPageViewModel()
@@ -132,7 +268,7 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
132
268
133
269
while (true)
134
270
{
135
bool isClockUI = false;
271
_isClockUI = false;
136
272
int time = 0;
137
273
try
138
274
{
@@ -140,9 +276,15 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
140
276
{
141
277
Console.WriteLine("[DEBUG]设备均在线,准备进入主循环");
142
278
string lastRead = string.Empty;
279
string lastTrackTitle = string.Empty;
280
string lastTrackArtist = string.Empty;
143
281
bool scrolled = false;
282
bool wasPlaying = false;
144
283
(byte R, byte G, byte B) lastScreenColor = (0, 0, 0);
145
284
(byte R, byte G, byte B) lastAmbientColor = (0, 0, 0);
285
var lastAmbientLightEffect = SpotifyLyricsProfile.SyncAmbientLightEffect;
286
var lastAmbientLightBrightness = SpotifyLyricsProfile.SyncAmbientLightBrightness;
287
int lastAmbientLightSpeed = SpotifyLyricsProfile.SyncAmbientLightSpeed;
146
288
while (true)
147
289
{
148
290
try
@@ -150,6 +292,29 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
150
292
if (!DeviceReady || !SpotifyReady || !EnableSpotifyLyrics)
151
293
break;
152
294
295
bool isPlaying = Reader.IsPlaying;
296
bool trackChanged = lastTrackTitle != Reader.CurrentTitle || lastTrackArtist != Reader.CurrentArtist;
297
bool lyricsChanged = Reader.TryReadLyrics(out var lyrics) && lastRead != lyrics;
298
299
if (isPlaying && (_isClockUI || trackChanged))
300
{
301
if (!wasPlaying && isPlaying)
302
{
303
_isClockUI = false;
304
_forceRefresh = true;
305
time = 0;
306
}
307
else if (lyricsChanged || trackChanged)
308
{
309
_isClockUI = false;
310
_forceRefresh = true;
311
time = 0;
312
}
313
}
314
wasPlaying = isPlaying;
315
lastTrackTitle = Reader.CurrentTitle ?? string.Empty;
316
lastTrackArtist = Reader.CurrentArtist ?? string.Empty;
317
153
318
// Update track info text in UI
154
319
AutoNavigationParameterService.CurrentPage?.DispatcherQueue.TryEnqueue(() =>
155
320
{
@@ -172,24 +337,30 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
172
337
ambientColor = albumColor.Value;
173
338
}
174
339
340
var ambientEffect = SpotifyLyricsProfile.SyncAmbientLightEffect;
341
var ambientBrightness = SpotifyLyricsProfile.SyncAmbientLightBrightness;
342
int ambientSpeed = SpotifyLyricsProfile.SyncAmbientLightSpeed;
343
175
344
bool colorChanged = lastScreenColor != screenColor || lastAmbientColor != ambientColor;
176
bool lyricsChanged = Reader.TryReadLyrics(out var lyrics) && lastRead != lyrics;
345
bool effectChanged = lastAmbientLightEffect != ambientEffect || lastAmbientLightBrightness != ambientBrightness || lastAmbientLightSpeed != ambientSpeed;
177
346
178
if (lyricsChanged || colorChanged || _forceRefresh)
347
if (!_isClockUI && (colorChanged || effectChanged || _forceRefresh))
179
348
{
180
_forceRefresh = false;
181
349
lastScreenColor = screenColor;
182
350
lastAmbientColor = ambientColor;
351
lastAmbientLightEffect = ambientEffect;
352
lastAmbientLightBrightness = ambientBrightness;
353
lastAmbientLightSpeed = ambientSpeed;
183
354
HidPacketBuilder.CurrentColor = screenColor;
184
355
185
356
try
186
357
{
187
358
Device.SetAmbientLight(new Core.Models.Lighting.AmbientLightOptions
188
359
{
189
Effect = Core.Models.Lighting.AmbientLightEffect.Static,
360
Effect = ambientEffect,
190
361
Color = new Core.Models.Display.HaloPixelColor(ambientColor.R, ambientColor.G, ambientColor.B),
191
Brightness = Core.Models.Lighting.AmbientLightBrightness.High,
192
Speed = 5
362
Brightness = ambientBrightness,
363
Speed = (byte)ambientSpeed
193
364
});
194
365
}
195
366
catch (Exception ex)
@@ -205,12 +376,20 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
205
376
{
206
377
Console.WriteLine($"[ERROR] SetPixelScreenColor failed: {ex.Message}");
207
378
}
379
}
208
380
381
if (!_isClockUI && (lyricsChanged || _forceRefresh))
382
{
383
_forceRefresh = false;
209
384
if (lyricsChanged)
210
385
{
211
386
Console.WriteLine($"已读取到歌词:{lyrics}");
212
387
lastRead = lyrics;
213
isClockUI = false;
388
if (_isClockUI)
389
{
390
_isClockUI = false;
391
_forceRefresh = true;
392
}
214
393
time = 0;
215
394
if (scrolled)
216
395
{
@@ -232,38 +411,69 @@ public partial class SpotifyLyricsToolPageViewModel : ServiceBaseViewModelBase<s
232
411
}
233
412
await Task.Delay(50);
234
413
time += 50;
235
if (!isClockUI && time >= SpotifyLyricsProfile.SwitchBackTimeout * 1000)
414
if (!_isClockUI && time >= SpotifyLyricsProfile.SwitchBackTimeout * 1000)
236
415
{
237
isClockUI = true;
238
(byte R, byte G, byte B) finalScreenColor = ((byte)0xf0, (byte)0xb4, (byte)0xc8);
239
if (EnableScreenColorSync && Reader.CurrentAlbumColor.HasValue)
416
_isClockUI = true;
417
(byte R, byte G, byte B) finalScreenColor = ParseHexColor(SpotifyLyricsProfile.DefaultScreenColor);
418
(byte R, byte G, byte B) finalAmbientColor = ParseHexColor(SpotifyLyricsProfile.DefaultAmbientLightColor);
419
HidPacketBuilder.CurrentColor = finalScreenColor;
420
try
240
421
{
241
finalScreenColor = Reader.CurrentAlbumColor.Value;
422
Device.SetAmbientLight(new Core.Models.Lighting.AmbientLightOptions
423
{
424
Effect = SpotifyLyricsProfile.DefaultAmbientLightEffect,
425
Color = new Core.Models.Display.HaloPixelColor(finalAmbientColor.R, finalAmbientColor.G, finalAmbientColor.B),
426
Brightness = SpotifyLyricsProfile.DefaultAmbientLightBrightness,
427
Speed = (byte)SpotifyLyricsProfile.DefaultAmbientLightSpeed
428
});
242
429
}
243
(byte R, byte G, byte B) finalAmbientColor = ((byte)0xf0, (byte)0xb4, (byte)0xc8);
244
if (EnableAmbientColorSync && Reader.CurrentAlbumColor.HasValue)
430
catch {}
431
try
245
432
{
246
finalAmbientColor = Reader.CurrentAlbumColor.Value;
433
Device.SetPixelScreenColor(new Core.Models.Display.HaloPixelColor(finalScreenColor.R, finalScreenColor.G, finalScreenColor.B));
247
434
}
248
HidPacketBuilder.CurrentColor = finalScreenColor;
435
catch {}
436
Device.SetUIModel(SpotifyLyricsProfile.DefaultHaloPixelUIModel);
437
Console.WriteLine("已切换至时钟界面");
438
}
439
440
if (_isClockUI && _forcePauseLightRefresh)
441
{
442
_forcePauseLightRefresh = false;
443
(byte R, byte G, byte B) finalAmbientColor = ParseHexColor(SpotifyLyricsProfile.DefaultAmbientLightColor);
249
444
try
250
445
{
251
446
Device.SetAmbientLight(new Core.Models.Lighting.AmbientLightOptions
252
447
{
253
Effect = Core.Models.Lighting.AmbientLightEffect.Static,
448
Effect = SpotifyLyricsProfile.DefaultAmbientLightEffect,
254
449
Color = new Core.Models.Display.HaloPixelColor(finalAmbientColor.R, finalAmbientColor.G, finalAmbientColor.B),
255
Brightness = Core.Models.Lighting.AmbientLightBrightness.High,
256
Speed = 5
450
Brightness = SpotifyLyricsProfile.DefaultAmbientLightBrightness,
451
Speed = (byte)SpotifyLyricsProfile.DefaultAmbientLightSpeed
257
452
});
258
453
}
259
454
catch {}
455
}
456
457
if (_isClockUI && _forcePauseScreenRefresh)
458
{
459
_forcePauseScreenRefresh = false;
460
(byte R, byte G, byte B) finalScreenColor = ParseHexColor(SpotifyLyricsProfile.DefaultScreenColor);
461
HidPacketBuilder.CurrentColor = finalScreenColor;
260
462
try
261
463
{
262
464
Device.SetPixelScreenColor(new Core.Models.Display.HaloPixelColor(finalScreenColor.R, finalScreenColor.G, finalScreenColor.B));
263
465
}
264
466
catch {}
265
Device.SetUIModel(SpotifyLyricsProfile.DefaultHaloPixelUIModel);
266
Console.WriteLine("已切换至时钟界面");
467
}
468
469
if (_isClockUI && _forcePauseUIModelRefresh)
470
{
471
_forcePauseUIModelRefresh = false;
472
try
473
{
474
Device.SetUIModel(SpotifyLyricsProfile.DefaultHaloPixelUIModel);
475
}
476
catch {}
267
477
}
268
478
}
269
479
catch (Exception ex)
@@ -62,6 +62,11 @@
62
62
<PersonPicture ProfilePicture="{x:Bind ViewModel.UserTile}" Height="25" Width="25" HorizontalAlignment="Center"/>
63
63
<TextBlock Text="{x:Bind ViewModel.UserName, Mode=OneWay}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8,0,0,0"/>
64
64
</StackPanel>
65
<NavigationViewItem Content="默认界面" add:NavigationAddition.NavigateTo="HaloPixelToolBox.Views.DefaultSettingsPage">
66
<NavigationViewItem.Icon>
67
<FontIcon Glyph=""/>
68
</NavigationViewItem.Icon>
69
</NavigationViewItem>
65
70
<NavigationViewItem Content="设置" add:NavigationAddition.NavigateTo="HaloPixelToolBox.Views.SettingPage">
66
71
<NavigationViewItem.Icon>
67
72
<FontIcon Glyph=""/>
@@ -51,36 +51,32 @@
51
51
<controls:SettingsCard Header="开启屏幕颜色同步" Description="自动提取当前歌曲专辑封面主色并应用到像素屏歌词文本颜色">
52
52
<ToggleSwitch IsOn="{x:Bind ViewModel.EnableScreenColorSync, Mode=TwoWay}"/>
53
53
</controls:SettingsCard>
54
<controls:SettingsCard Header="开启氛围灯颜色同步" Description="自动提取当前歌曲专辑封面主色并应用到音响氛围灯/底座灯颜色">
55
<ToggleSwitch IsOn="{x:Bind ViewModel.EnableAmbientColorSync, Mode=TwoWay}"/>
56
</controls:SettingsCard>
57
<controls:SettingsExpander Header="手动输入内存地址" Description="解析使用手动输入的内存地址">
58
<ToggleSwitch x:Name="useInputedAddressToggleSwitch" IsOn="{x:Bind ViewModel.UseInputedAddress, Mode=TwoWay}"/>
54
<controls:SettingsExpander Header="开启氛围灯颜色同步" Description="自动提取当前歌曲专辑封面主色并应用到音响氛围灯/底座灯颜色">
55
<ToggleSwitch x:Name="enableAmbientColorSyncToggleSwitch" IsOn="{x:Bind ViewModel.EnableAmbientColorSync, Mode=TwoWay}"/>
59
56
<controls:SettingsExpander.Items>
60
<controls:SettingsCard Header="内存地址" Description="设置要解析的内存地址" IsEnabled="{x:Bind useInputedAddressToggleSwitch.IsOn, Mode=OneWay}">
61
<TextBox Text="{x:Bind ViewModel.InputedAddress, Mode=TwoWay}"/>
57
<controls:SettingsCard Header="氛围灯同步效果" Description="设置专辑颜色同步时的灯光效果模式" IsEnabled="{x:Bind enableAmbientColorSyncToggleSwitch.IsOn, Mode=OneWay}">
58
<ComboBox x:Name="syncAmbientLightEffectComboBox" Tag="HaloPixelToolBox.Profiles.CrossVersionProfiles.CloudMusicLyricsProfile.SyncAmbientLightEffect">
59
<ComboBoxItem Content="常亮" Tag="Static"/>
60
<ComboBoxItem Content="呼吸" Tag="Breathing"/>
61
</ComboBox>
62
</controls:SettingsCard>
63
<controls:SettingsCard Header="氛围灯同步亮度" Description="设置专辑颜色同步时的灯光亮度模式" IsEnabled="{x:Bind enableAmbientColorSyncToggleSwitch.IsOn, Mode=OneWay}">
64
<StackPanel Orientation="Horizontal" Spacing="15">
65
<RadioButton x:Name="brightnessLowRadio" Content="低" GroupName="BrightnessSyncGroup" Checked="OnBrightnessRadioChecked"/>
66
<RadioButton x:Name="brightnessMediumRadio" Content="中" GroupName="BrightnessSyncGroup" Checked="OnBrightnessRadioChecked"/>
67
<RadioButton x:Name="brightnessHighRadio" Content="高" GroupName="BrightnessSyncGroup" Checked="OnBrightnessRadioChecked"/>
68
</StackPanel>
69
</controls:SettingsCard>
70
<controls:SettingsCard Header="氛围灯同步速度" Description="设置呼吸或动态灯效的变化速度 (1-10)" IsEnabled="{x:Bind enableAmbientColorSyncToggleSwitch.IsOn, Mode=OneWay}">
71
<Slider Minimum="1" Maximum="10" StepFrequency="1" Width="150" Value="{x:Bind ViewModel.SyncAmbientLightSpeed, Mode=TwoWay}"/>
62
72
</controls:SettingsCard>
63
73
</controls:SettingsExpander.Items>
64
74
</controls:SettingsExpander>
65
<TextBlock Text="个性化" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
66
<controls:SettingsExpander Header="暂停后切换回默认界面" Description="一段时间后自动切换回时钟界面等音响自带页面">
67
<ToggleSwitch x:Name="switchBackWhenPauseToggleSwitch" IsOn="{x:Bind ViewModel.SwitchBackWhenPause, Mode=TwoWay}"/>
75
<controls:SettingsExpander Header="手动输入内存地址" Description="解析使用手动输入的内存地址">
76
<ToggleSwitch x:Name="useInputedAddressToggleSwitch" IsOn="{x:Bind ViewModel.UseInputedAddress, Mode=TwoWay}"/>
68
77
<controls:SettingsExpander.Items>
69
<controls:SettingsCard Header="暂停延迟" Description="设置多长时间后,音响切换回默认界面" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
70
<NumberBox SpinButtonPlacementMode="Compact" Value="{x:Bind ViewModel.SwitchBackTimeout, Mode=TwoWay}"/>
71
</controls:SettingsCard>
72
<controls:SettingsCard Header="暂停界面" Description="设置暂停后切换回的默认界面" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
73
<ComboBox x:Name="defaultHaloPixelUIModelComboBox" Tag="HaloPixelToolBox.Profiles.CrossVersionProfiles.CloudMusicLyricsProfile.DefaultHaloPixelUIModel">
74
<ComboBoxItem Content="时钟类" Tag="Clock"/>
75
<ComboBoxItem Content="游戏类" Tag="Game"/>
76
<ComboBoxItem Content="打工类" Tag="Work"/>
77
<ComboBoxItem Content="读书类" Tag="Read"/>
78
<ComboBoxItem Content="猫咪类" Tag="Cats"/>
79
<ComboBoxItem Content="狗狗类" Tag="Dogs"/>
80
<ComboBoxItem Content="热更类" Tag="Memes"/>
81
<ComboBoxItem Content="赛博类" Tag="Cyber"/>
82
<ComboBoxItem Content="频谱类" Tag="Waves"/>
83
</ComboBox>
78
<controls:SettingsCard Header="内存地址" Description="设置要解析的内存地址" IsEnabled="{x:Bind useInputedAddressToggleSwitch.IsOn, Mode=OneWay}">
79
<TextBox Text="{x:Bind ViewModel.InputedAddress, Mode=TwoWay}"/>
84
80
</controls:SettingsCard>
85
81
</controls:SettingsExpander.Items>
86
82
</controls:SettingsExpander>
@@ -1,5 +1,8 @@
1
1
using HaloPixelToolBox.Core.Models;
2
using HaloPixelToolBox.Core.Models.Lighting;
3
using Microsoft.UI.Xaml.Controls;
2
4
using Microsoft.UI.Xaml.Navigation;
5
using System;
3
6
using XFEExtension.NetCore.WinUIHelper.Utilities.Helper;
4
7
5
8
namespace HaloPixelToolBox.Views;
@@ -18,13 +21,47 @@ public sealed partial class CloudMusicLyricsToolPage : Page
18
21
InitializeComponent();
19
22
ViewModel.AutoNavigationParameterService.Initialize(this);
20
23
ViewModel.SettingService.AddComboBox(defaultHaloPixelTextLayoutComboBox, ProfileHelper.GetEnumProfileSaveFunc<HaloPixelTextLayout>(), ProfileHelper.GetEnumProfileLoadFuncForComboBox());
21
ViewModel.SettingService.AddComboBox(defaultHaloPixelUIModelComboBox, ProfileHelper.GetEnumProfileSaveFunc<HaloPixelUIModel>(), ProfileHelper.GetEnumProfileLoadFuncForComboBox());
24
ViewModel.SettingService.AddComboBox(syncAmbientLightEffectComboBox, ProfileHelper.GetEnumProfileSaveFunc<AmbientLightEffect>(), ProfileHelper.GetEnumProfileLoadFuncForComboBox());
22
25
ViewModel.SettingService.Initialize();
23
26
ViewModel.SettingService.RegisterEvents();
27
28
// Propagate ComboBox selection changes to ViewModel properties
29
syncAmbientLightEffectComboBox.SelectionChanged += (s, e) =>
30
{
31
if (syncAmbientLightEffectComboBox.SelectedItem is ComboBoxItem item && Enum.TryParse<AmbientLightEffect>(item.Tag?.ToString(), out var effect))
32
{
33
ViewModel.SyncAmbientLightEffect = effect;
34
}
35
};
36
37
// Initialize brightness radio buttons
38
switch (ViewModel.SyncAmbientLightBrightness)
39
{
40
case AmbientLightBrightness.Low:
41
brightnessLowRadio.IsChecked = true;
42
break;
43
case AmbientLightBrightness.Medium:
44
brightnessMediumRadio.IsChecked = true;
45
break;
46
case AmbientLightBrightness.High:
47
brightnessHighRadio.IsChecked = true;
48
break;
49
}
50
24
51
NavigationCacheMode = NavigationCacheMode.Enabled;
25
52
Console.WriteLine("网易云歌词工具页面初始化完成");
26
53
}
27
54
55
private void OnBrightnessRadioChecked(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
56
{
57
if (ReferenceEquals(sender, brightnessLowRadio))
58
ViewModel.SyncAmbientLightBrightness = AmbientLightBrightness.Low;
59
else if (ReferenceEquals(sender, brightnessMediumRadio))
60
ViewModel.SyncAmbientLightBrightness = AmbientLightBrightness.Medium;
61
else if (ReferenceEquals(sender, brightnessHighRadio))
62
ViewModel.SyncAmbientLightBrightness = AmbientLightBrightness.High;
63
}
64
28
65
protected override void OnNavigatedTo(NavigationEventArgs e)
29
66
{
30
67
Console.WriteLine("导航到网易云歌词页面");
@@ -0,0 +1,126 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<Page
3
x:Class="HaloPixelToolBox.Views.DefaultSettingsPage"
4
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6
xmlns:local="using:HaloPixelToolBox.Views"
7
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
8
xmlns:converter="using:XFEExtension.NetCore.WinUIHelper.Utilities.Converter"
9
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
10
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
11
mc:Ignorable="d">
12
<Page.Resources>
13
<Style x:Key="SettingsSectionHeaderTextBlockStyle"
14
BasedOn="{StaticResource BodyStrongTextBlockStyle}"
15
TargetType="TextBlock">
16
<Style.Setters>
17
<Setter Property="Margin" Value="1,15,0,6" />
18
</Style.Setters>
19
</Style>
20
</Page.Resources>
21
22
<Grid>
23
<ScrollView>
24
<StackPanel Orientation="Vertical" Spacing="4" Margin="0,0,0,20">
25
<TextBlock Text="默认界面设置" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
26
27
<controls:SettingsCard Header="暂停后切换回默认界面" Description="在音乐暂停一段时间后,自动把花再设备切换回默认的时钟或页面">
28
<controls:SettingsCard.HeaderIcon>
29
<FontIcon Glyph=""/>
30
</controls:SettingsCard.HeaderIcon>
31
<ToggleSwitch x:Name="switchBackWhenPauseToggleSwitch" IsOn="{x:Bind ViewModel.SwitchBackWhenPause, Mode=TwoWay}"/>
32
</controls:SettingsCard>
33
34
<controls:SettingsCard Header="等待时间" Description="音乐暂停后等待切换的时间(秒)" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
35
<controls:SettingsCard.HeaderIcon>
36
<FontIcon Glyph=""/>
37
</controls:SettingsCard.HeaderIcon>
38
<NumberBox Value="{x:Bind ViewModel.SwitchBackTimeout, Mode=TwoWay}" Minimum="1" Maximum="3600" SpinButtonPlacementMode="Compact" Width="150"/>
39
</controls:SettingsCard>
40
41
<TextBlock Text="默认显示 & 灯效" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
42
43
<controls:SettingsCard Header="暂停像素屏界面" Description="暂停后切换回的默认界面模式" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
44
<controls:SettingsCard.HeaderIcon>
45
<FontIcon Glyph=""/>
46
</controls:SettingsCard.HeaderIcon>
47
<ComboBox x:Name="defaultHaloPixelUIModelComboBox" Tag="HaloPixelToolBox.Profiles.CrossVersionProfiles.SpotifyLyricsProfile.DefaultHaloPixelUIModel">
48
<ComboBoxItem Content="时钟类" Tag="Clock"/>
49
<ComboBoxItem Content="游戏类" Tag="Game"/>
50
<ComboBoxItem Content="打工类" Tag="Work"/>
51
<ComboBoxItem Content="读书类" Tag="Read"/>
52
<ComboBoxItem Content="猫咪类" Tag="Cats"/>
53
<ComboBoxItem Content="狗狗类" Tag="Dogs"/>
54
<ComboBoxItem Content="热更类" Tag="Memes"/>
55
<ComboBoxItem Content="赛博类" Tag="Cyber"/>
56
<ComboBoxItem Content="频谱类" Tag="Waves"/>
57
</ComboBox>
58
</controls:SettingsCard>
59
60
<controls:SettingsCard Header="暂停氛围灯效果" Description="设置暂停后切换回的氛围灯效果类型" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
61
<controls:SettingsCard.HeaderIcon>
62
<FontIcon Glyph=""/>
63
</controls:SettingsCard.HeaderIcon>
64
<ComboBox x:Name="defaultAmbientLightEffectComboBox" Tag="HaloPixelToolBox.Profiles.CrossVersionProfiles.SpotifyLyricsProfile.DefaultAmbientLightEffect">
65
<ComboBoxItem Content="常亮" Tag="Static"/>
66
<ComboBoxItem Content="呼吸" Tag="Breathing"/>
67
<ComboBoxItem Content="渐变" Tag="ColorTide"/>
68
<ComboBoxItem Content="流动" Tag="Flow"/>
69
<ComboBoxItem Content="涟漪" Tag="Ripple"/>
70
<ComboBoxItem Content="律动" Tag="Dynamic"/>
71
</ComboBox>
72
</controls:SettingsCard>
73
74
<controls:SettingsCard Header="暂停氛围灯亮度" Description="设置暂停后切换回的氛围灯光亮度模式" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
75
<controls:SettingsCard.HeaderIcon>
76
<FontIcon Glyph=""/>
77
</controls:SettingsCard.HeaderIcon>
78
<StackPanel Orientation="Horizontal" Spacing="15">
79
<RadioButton x:Name="defaultBrightnessLowRadio" Content="低" GroupName="DefaultBrightnessSyncGroup" Checked="OnDefaultBrightnessRadioChecked"/>
80
<RadioButton x:Name="defaultBrightnessMediumRadio" Content="中" GroupName="DefaultBrightnessSyncGroup" Checked="OnDefaultBrightnessRadioChecked"/>
81
<RadioButton x:Name="defaultBrightnessHighRadio" Content="高" GroupName="DefaultBrightnessSyncGroup" Checked="OnDefaultBrightnessRadioChecked"/>
82
</StackPanel>
83
</controls:SettingsCard>
84
85
<controls:SettingsCard Header="暂停氛围灯速度" Description="设置暂停后切换回的呼吸或动态灯效速度 (1-10)" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
86
<controls:SettingsCard.HeaderIcon>
87
<FontIcon Glyph=""/>
88
</controls:SettingsCard.HeaderIcon>
89
<Slider Minimum="1" Maximum="10" StepFrequency="1" Width="150" Value="{x:Bind ViewModel.DefaultAmbientLightSpeed, Mode=TwoWay}"/>
90
</controls:SettingsCard>
91
92
<controls:SettingsCard Header="暂停氛围灯颜色" Description="设置暂停后切换回的氛围灯光颜色" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
93
<controls:SettingsCard.HeaderIcon>
94
<FontIcon Glyph=""/>
95
</controls:SettingsCard.HeaderIcon>
96
<StackPanel Orientation="Horizontal" Spacing="8">
97
<Border x:Name="defaultAmbientColorIndicator" CornerRadius="4" Width="20" Height="20" BorderBrush="{ThemeResource SystemControlForegroundBaseMediumLowBrush}" BorderThickness="1"/>
98
<DropDownButton Content="选择颜色">
99
<DropDownButton.Flyout>
100
<Flyout>
101
<ColorPicker x:Name="defaultAmbientColorPicker" IsColorChannelTextInputVisible="False" IsHexInputVisible="True" IsAlphaEnabled="False" IsAlphaSliderVisible="False" ColorChanged="OnDefaultAmbientColorChanged"/>
102
</Flyout>
103
</DropDownButton.Flyout>
104
</DropDownButton>
105
</StackPanel>
106
</controls:SettingsCard>
107
108
<controls:SettingsCard Header="暂停像素屏颜色" Description="设置暂停后时钟或默认界面的前景色" IsEnabled="{x:Bind switchBackWhenPauseToggleSwitch.IsOn, Mode=OneWay}">
109
<controls:SettingsCard.HeaderIcon>
110
<FontIcon Glyph=""/>
111
</controls:SettingsCard.HeaderIcon>
112
<StackPanel Orientation="Horizontal" Spacing="8">
113
<Border x:Name="defaultScreenColorIndicator" CornerRadius="4" Width="20" Height="20" BorderBrush="{ThemeResource SystemControlForegroundBaseMediumLowBrush}" BorderThickness="1"/>
114
<DropDownButton Content="选择颜色">
115
<DropDownButton.Flyout>
116
<Flyout>
117
<ColorPicker x:Name="defaultScreenColorPicker" IsColorChannelTextInputVisible="False" IsHexInputVisible="True" IsAlphaEnabled="False" IsAlphaSliderVisible="False" ColorChanged="OnDefaultScreenColorChanged"/>
118
</Flyout>
119
</DropDownButton.Flyout>
120
</DropDownButton>
121
</StackPanel>
122
</controls:SettingsCard>
123
</StackPanel>
124
</ScrollView>
125
</Grid>
126
</Page>