CSAPP/src/preload.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-04-29 18:36:29 +08:00
// See the Electron documentation for details on how to use preload scripts:
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
import { contextBridge, ipcRenderer } from 'electron';
contextBridge.exposeInMainWorld('electronAPI', {
setCookie: async (cookieString: string) => {
const cookies = cookieString.split(';').map(cookie => {
const [name, value] = cookie.trim().split('=');
return {
name: name.trim(),
value: value.trim(),
path: '/',
secure: false,
httpOnly: false,
expirationDate: Math.floor(Date.now() / 1000) + 86400 // 24小时后过期
};
});
// 为每个域名设置Cookie
const domains = ['localhost', '1.12.73.211'];
const ports = ['', ':8848'];
for (const cookie of cookies) {
for (const domain of domains) {
for (const port of ports) {
const url = `http://${domain}${port}`;
await ipcRenderer.invoke('set-cookie', {
...cookie,
url,
domain
});
}
}
}
2025-04-30 17:28:03 +08:00
},
checkUrl: (url: string) => ipcRenderer.invoke('check-url', url)
2025-04-29 18:36:29 +08:00
});