mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-03 14:20:50 +08:00
fix: 修复 NeteaseCloudMusicApi anonymous_token 文件不存在导致启动崩溃
将 NeteaseCloudMusicApi/server 从静态 import 改为动态 require(), 确保 anonymous_token 文件在模块加载前创建
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import Store from 'electron-store';
|
||||
import fs from 'fs';
|
||||
import server from 'NeteaseCloudMusicApi/server';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
|
||||
import { type Platform, unblockMusic } from './unblockMusic';
|
||||
|
||||
const store = new Store();
|
||||
// 必须在 import NeteaseCloudMusicApi 之前创建 anonymous_token 文件
|
||||
// 否则模块加载时 readFileSync 会因文件不存在而崩溃
|
||||
if (!fs.existsSync(path.resolve(os.tmpdir(), 'anonymous_token'))) {
|
||||
fs.writeFileSync(path.resolve(os.tmpdir(), 'anonymous_token'), '', 'utf-8');
|
||||
}
|
||||
|
||||
const store = new Store();
|
||||
|
||||
// 设置音乐解析的处理程序
|
||||
ipcMain.handle('unblock-music', async (_event, id, songData, enabledSources) => {
|
||||
try {
|
||||
@@ -66,6 +68,7 @@ async function startMusicApi(): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
const server = require('NeteaseCloudMusicApi/server');
|
||||
await server.serveNcmApi({
|
||||
port,
|
||||
// 安全默认值:仅监听本机回环地址,避免对局域网暴露
|
||||
|
||||
Reference in New Issue
Block a user