Skip to content

Commit d797ac0

Browse files
committed
🐞 fix: 修复一些小问题
1 parent 469e4b5 commit d797ac0

4 files changed

Lines changed: 109 additions & 45 deletions

File tree

src/components/Modal/Setting/FontManager.vue

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,49 @@
4343
</n-flex>
4444
</n-card>
4545
</div>
46-
46+
<div class="set-list" v-if="isElectron">
47+
<n-h3 prefix="bar">桌面歌词</n-h3>
48+
<n-card class="set-item">
49+
<div class="label">
50+
<n-text class="name">桌面歌词字体</n-text>
51+
<n-text class="tip" :depth="3"> 桌面歌词使用的字体 </n-text>
52+
</div>
53+
<n-flex align="center">
54+
<Transition name="fade" mode="out-in">
55+
<n-button
56+
v-if="desktopLyricConfig.fontFamily !== 'system-ui'"
57+
type="primary"
58+
strong
59+
secondary
60+
@click="
61+
() => {
62+
desktopLyricConfig.fontFamily = 'system-ui';
63+
saveDesktopLyricConfig();
64+
}
65+
"
66+
>
67+
恢复默认
68+
</n-button>
69+
</Transition>
70+
<s-input
71+
v-if="settingStore.useCustomFont"
72+
v-model:value="desktopLyricConfig.fontFamily"
73+
:update-value-on-input="false"
74+
placeholder="输入字体名称"
75+
class="set"
76+
@change="saveDesktopLyricConfig"
77+
/>
78+
<n-select
79+
v-else
80+
v-model:value="desktopLyricConfig.fontFamily"
81+
:options="getOptions('desktop')"
82+
class="set"
83+
filterable
84+
@update:value="saveDesktopLyricConfig"
85+
/>
86+
</n-flex>
87+
</n-card>
88+
</div>
4789
<div class="set-list">
4890
<n-h3 prefix="bar">歌词字体</n-h3>
4991
<n-card v-for="font in lyricFontConfigs" :key="font.keySetting" class="set-item">
@@ -88,17 +130,29 @@ import { useSettingStore } from "@/stores";
88130
import { isElectron } from "@/utils/env";
89131
import type { SelectOption } from "naive-ui";
90132
import { lyricFontConfigs } from "@/utils/lyricFontConfig";
133+
import { LyricConfig } from "@/types/desktop-lyric";
134+
import defaultDesktopLyricConfig from "@/assets/data/lyricConfig";
135+
import { cloneDeep, isEqual } from "lodash-es";
91136
92137
const settingStore = useSettingStore();
93138
94139
// 系统字体选项
95140
const systemFonts = ref<SelectOption[]>([]);
96141
142+
// 桌面歌词配置
143+
const desktopLyricConfig = reactive<LyricConfig>({ ...defaultDesktopLyricConfig });
144+
97145
// 获取下拉选项
98146
const getOptions = (key: string) => {
99147
const isGlobal = key === "globalFont";
100-
const defaultLabel = isGlobal ? "系统默认" : "跟随全局";
101-
const defaultValue = isGlobal ? "default" : "follow";
148+
const isDesktop = key === "desktop";
149+
let defaultLabel = "跟随全局";
150+
let defaultValue = "follow";
151+
152+
if (isGlobal || isDesktop) {
153+
defaultLabel = "系统默认";
154+
defaultValue = isGlobal ? "default" : "system-ui";
155+
}
102156
103157
return [{ label: defaultLabel, value: defaultValue }, ...systemFonts.value];
104158
};
@@ -123,8 +177,39 @@ const getAllSystemFonts = async () => {
123177
}
124178
};
125179
180+
// 获取桌面歌词配置
181+
const getDesktopLyricConfig = async () => {
182+
if (!isElectron) return;
183+
const config = await window.electron.ipcRenderer.invoke("request-desktop-lyric-option");
184+
if (config) Object.assign(desktopLyricConfig, config);
185+
// 监听更新
186+
window.electron.ipcRenderer.on("update-desktop-lyric-option", (_, config) => {
187+
if (config && !isEqual(desktopLyricConfig, config)) {
188+
Object.assign(desktopLyricConfig, config);
189+
}
190+
});
191+
};
192+
193+
// 保存桌面歌词配置
194+
const saveDesktopLyricConfig = () => {
195+
try {
196+
if (!isElectron) return;
197+
window.electron.ipcRenderer.send(
198+
"update-desktop-lyric-option",
199+
cloneDeep(desktopLyricConfig),
200+
true,
201+
);
202+
window.$message.success("桌面歌词字体已保存");
203+
} catch (error) {
204+
console.error("Failed to save options:", error);
205+
window.$message.error("桌面歌词配置保存失败");
206+
getDesktopLyricConfig();
207+
}
208+
};
209+
126210
onMounted(() => {
127211
getAllSystemFonts();
212+
getDesktopLyricConfig();
128213
});
129214
</script>
130215

src/components/Setting/LyricsSetting.vue

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -477,31 +477,7 @@
477477
<n-text class="name">歌词字体</n-text>
478478
<n-text class="tip" :depth="3"> 更改桌面歌词字体 </n-text>
479479
</div>
480-
<n-flex>
481-
<Transition name="fade" mode="out-in">
482-
<n-button
483-
v-if="desktopLyricConfig.fontFamily !== 'system-ui'"
484-
type="primary"
485-
strong
486-
secondary
487-
@click="
488-
() => {
489-
desktopLyricConfig.fontFamily = 'system-ui';
490-
saveDesktopLyricConfig();
491-
}
492-
"
493-
>
494-
恢复默认
495-
</n-button>
496-
</Transition>
497-
<n-select
498-
v-model:value="desktopLyricConfig.fontFamily"
499-
:options="allFontsData"
500-
class="set"
501-
filterable
502-
@update:value="saveDesktopLyricConfig"
503-
/>
504-
</n-flex>
480+
<n-button type="primary" strong secondary @click="openFontManager">配置</n-button>
505481
</n-card>
506482
<n-card class="set-item">
507483
<div class="label">
@@ -639,7 +615,6 @@ import { isElectron } from "@/utils/env";
639615
import { openLyricExclude, openAMLLServer, openFontManager } from "@/utils/modal";
640616
import { LyricConfig } from "@/types/desktop-lyric";
641617
import { usePlayerController } from "@/core/player/PlayerController";
642-
import { SelectOption } from "naive-ui";
643618
import defaultDesktopLyricConfig from "@/assets/data/lyricConfig";
644619
645620
const props = defineProps<{ scrollTo?: string }>();
@@ -651,20 +626,19 @@ const settingStore = useSettingStore();
651626
// 桌面歌词区域引用
652627
const desktopLyricRef = ref<HTMLElement | null>(null);
653628
654-
// 全部字体
655-
const allFontsData = ref<SelectOption[]>([]);
656-
657629
/**
658630
* 创建响应式字体大小计算属性
659631
* 当启用 AMLL 时,翻译和音译的字体大小会根据主歌词大小自动调整
660632
*/
661-
const fontSizeComputed = (key: string) => computed({
662-
get: () => settingStore.useAMLyrics ?
663-
// AMLL 会为翻译和音译设置 `font-size: max(.5em, 10px);`
664-
Math.max(0.5 * settingStore.lyricFontSize, 10) :
665-
settingStore[key],
666-
set: (value) => settingStore[key] = value,
667-
});
633+
const fontSizeComputed = (key: string) =>
634+
computed({
635+
get: () =>
636+
settingStore.useAMLyrics
637+
? // AMLL 会为翻译和音译设置 `font-size: max(.5em, 10px);`
638+
Math.max(0.5 * settingStore.lyricFontSize, 10)
639+
: settingStore[key],
640+
set: (value) => (settingStore[key] = value),
641+
});
668642
669643
// 真实显示的翻译歌词字体大小
670644
const tranFontSize = fontSizeComputed("lyricTranFontSize");
@@ -673,8 +647,9 @@ const tranFontSize = fontSizeComputed("lyricTranFontSize");
673647
const romaFontSize = fontSizeComputed("lyricRomaFontSize");
674648
675649
// 显示翻译和音译歌词字体大小被禁用的原因
676-
const tranFontSizeTitle = computed(() => settingStore.useAMLyrics ?
677-
"翻译和音译歌词大小由 Apple Music-like Lyrics 自动设置" : "")
650+
const tranFontSizeTitle = computed(() =>
651+
settingStore.useAMLyrics ? "翻译和音译歌词大小由 Apple Music-like Lyrics 自动设置" : "",
652+
);
678653
679654
// 桌面歌词配置
680655
const desktopLyricConfig = reactive<LyricConfig>({ ...defaultDesktopLyricConfig });

src/components/Setting/PlaySetting.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
/>
112112
</n-card>
113113
</div>
114-
<div v-if="isElectron && statusStore.isDeveloperMode" class="set-list">
114+
<div v-if="isElectron" class="set-list">
115115
<n-h3 prefix="bar">
116116
音乐解锁
117117
<n-tag type="warning" size="small" round>Beta</n-tag>
@@ -316,9 +316,7 @@
316316
<n-card class="set-item">
317317
<div class="label">
318318
<n-text class="name">播放列表歌曲数量</n-text>
319-
<n-text class="tip" :depth="3">
320-
在右下角的播放列表按钮处显示播放列表的歌曲数量
321-
</n-text>
319+
<n-text class="tip" :depth="3"> 在右下角的播放列表按钮处显示播放列表的歌曲数量 </n-text>
322320
</div>
323321
<n-switch v-model:value="settingStore.showPlaylistCount" class="set" :round="false" />
324322
</n-card>

src/core/player/LyricManager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ class LyricManager {
440440
if (this.isLyricDataEqual(musicStore.songLyric, lyricData)) {
441441
// 仅更新加载状态,不更新歌词数据
442442
statusStore.lyricLoading = false;
443+
// 单曲循环时,歌词数据未变,需通知桌面歌词取消加载状态
444+
if (isElectron) {
445+
window.electron.ipcRenderer.send("update-desktop-lyric-data", {
446+
lyricLoading: false,
447+
});
448+
}
443449
return;
444450
}
445451
// 设置歌词

0 commit comments

Comments
 (0)