@@ -240,7 +240,7 @@ const initFileIpc = (): void => {
240240 musicPath : string , // 参数名改为 musicPath 以示区分
241241 ) : Promise < {
242242 lyric : string ;
243- format : "lrc" | "ttml" ;
243+ format : "lrc" | "ttml" | "yrc" ;
244244 } > => {
245245 try {
246246 // 获取文件基本信息
@@ -257,7 +257,7 @@ const initFileIpc = (): void => {
257257 throw error ;
258258 }
259259 // 遍历优先级
260- for ( const format of [ "lrc " , "ttml " ] as const ) {
260+ for ( const format of [ "ttml " , "yrc" , "lrc "] as const ) {
261261 // 构造期望目标文件名
262262 const targetNameLower = `${ baseName } .${ format } ` . toLowerCase ( ) ;
263263 // 在文件列表中查找是否存在匹配项(忽略大小写)
@@ -695,6 +695,52 @@ const initFileIpc = (): void => {
695695 return relativePath && ! relativePath . startsWith ( ".." ) && ! isAbsolute ( relativePath ) ;
696696 } ) ;
697697 } ) ;
698+
699+ // 保存文件内容 (用于保存文本文件等)
700+ ipcMain . handle (
701+ "save-file-content" ,
702+ async (
703+ _ ,
704+ options : { path : string ; fileName : string ; content : string ; encoding ?: string } ,
705+ ) : Promise < { success : boolean ; message ?: string } > => {
706+ try {
707+ const { path, fileName, content, encoding = "utf-8" } = options ;
708+ // 规范化路径
709+ const dirPath = resolve ( path ) ;
710+ // 检查文件夹是否存在,不存在则自动递归创建
711+ try {
712+ await access ( dirPath ) ;
713+ } catch {
714+ await mkdir ( dirPath , { recursive : true } ) ;
715+ }
716+ const filePath = join ( dirPath , fileName ) ;
717+
718+ if ( encoding !== "utf-8" ) {
719+ try {
720+ // 使用动态导入,避免启动时加载问题
721+ const { encode } = await import ( "iconv-lite" ) ;
722+ // iconv-lite support 'utf16' as alias for 'utf-16' etc.
723+ const buffer = encode ( content , encoding ) ;
724+ await writeFile ( filePath , buffer ) ;
725+ } catch ( e ) {
726+ ipcLog . error ( `❌ ${ encoding } encoding failed:` , e ) ;
727+ // Fallback to UTF-8 on error
728+ await writeFile ( filePath , content , "utf-8" ) ;
729+ }
730+ } else {
731+ await writeFile ( filePath , content , "utf-8" ) ;
732+ }
733+
734+ return { success : true } ;
735+ } catch ( error ) {
736+ ipcLog . error ( "❌ Error saving file content:" , error ) ;
737+ return {
738+ success : false ,
739+ message : error instanceof Error ? error . message : "Unknown error" ,
740+ } ;
741+ }
742+ } ,
743+ ) ;
698744} ;
699745
700746export default initFileIpc ;
0 commit comments