Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

Commit 82705f3

Browse files
committed
🎈 perf: 清理旧的 blob URL
1 parent 0fc56bc commit 82705f3

4 files changed

Lines changed: 43 additions & 21 deletions

File tree

‎src/components/UI/s-image.vue‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
<!-- 图片组件 -->
22
<template>
3-
<Transition name="fade" mode="out-in">
4-
<div ref="imgContainer" :key="src" class="s-image">
5-
<!-- 加载图片 -->
6-
<Transition name="fade">
7-
<img v-if="!isLoaded" :src="defaultSrc" class="loading" alt="loading" />
8-
</Transition>
9-
<!-- 真实图片 -->
10-
<img
11-
v-if="imgSrc"
12-
ref="imgRef"
13-
:src="imgSrc"
14-
:key="imgSrc"
15-
:alt="alt || 'image'"
16-
:class="['cover', { loaded: isLoaded }]"
17-
:decoding="decodeAsync ? 'async' : 'auto'"
18-
:loading="nativeLazy ? 'lazy' : 'eager'"
19-
@load="imageLoaded"
20-
@error="imageError"
21-
/>
22-
</div>
23-
</Transition>
3+
<div ref="imgContainer" :key="src" class="s-image">
4+
<!-- 加载图片 -->
5+
<Transition name="fade">
6+
<img v-if="!isLoaded" :src="defaultSrc" class="loading" alt="loading" />
7+
</Transition>
8+
<!-- 真实图片 -->
9+
<img
10+
v-if="imgSrc"
11+
ref="imgRef"
12+
:src="imgSrc"
13+
:key="imgSrc"
14+
:alt="alt || 'image'"
15+
:class="['cover', { loaded: isLoaded }]"
16+
:decoding="decodeAsync ? 'async' : 'auto'"
17+
:loading="nativeLazy ? 'lazy' : 'eager'"
18+
@load="imageLoaded"
19+
@error="imageError"
20+
/>
21+
</div>
2422
</template>
2523

2624
<script setup lang="ts">

‎src/layout/AppLayout.vue‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979

8080
<script setup lang="ts">
8181
import { useMusicStore, useStatusStore, useSettingStore } from "@/stores";
82+
import blob from "@/utils/blob";
8283
import init from "@/utils/init";
8384
8485
const musicStore = useMusicStore();
@@ -94,6 +95,8 @@ const { height: contentHeight } = useElementSize(contentRef);
9495
// 离开前提醒
9596
window.addEventListener("beforeunload", (event) => {
9697
event.preventDefault();
98+
// 释放所有 blob URL
99+
blob.revokeAllBlobURLs();
97100
event.returnValue = "";
98101
});
99102

‎src/stores/music.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { SongType } from "@/types/main";
33
import { isElectron } from "@/utils/env";
44
import { cloneDeep } from "lodash-es";
55
import { SongLyric } from "@/types/lyric";
6+
import blob from "@/utils/blob";
67

78
interface MusicState {
89
playSong: SongType;
@@ -80,6 +81,16 @@ export const useMusicStore = defineStore("music", {
8081
actions: {
8182
/** 重置音乐数据 */
8283
resetMusicData() {
84+
// 清理旧的 blob URL(如果 cover 是 blob URL)
85+
const oldCover = this.playSong.cover;
86+
const oldPath = this.playSong.path;
87+
if (oldCover && oldCover.startsWith("blob:") && oldPath) {
88+
try {
89+
blob.revokeBlobURL(oldPath);
90+
} catch (e) {
91+
// 忽略错误
92+
}
93+
}
8394
this.playSong = { ...defaultMusicData };
8495
this.setSongLyric({ lrcData: [], yrcData: [] }, true);
8596
if (isElectron) {

‎src/utils/player.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ class Player {
451451
try {
452452
const musicStore = useMusicStore();
453453
const statusStore = useStatusStore();
454+
// 清理旧的 blob URL(如果存在)
455+
const oldCover = musicStore.playSong.cover;
456+
const oldPath = musicStore.playSong.path;
457+
if (oldCover && oldCover.startsWith("blob:") && oldPath && oldPath !== path) {
458+
try {
459+
blob.revokeBlobURL(oldPath);
460+
} catch (e) {
461+
// 忽略错误
462+
}
463+
}
454464
// 获取封面数据
455465
const coverData = await window.electron.ipcRenderer.invoke("get-music-cover", path);
456466
if (coverData) {

0 commit comments

Comments
 (0)