mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
fix: electron preload issue (#1603)
This commit is contained in:
2
.github/workflows/client-app.yml
vendored
2
.github/workflows/client-app.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
version:
|
version:
|
||||||
description: App Version
|
description: App Version
|
||||||
required: true
|
required: true
|
||||||
default: 0.1.0
|
default: 0.0.0
|
||||||
is-draft:
|
is-draft:
|
||||||
description: 'Draft Release?'
|
description: 'Draft Release?'
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ async function createWindow() {
|
|||||||
sandbox: false,
|
sandbox: false,
|
||||||
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
|
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
|
||||||
spellcheck: false, // FIXME: enable?
|
spellcheck: false, // FIXME: enable?
|
||||||
preload: join(__dirname, '../../preload/dist/index.js'),
|
preload: join(__dirname, '../preload/index.js'),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,22 @@ import { protocol } from 'electron';
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
export function registerProtocol() {
|
export function registerProtocol() {
|
||||||
protocol.interceptFileProtocol('file', (request, callback) => {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
const url = request.url.replace(/^file:\/\//, '');
|
protocol.interceptFileProtocol('file', (request, callback) => {
|
||||||
if (url.startsWith('./')) {
|
const url = request.url.replace(/^file:\/\//, '');
|
||||||
const realpath = join(
|
const webStaticDir = join(__dirname, '../../../resources/web-static');
|
||||||
__dirname,
|
if (url.startsWith('./')) {
|
||||||
'../../../resources/web-static',
|
// if is a file type, load the file in resources
|
||||||
decodeURIComponent(url)
|
if (url.split('/').at(-1)?.includes('.')) {
|
||||||
);
|
const realpath = join(webStaticDir, decodeURIComponent(url));
|
||||||
callback(realpath);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user