|
|
@@ -60,7 +60,7 @@ function createTray() {
|
|
|
}
|
|
|
]);
|
|
|
|
|
|
- tray.setToolTip('多平台媒体管理系统');
|
|
|
+ tray.setToolTip('智媒通');
|
|
|
tray.setContextMenu(contextMenu);
|
|
|
|
|
|
// 点击托盘图标显示窗口
|
|
|
@@ -234,10 +234,10 @@ function setupWebviewSessions() {
|
|
|
function isAllowedUrl(url: string): boolean {
|
|
|
if (!url) return false;
|
|
|
const lowerUrl = url.toLowerCase();
|
|
|
- return lowerUrl.startsWith('http://') ||
|
|
|
- lowerUrl.startsWith('https://') ||
|
|
|
- lowerUrl.startsWith('about:') ||
|
|
|
- lowerUrl.startsWith('data:');
|
|
|
+ return lowerUrl.startsWith('http://') ||
|
|
|
+ lowerUrl.startsWith('https://') ||
|
|
|
+ lowerUrl.startsWith('about:') ||
|
|
|
+ lowerUrl.startsWith('data:');
|
|
|
}
|
|
|
|
|
|
// 阻止默认的 window-all-closed 行为,保持托盘运行
|
|
|
@@ -411,7 +411,7 @@ ipcMain.handle('set-webview-cookies', async (_event: unknown, partition: string,
|
|
|
try {
|
|
|
console.log(`[Main] 设置 webview cookies, partition=${partition}, count=${cookies.length}`);
|
|
|
const ses = session.fromPartition(partition);
|
|
|
-
|
|
|
+
|
|
|
// 逐个设置 cookie
|
|
|
let successCount = 0;
|
|
|
for (const cookie of cookies) {
|
|
|
@@ -424,7 +424,7 @@ ipcMain.handle('set-webview-cookies', async (_event: unknown, partition: string,
|
|
|
domain: cookie.domain,
|
|
|
path: cookie.path || '/',
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
// 可选字段
|
|
|
if (cookie.expirationDate) {
|
|
|
cookieToSet.expirationDate = cookie.expirationDate;
|
|
|
@@ -438,10 +438,10 @@ ipcMain.handle('set-webview-cookies', async (_event: unknown, partition: string,
|
|
|
if (cookie.sameSite) {
|
|
|
cookieToSet.sameSite = cookie.sameSite as 'no_restriction' | 'lax' | 'strict';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
await ses.cookies.set(cookieToSet);
|
|
|
successCount++;
|
|
|
-
|
|
|
+
|
|
|
// 记录关键 Cookie
|
|
|
if (cookie.name === 'BDUSS' || cookie.name === 'STOKEN' || cookie.name === 'sessionid') {
|
|
|
console.log(`[Main] 成功设置关键 Cookie: ${cookie.name}, domain: ${cookie.domain}`);
|
|
|
@@ -450,9 +450,9 @@ ipcMain.handle('set-webview-cookies', async (_event: unknown, partition: string,
|
|
|
console.error(`[Main] 设置 cookie 失败 (${cookie.name}):`, error);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
console.log(`[Main] 成功设置 ${successCount}/${cookies.length} 个 cookies`);
|
|
|
-
|
|
|
+
|
|
|
// 验证 Cookie 是否真的设置成功
|
|
|
try {
|
|
|
const setCookies = await ses.cookies.get({ domain: '.baidu.com' });
|
|
|
@@ -462,7 +462,7 @@ ipcMain.handle('set-webview-cookies', async (_event: unknown, partition: string,
|
|
|
} catch (verifyError) {
|
|
|
console.error('[Main] 验证 Cookie 失败:', verifyError);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return true;
|
|
|
} catch (error) {
|
|
|
console.error('[Main] 设置 cookies 失败:', error);
|
|
|
@@ -661,12 +661,12 @@ ipcMain.handle('webview-click-by-text', async (_event: unknown, webContentsId: n
|
|
|
// ========== CDP 网络拦截功能 ==========
|
|
|
// 存储每个 webContents 的网络拦截配置
|
|
|
const networkInterceptors: Map<number, {
|
|
|
- patterns: Array<{match: string, key: string}>;
|
|
|
- pendingRequests: Map<string, {url: string, timestamp: number}>;
|
|
|
+ patterns: Array<{ match: string, key: string }>;
|
|
|
+ pendingRequests: Map<string, { url: string, timestamp: number }>;
|
|
|
}> = new Map();
|
|
|
|
|
|
// 启用 CDP 网络拦截
|
|
|
-ipcMain.handle('enable-network-intercept', async (_event: unknown, webContentsId: number, patterns: Array<{match: string, key: string}>) => {
|
|
|
+ipcMain.handle('enable-network-intercept', async (_event: unknown, webContentsId: number, patterns: Array<{ match: string, key: string }>) => {
|
|
|
try {
|
|
|
const wc = webContents.fromId(webContentsId);
|
|
|
if (!wc) {
|
|
|
@@ -749,7 +749,7 @@ ipcMain.handle('enable-network-intercept', async (_event: unknown, webContentsId
|
|
|
// 获取响应体
|
|
|
const result = await wc.debugger.sendCommand('Network.getResponseBody', { requestId }) as { body: string; base64Encoded: boolean };
|
|
|
let body = result.body;
|
|
|
-
|
|
|
+
|
|
|
// 如果是 base64 编码,解码
|
|
|
if (result.base64Encoded) {
|
|
|
body = Buffer.from(body, 'base64').toString('utf8');
|
|
|
@@ -812,7 +812,7 @@ ipcMain.handle('disable-network-intercept', async (_event: unknown, webContentsI
|
|
|
});
|
|
|
|
|
|
// 更新网络拦截的 patterns
|
|
|
-ipcMain.handle('update-network-patterns', async (_event: unknown, webContentsId: number, patterns: Array<{match: string, key: string}>) => {
|
|
|
+ipcMain.handle('update-network-patterns', async (_event: unknown, webContentsId: number, patterns: Array<{ match: string, key: string }>) => {
|
|
|
const config = networkInterceptors.get(webContentsId);
|
|
|
if (config) {
|
|
|
config.patterns = patterns;
|