Skip to content

Commit 9c30a55

Browse files
committed
支持本地源
1 parent 0a89a4a commit 9c30a55

11 files changed

Lines changed: 140 additions & 22 deletions

File tree

‎HotLyric/HotLyric.Package/Package.appxmanifest‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Identity
1414
Name="306200B4771A6.217957860C1A5"
1515
Publisher="CN=148E23EA-3EA2-4733-8A82-49C463DC3722"
16-
Version="1.3.45.0" />
16+
Version="1.3.46.0" />
1717

1818
<Properties>
1919
<DisplayName>热词</DisplayName>

‎HotLyric/HotLyric.Win32/App.xaml.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
4444

4545
_ = ViewModelLocator.Instance.AppConfigurationSettingsViewModel.UpdateConfigurationAsync();
4646

47-
ViewModelLocator.Instance.SettingsWindowViewModel.TryShowReadMeOnStartup();
47+
DispatcherQueue.TryEnqueue(async () =>
48+
{
49+
await Task.Delay(TimeSpan.FromSeconds(10));
50+
if (!Exiting)
51+
{
52+
ViewModelLocator.Instance.SettingsWindowViewModel.TryShowReadMeOnStartup();
53+
}
54+
});
4855

4956
HotKeyManager.HotKeyInvoked += HotKeyManager_HotKeyInvoked;
5057
}
26.5 KB
Loading
26 KB
Loading
27.6 KB
Loading

‎HotLyric/HotLyric.Win32/HotLyric.Win32.csproj‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,17 @@
4949
</ItemGroup>
5050

5151
<ItemGroup>
52-
<Content Include="configuration.json">
53-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54-
</Content>
55-
</ItemGroup>
56-
57-
<ItemGroup>
58-
<None Update="Assets\defaultTheme.json">
52+
<None Update="configuration.json">
53+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54+
</None>
55+
<None Update="Assets\**\*">
5956
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6057
</None>
6158
<None Update="NLog.config">
6259
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6360
</None>
64-
</ItemGroup>
61+
62+
</ItemGroup>
6563

6664
<ItemGroup Condition="'$(HotLyricExtensionLibraryEnabled)' != 'false'">
6765
<ContentWithTargetPath Include="Extensions\$(Platform)\$(Configuration)\HotLyric.Extensions.dll">

‎HotLyric/HotLyric.Win32/Utils/AppConfigurations/AppConfigurationManager.cs‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ public async Task<bool> UpdateConfigurationAsync()
140140
{
141141
"http" => true,
142142
"https" => true,
143+
"file" => true,
143144
_ => false
144145
})
145146
{
146-
return c.Uri;
147+
return uri;
147148
}
148149
return null;
149150
})
150-
.Where(c => !string.IsNullOrEmpty(c))
151-
.OfType<string>()
151+
.Where(c => c != null)
152+
.OfType<Uri>()
152153
.ToArray();
153154

154155
if (enabledSources.Length > 0)
@@ -159,16 +160,28 @@ public async Task<bool> UpdateConfigurationAsync()
159160
{
160161
try
161162
{
162-
var _json = await client.GetStringAsync(c, cancellationSource.Token);
163+
string? _json = null;
164+
if (c.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase))
165+
{
166+
if (System.IO.File.Exists(c.AbsolutePath))
167+
{
168+
_json = await System.IO.File.ReadAllTextAsync(c.AbsolutePath, cancellationSource.Token);
169+
}
170+
}
171+
else
172+
{
173+
_json = await client.GetStringAsync(c, cancellationSource.Token);
174+
}
175+
163176
if (!string.IsNullOrEmpty(_json))
164177
{
165-
var _model = AppConfigurationModel.CreateFromJson(c, _json);
178+
var _model = AppConfigurationModel.CreateFromJson(c.OriginalString, _json);
166179
if (_model != null)
167180
{
168181
return new AppConfigurationModelResult(
169182
_model,
170183
DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
171-
c,
184+
c.OriginalString,
172185
_json);
173186
}
174187
}

‎HotLyric/HotLyric.Win32/Utils/MediaSessions/SMTC/SMTCManager.cs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ private SMTCManager(MediaSessionAppFactory mediaSessionAppFactory, GlobalSystemM
2929

3030
private async void Manager_SessionsChanged(GlobalSystemMediaTransportControlsSessionManager sender, SessionsChangedEventArgs args)
3131
{
32-
await UpdateSessionAsync();
33-
SessionsChanged?.Invoke(this, EventArgs.Empty);
32+
await UpdateSessionAsync(true);
3433
}
3534

36-
public async Task UpdateSessionAsync()
35+
public async Task UpdateSessionAsync(bool raiseSessionsChanged)
3736
{
3837
var oldTask = lastUpdateSessionTask;
3938
if (oldTask != null)
@@ -48,6 +47,11 @@ public async Task UpdateSessionAsync()
4847
var task = lastUpdateSessionTask = UpdateSessionsAsyncCore();
4948
await task;
5049
lastUpdateSessionTask = null;
50+
51+
if (raiseSessionsChanged)
52+
{
53+
SessionsChanged?.Invoke(this, EventArgs.Empty);
54+
}
5155
}
5256

5357
private async Task UpdateSessionsAsyncCore(CancellationToken cancellationToken = default)

‎HotLyric/HotLyric.Win32/Utils/MediaSessions/SMTC/SMTCSession.cs‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,26 @@ private void UpdateControls()
345345

346346
public async Task<ImageSource?> GetSessionIconAsync()
347347
{
348-
if (App.AppInfo?.Icon != null)
348+
var iconUri = App.AppInfo?.Icon;
349+
if (iconUri != null)
349350
{
350-
return new BitmapImage(App.AppInfo.Icon);
351+
if (iconUri.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase))
352+
{
353+
try
354+
{
355+
if (File.Exists(iconUri.AbsolutePath))
356+
{
357+
var bitmap = new BitmapImage();
358+
await bitmap.SetSourceAsync(File.OpenRead(iconUri.AbsolutePath).AsRandomAccessStream());
359+
return bitmap;
360+
}
361+
}
362+
catch { }
363+
}
364+
else
365+
{
366+
return new BitmapImage(iconUri);
367+
}
351368
}
352369

353370
var package = await GetAppPackageAsync();

‎HotLyric/HotLyric.Win32/ViewModels/LyricWindowViewModel.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public LyricWindowViewModel(
4848
{
4949
if (smtcManager != null)
5050
{
51-
await smtcManager.UpdateSessionAsync();
51+
await smtcManager.UpdateSessionAsync(true);
5252
}
5353
});
5454
};

0 commit comments

Comments
 (0)