mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
fix: electron sourcemap issues (#1919)
This commit is contained in:
@@ -1,23 +1,48 @@
|
||||
import { protocol, session } from 'electron';
|
||||
import { join } from 'path';
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{
|
||||
scheme: 'assets',
|
||||
privileges: {
|
||||
secure: false,
|
||||
corsEnabled: true,
|
||||
supportFetchAPI: true,
|
||||
standard: true,
|
||||
bypassCSP: true,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
function toAbsolutePath(url: string) {
|
||||
let realpath = decodeURIComponent(url);
|
||||
const webStaticDir = join(__dirname, '../../../resources/web-static');
|
||||
if (url.startsWith('./')) {
|
||||
// if is a file type, load the file in resources
|
||||
if (url.split('/').at(-1)?.includes('.')) {
|
||||
realpath = join(webStaticDir, decodeURIComponent(url));
|
||||
} else {
|
||||
// else, fallback to load the index.html instead
|
||||
realpath = join(webStaticDir, 'index.html');
|
||||
}
|
||||
}
|
||||
return realpath;
|
||||
}
|
||||
|
||||
export function registerProtocol() {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
protocol.interceptFileProtocol('file', (request, callback) => {
|
||||
const url = request.url.replace(/^file:\/\//, '');
|
||||
const webStaticDir = join(__dirname, '../../../resources/web-static');
|
||||
if (url.startsWith('./')) {
|
||||
// if is a file type, load the file in resources
|
||||
if (url.split('/').at(-1)?.includes('.')) {
|
||||
const realpath = join(webStaticDir, decodeURIComponent(url));
|
||||
callback(realpath);
|
||||
} else {
|
||||
// else, fallback to load the index.html instead
|
||||
const realpath = join(webStaticDir, 'index.html');
|
||||
console.log(realpath, 'realpath', url, 'url');
|
||||
callback(realpath);
|
||||
}
|
||||
}
|
||||
const realpath = toAbsolutePath(url);
|
||||
// console.log('realpath', realpath, 'for', url);
|
||||
callback(realpath);
|
||||
});
|
||||
|
||||
protocol.registerFileProtocol('assets', (request, callback) => {
|
||||
const url = request.url.replace(/^assets:\/\//, '');
|
||||
const realpath = toAbsolutePath(url);
|
||||
// console.log('realpath', realpath, 'for', url);
|
||||
callback(realpath);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,6 +60,7 @@ export function registerProtocol() {
|
||||
'DELETE',
|
||||
'OPTIONS',
|
||||
];
|
||||
// responseHeaders['Content-Security-Policy'] = ["default-src 'self'"];
|
||||
}
|
||||
|
||||
callback({ responseHeaders });
|
||||
|
||||
Reference in New Issue
Block a user