|
|
@@ -148,6 +148,12 @@ export function progressTrackingPlugin() {
|
|
|
console.log('timeSinceLastResource:', timeSinceLastResource);
|
|
|
console.log('isLoading:', isLoading);
|
|
|
|
|
|
+ // 如果已经不在加载状态,直接返回
|
|
|
+ if (!isLoading) {
|
|
|
+ console.log('⚠️ Not loading anymore, exiting checkCompletion');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 根据服务端活动情况调整完成条件
|
|
|
if (!hasServerActivity) {
|
|
|
console.log('Checking client-only completion conditions...');
|
|
|
@@ -177,9 +183,23 @@ export function progressTrackingPlugin() {
|
|
|
} else {
|
|
|
console.log('Checking mixed mode completion conditions...');
|
|
|
|
|
|
- // 有服务端编译时的完成条件
|
|
|
+ // 有服务端编译时的完成条件 - 添加多个完成条件
|
|
|
if (serverProgress >= 1.0 && timeSinceLastResource > 1500) {
|
|
|
- console.log('✅ Server + client loading complete');
|
|
|
+ console.log('✅ Server + client loading complete (1.5s timeout)');
|
|
|
+ forceComplete();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加基于资源完成度的提前完成条件
|
|
|
+ if (serverProgress >= 1.0 && resourcesCompleted >= estimatedTotal * 0.95 && timeSinceLastResource > 800) {
|
|
|
+ console.log('✅ Server + client loading complete (95% resources + 0.8s)');
|
|
|
+ forceComplete();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果服务端完成且资源接近完成,更短的等待时间
|
|
|
+ if (serverProgress >= 1.0 && resourcesCompleted >= estimatedTotal * 0.98 && timeSinceLastResource > 600) {
|
|
|
+ console.log('✅ Server + client loading complete (98% resources + 0.6s)');
|
|
|
forceComplete();
|
|
|
return;
|
|
|
}
|
|
|
@@ -187,17 +207,53 @@ export function progressTrackingPlugin() {
|
|
|
console.log('❌ Mixed mode conditions not met');
|
|
|
console.log('serverProgress >= 1.0:', serverProgress >= 1.0);
|
|
|
console.log('timeSinceLastResource > 1500:', timeSinceLastResource > 1500);
|
|
|
+ console.log('resourcesCompleted >= estimatedTotal * 0.95:', resourcesCompleted >= estimatedTotal * 0.95);
|
|
|
}
|
|
|
|
|
|
// 超时强制完成 - 进一步缩短超时时间
|
|
|
if (timeSinceLastResource > 2000) {
|
|
|
console.log('⏰ Force completing due to timeout (2s)');
|
|
|
forceComplete();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关键修复:如果条件未满足,重新调度检查
|
|
|
+ // 根据当前状态动态计算下次检查的时间间隔
|
|
|
+ let nextCheckDelay;
|
|
|
+
|
|
|
+ if (hasServerActivity && serverProgress >= 1.0) {
|
|
|
+ // 服务端已完成,更频繁地检查
|
|
|
+ const remainingTimeFor1500 = Math.max(1500 - timeSinceLastResource, 0);
|
|
|
+ const remainingTimeFor800 = Math.max(800 - timeSinceLastResource, 0);
|
|
|
+
|
|
|
+ if (resourcesCompleted >= estimatedTotal * 0.95) {
|
|
|
+ nextCheckDelay = Math.max(remainingTimeFor800, 200);
|
|
|
+ } else {
|
|
|
+ nextCheckDelay = Math.max(remainingTimeFor1500, 300);
|
|
|
+ }
|
|
|
+ } else if (!hasServerActivity) {
|
|
|
+ // 客户端模式,根据资源完成度调整检查频率
|
|
|
+ if (resourcesCompleted >= estimatedTotal * 0.97) {
|
|
|
+ nextCheckDelay = Math.max(500 - timeSinceLastResource, 200);
|
|
|
+ } else if (resourcesCompleted >= estimatedTotal * 0.95) {
|
|
|
+ nextCheckDelay = Math.max(1000 - timeSinceLastResource, 300);
|
|
|
+ } else {
|
|
|
+ nextCheckDelay = Math.max(1000 - timeSinceLastResource, 500);
|
|
|
+ }
|
|
|
} else {
|
|
|
- console.log('⏳ Waiting for timeout, remaining:', 2000 - timeSinceLastResource, 'ms');
|
|
|
+ // 服务端还在处理中,较长的检查间隔
|
|
|
+ nextCheckDelay = 500;
|
|
|
}
|
|
|
|
|
|
+ // 确保最小检查间隔
|
|
|
+ nextCheckDelay = Math.max(nextCheckDelay, 200);
|
|
|
+
|
|
|
+ console.log('⏳ Rescheduling completion check in:', nextCheckDelay, 'ms');
|
|
|
console.log('=== End checkCompletion Debug ===');
|
|
|
+
|
|
|
+ // 重新调度下次检查
|
|
|
+ if (completionTimer) clearTimeout(completionTimer);
|
|
|
+ completionTimer = setTimeout(checkCompletion, nextCheckDelay);
|
|
|
}
|
|
|
|
|
|
// 强制完成
|