Skip to content

Commit 059e8cb

Browse files
committed
🦄 refactor: Linux 优先使用原始字节更新封面,并在切歌时重置播放进度。补全部分文档
1 parent 1b81c2b commit 059e8cb

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

native/external-media-integration/src/model.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl fmt::Debug for MetadataPayload {
7575
}
7676

7777
#[napi(object)]
78+
#[allow(clippy::doc_markdown)]
7879
pub struct MetadataParam {
7980
pub song_name: String,
8081
pub author_name: String,
@@ -85,12 +86,15 @@ pub struct MetadataParam {
8586

8687
/// 封面的 HTTP URL,更新 Discord RPC 时必传,其他平台可不传
8788
///
88-
/// Linux 平台会优先使用 URL 来更新封面
89+
/// Linux 平台在没有提供 `cover_data` 时会使用它
8990
pub original_cover_url: Option<String>,
9091

91-
/// 网易云音乐 ID
92+
/// 网易云音乐中对应的曲目 ID
9293
///
93-
/// 会以 "NCM-{ID}" 的格式上传到 SMTC 的 “流派” 字段,以及用来生成 Discord RPC 的按钮链接
94+
/// ### 用途
95+
/// - 以 "NCM-{ID}" 的格式上传到 SMTC 的 “流派” 字段
96+
/// - 生成 Discord RPC 的按钮链接
97+
/// - MacOS 和 Linux 会使用此值来填充唯一的曲目 ID
9498
pub ncm_id: Option<i64>,
9599

96100
/// 当前歌曲时长,单位是毫秒

native/external-media-integration/src/sys_media/linux.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,7 @@ async fn process_metadata_update(
167167
payload: MetadataPayload,
168168
cover_guard: &mut Option<NamedTempFile>,
169169
) {
170-
let art_url = if let Some(url) = payload.original_cover_url {
171-
*cover_guard = None;
172-
Some(url)
173-
} else if let Some(data) = payload.cover_data {
170+
let art_url = if let Some(data) = payload.cover_data {
174171
match tempfile::Builder::new().suffix(".jpg").tempfile() {
175172
Ok(mut file) => {
176173
if file.write_all(&data).is_ok() {
@@ -189,6 +186,9 @@ async fn process_metadata_update(
189186
None
190187
}
191188
}
189+
} else if let Some(url) = payload.original_cover_url {
190+
*cover_guard = None;
191+
Some(url)
192192
} else {
193193
*cover_guard = None;
194194
None
@@ -228,6 +228,7 @@ async fn process_metadata_update(
228228
}
229229

230230
player.set_metadata(mb.build()).await.ok();
231+
player.set_position(Time::from_millis(0));
231232
}
232233

233234
#[allow(clippy::future_not_send)]

0 commit comments

Comments
 (0)