Skip to content

Commit 7eb97b4

Browse files
committed
feat: 添加自定义fetch处理以支持动态URL构建
1 parent e6c7f98 commit 7eb97b4

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ function createWindow() {
1111
icon: 'icon.ico',
1212
});
1313

14+
mainWindow.webContents.on('did-finish-load', async () => {
15+
await mainWindow.webContents.executeJavaScript(`
16+
(() => {
17+
const rawFetch = window.fetch.bind(window)
18+
19+
const BASE_URL = 'https://k5.vicicode.cn'
20+
21+
window.fetch = async (input, init) => {
22+
if (
23+
typeof input === 'string' &&
24+
input.startsWith('/') &&
25+
!input.startsWith('//') &&
26+
input.endsWith('.bin')
27+
) {
28+
input = BASE_URL + input
29+
}
30+
31+
return rawFetch(input, init)
32+
}
33+
})()
34+
`)
35+
});
36+
1437
mainWindow.webContents.session.on('select-serial-port', async (event, portList, webContents, callback) => {
1538
// Add listeners to handle ports being added or removed before the callback for `select-serial-port` is called.
1639
mainWindow.webContents.session.on('serial-port-added', (event, port) => {

0 commit comments

Comments
 (0)