()
| 42 | // 是否退出 |
| 43 | isQuit: boolean = false; |
| 44 | constructor() { |
| 45 | processLog.info("🚀 Main process startup"); |
| 46 | |
| 47 | // 在 Windows、Linux 和 MacOS 上禁用自带的媒体控件功能,因为我们已经通过原生插件实现媒体控件的集成了 |
| 48 | const platform = process.platform; |
| 49 | const hasNativeMediaSupport = ["win32", "linux", "darwin"].includes(platform); |
| 50 | |
| 51 | if (hasNativeMediaSupport) { |
| 52 | app.commandLine.appendSwitch( |
| 53 | "disable-features", |
| 54 | "HardwareMediaKeyHandling,MediaSessionService", |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | if (platform === "win32") { |
| 59 | // GPU 稳定性配置:禁用 GPU 进程崩溃次数限制,允许 GPU 进程自动恢复 |
| 60 | app.commandLine.appendSwitch("disable-gpu-process-crash-limit"); |
| 61 | } |
| 62 | |
| 63 | // 防止后台时渲染进程被休眠 |
| 64 | app.commandLine.appendSwitch("disable-renderer-backgrounding"); |
| 65 | app.commandLine.appendSwitch("disable-backgrounding-occluded-windows"); |
| 66 | |
| 67 | // 程序单例锁 |
| 68 | initSingleLock(); |
| 69 | // 监听应用事件 |
| 70 | this.handleAppEvents(); |
| 71 | // Electron 初始化完成后 |
| 72 | // 某些 API 只有在此事件发生后才能使用 |
| 73 | app.whenReady().then(async () => { |
| 74 | processLog.info("🚀 Application Process Startup"); |
| 75 | |
| 76 | // 配置 COOP/COEP/CORP 头,FFmpeg 需要 |
| 77 | session.defaultSession.webRequest.onHeadersReceived((details, callback) => { |
| 78 | const responseHeaders = { ...details.responseHeaders }; |
| 79 | const url = new URL(details.url); |
| 80 | |
| 81 | // 桌面歌词窗口需要透明背景,必须排除严格的安全策略 |
| 82 | if (url.searchParams.get("win") === "desktop-lyric") { |
| 83 | callback({ responseHeaders }); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | // 同样可以解决 CORS 限制,但为了避免安全问题,等真有需要的时候再开 |
| 88 | // responseHeaders["Access-Control-Allow-Origin"] = ["*"]; |
| 89 | // responseHeaders["Access-Control-Allow-Headers"] = ["*"]; |
| 90 | |
| 91 | // COOP/COEP/CORP 配置 |
| 92 | responseHeaders["Cross-Origin-Opener-Policy"] = ["same-origin"]; |
| 93 | responseHeaders["Cross-Origin-Embedder-Policy"] = ["require-corp"]; |
| 94 | responseHeaders["Cross-Origin-Resource-Policy"] = ["cross-origin"]; |
| 95 | |
| 96 | callback({ responseHeaders }); |
| 97 | }); |
| 98 | |
| 99 | // 设置应用程序名称 |
| 100 | electronApp.setAppUserModelId("com.imsyy.splayer"); |
| 101 | // 启动主服务进程 |
nothing calls this directly
no test coverage detected