feat: add channel open interval configuration and improve page navigation logic

This commit is contained in:
duanshuwen
2026-04-15 22:08:54 +08:00
parent e77c815a86
commit 5a8e5e4ac2
3 changed files with 21 additions and 3 deletions

3
.env
View File

@@ -8,3 +8,6 @@ VITE_OAUTH2_PASSWORD_CLIENT='pig:pig'
# 前端加密密钥
VITE_PWD_ENC_KEY='thanks,pig4cloud'
# 渠道打开间隔,单位毫秒
CHANNEL_OPEN_INTERVAL_MS=3000

View File

@@ -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");

View File

@@ -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);
}
}