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";
88130import { isElectron } from " @/utils/env" ;
89131import type { SelectOption } from " naive-ui" ;
90132import { 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
92137const settingStore = useSettingStore ();
93138
94139// 系统字体选项
95140const systemFonts = ref <SelectOption []>([]);
96141
142+ // 桌面歌词配置
143+ const desktopLyricConfig = reactive <LyricConfig >({ ... defaultDesktopLyricConfig });
144+
97145// 获取下拉选项
98146const 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+
126210onMounted (() => {
127211 getAllSystemFonts ();
212+ getDesktopLyricConfig ();
128213});
129214 </script >
130215
0 commit comments