mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-07-11 21:03:37 +08:00
fix(local-music): 注册 local 协议为特权 scheme 修复本地音乐 CORS 报错
- main/index.ts 在 app.whenReady 之前调用 registerSchemesAsPrivileged, 把 local 标记为 standard/secure/supportFetchAPI/stream/corsEnabled/bypassCSP, 让 http 页面(dev server / 生产)可跨协议加载本地音频 - fileManager.ts 用 Electron 25 起推荐的 protocol.handle 替代已弃用的 registerFileProtocol,内部转发到 file:// 自动支持 Range / 流式播放 - 修复 macOS/Linux 上去掉前导斜杠后丢失绝对路径前缀的问题
This commit is contained in:
+18
-1
@@ -1,7 +1,24 @@
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils';
|
||||
import { app, ipcMain, nativeImage, session } from 'electron';
|
||||
import { app, ipcMain, nativeImage, protocol, session } from 'electron';
|
||||
import { join } from 'path';
|
||||
|
||||
// 必须在 app.whenReady() 之前注册自定义协议为特权协议,
|
||||
// 否则 http(s) 页面(dev server、生产环境的 file://)无法把 local:// 当成
|
||||
// 安全/可 fetch/可流式的资源加载,会触发 CORS 拦截或 net::ERR_UNKNOWN_URL_SCHEME
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{
|
||||
scheme: 'local',
|
||||
privileges: {
|
||||
standard: true,
|
||||
secure: true,
|
||||
supportFetchAPI: true,
|
||||
stream: true,
|
||||
bypassCSP: true,
|
||||
corsEnabled: true
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
import type { Language } from '../i18n/main';
|
||||
import i18n from '../i18n/main';
|
||||
import { loadLyricWindow } from './lyric';
|
||||
|
||||
Reference in New Issue
Block a user