mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 10:54:55 +08:00
fix: app crash when audio device was not found
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
<Identity
|
<Identity
|
||||||
Name="37412.BetterLyrics"
|
Name="37412.BetterLyrics"
|
||||||
Publisher="CN=E1428B0E-DC1D-4EA4-ACB1-4556569D5BA9"
|
Publisher="CN=E1428B0E-DC1D-4EA4-ACB1-4556569D5BA9"
|
||||||
Version="1.1.221.0" />
|
Version="1.2.222.0" />
|
||||||
|
|
||||||
<mp:PhoneIdentity PhoneProductId="ca4a4830-fc19-40d9-b823-53e2bff3d816" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
<mp:PhoneIdentity PhoneProductId="ca4a4830-fc19-40d9-b823-53e2bff3d816" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,11 @@ namespace BetterLyrics.WinUI3.Hooks
|
|||||||
public static event EventHandler<int>? VolumeNotification;
|
public static event EventHandler<int>? VolumeNotification;
|
||||||
|
|
||||||
static SystemVolumeHook()
|
static SystemVolumeHook()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
_deviceEnumerator = new MMDeviceEnumerator();
|
_deviceEnumerator = new MMDeviceEnumerator();
|
||||||
|
// 找不到设备会抛出异常,在这里截获它
|
||||||
_defaultDevice = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
|
_defaultDevice = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
|
||||||
|
|
||||||
if (_defaultDevice != null)
|
if (_defaultDevice != null)
|
||||||
@@ -25,6 +28,11 @@ namespace BetterLyrics.WinUI3.Hooks
|
|||||||
_defaultDevice.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
|
_defaultDevice.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_defaultDevice = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
|
private static void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,27 +3,24 @@ using System;
|
|||||||
|
|
||||||
namespace BetterLyrics.WinUI3.Models
|
namespace BetterLyrics.WinUI3.Models
|
||||||
{
|
{
|
||||||
|
[Preserve(AllMembers = true)]
|
||||||
[Table("FileCache")]
|
[Table("FileCache")]
|
||||||
public class FileCacheEntity
|
public class FileCacheEntity
|
||||||
{
|
{
|
||||||
[PrimaryKey, AutoIncrement]
|
[PrimaryKey, AutoIncrement]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
// 【新增】关键字段!
|
|
||||||
// 关联到 MediaFolder.Id。
|
// 关联到 MediaFolder.Id。
|
||||||
// 作用:
|
// 区分不同配置(即使两个配置连的是同一个 SMB,但在 APP 里视为不同源)。
|
||||||
// 1. 区分不同配置(即使两个配置连的是同一个 SMB,但在 APP 里视为不同源)。
|
// 删除配置时,可以由 MediaFolderId 快速级联删除所有缓存。
|
||||||
// 2. 删除配置时,可以由 MediaFolderId 快速级联删除所有缓存。
|
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public string MediaFolderId { get; set; }
|
public string MediaFolderId { get; set; }
|
||||||
|
|
||||||
// 【修改】从 ParentPath 改为 ParentUri
|
|
||||||
// 存储父文件夹的标准 URI (smb://host/share/parent)
|
// 存储父文件夹的标准 URI (smb://host/share/parent)
|
||||||
// 根目录文件的 ParentUri 可以为空,或者等于 MediaFolder 的 Base Uri
|
// 根目录文件的 ParentUri 可以为空,或者等于 MediaFolder 的 Base Uri
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public string? ParentUri { get; set; }
|
public string? ParentUri { get; set; }
|
||||||
|
|
||||||
// 【核心】标准化的完整 URI (smb://host/share/folder/file.ext)
|
|
||||||
// 确保它是 URL 编码过且格式统一的
|
// 确保它是 URL 编码过且格式统一的
|
||||||
[Indexed(Unique = true)]
|
[Indexed(Unique = true)]
|
||||||
public string Uri { get; set; }
|
public string Uri { get; set; }
|
||||||
@@ -38,7 +35,6 @@ namespace BetterLyrics.WinUI3.Models
|
|||||||
// 记录修改时间,同步时对比使用
|
// 记录修改时间,同步时对比使用
|
||||||
public DateTime? LastModified { get; set; }
|
public DateTime? LastModified { get; set; }
|
||||||
|
|
||||||
// ------ 元数据部分 (保持不变) ------
|
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
public string Artists { get; set; } = "";
|
public string Artists { get; set; } = "";
|
||||||
public string Album { get; set; } = "";
|
public string Album { get; set; } = "";
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace BetterLyrics.WinUI3.Models
|
namespace BetterLyrics.WinUI3.Models
|
||||||
{
|
{
|
||||||
|
[Preserve(AllMembers = true)]
|
||||||
[Table("PlayHistory")]
|
[Table("PlayHistory")]
|
||||||
public class PlayHistoryItem
|
public class PlayHistoryItem
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user