mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 15:46:29 +08:00
24 lines
854 B
TypeScript
24 lines
854 B
TypeScript
import { protocol } from 'electron';
|
|
import { join } from 'path';
|
|
|
|
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);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|