feat: add channel open interval configuration and improve page navigation logic
This commit is contained in:
3
.env
3
.env
@@ -8,3 +8,6 @@ VITE_OAUTH2_PASSWORD_CLIENT='pig:pig'
|
||||
|
||||
# 前端加密密钥
|
||||
VITE_PWD_ENC_KEY='thanks,pig4cloud'
|
||||
|
||||
# 渠道打开间隔,单位毫秒
|
||||
CHANNEL_OPEN_INTERVAL_MS=3000
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
require("electron");
|
||||
require("./main-D4EDpIiu.js");
|
||||
require("./main-BSugeX-C.js");
|
||||
require("electron-squirrel-startup");
|
||||
require("electron-log");
|
||||
require("bytenode");
|
||||
|
||||
@@ -43,6 +43,15 @@ const isBlankLikePage = (url) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const getOpenInterval = () => {
|
||||
const raw = process.env.CHANNEL_OPEN_INTERVAL_MS;
|
||||
if (!raw) return 5000;
|
||||
const n = Number(raw);
|
||||
return Number.isFinite(n) && n >= 0 ? n : 5000;
|
||||
};
|
||||
|
||||
(async () => {
|
||||
let browser;
|
||||
|
||||
@@ -66,6 +75,7 @@ const isBlankLikePage = (url) => {
|
||||
});
|
||||
|
||||
const usedPages = new Set();
|
||||
const openInterval = getOpenInterval();
|
||||
|
||||
for (let i = 0; i < channels.length; i++) {
|
||||
const targetUrl = channels[i]?.channelUrl;
|
||||
@@ -103,7 +113,12 @@ const isBlankLikePage = (url) => {
|
||||
const current = page.url();
|
||||
|
||||
if (!current || !isSameTarget(current, targetUrl)) {
|
||||
await page.goto(targetUrl, { waitUntil: 'domcontentloaded' });
|
||||
await page.goto(targetUrl, { waitUntil: 'networkidle' });
|
||||
}
|
||||
|
||||
if (i < channels.length - 1 && openInterval > 0) {
|
||||
log.info(`Channel ${i + 1}/${channels.length} opened. Sleeping ${openInterval}ms before next...`);
|
||||
await sleep(openInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user