Add GPU error handling and performance optimizations

Introduces a comprehensive GPU configuration and fallback system to resolve GPU process launch failures (Error 18), including new modules for GPU management and performance monitoring. Adds a GPU diagnostics HTML page, optimized CSS for rendering, and a diagnostic startup script. Updates main and preload scripts for improved stability, async file operations, and enhanced API exposure. Site history and bookmarks handling are optimized for performance and reliability.
This commit is contained in:
2025-07-26 14:38:05 +12:00
parent 0b61f86dd4
commit fbd9ba8a1b
10 changed files with 1081 additions and 59 deletions
+105
View File
@@ -0,0 +1,105 @@
// gpu-fallback.js - GPU error handling and fallback system
const { app } = require('electron');
class GPUFallback {
constructor() {
this.gpuEnabled = true;
this.fallbackLevel = 0;
this.maxFallbacks = 3;
}
// Apply progressive GPU fallbacks
applyFallback(level = 0) {
console.log(`Applying GPU fallback level ${level}`);
switch (level) {
case 0:
// Level 0: Conservative GPU settings (already applied in main.js)
break;
case 1:
// Level 1: Disable hardware acceleration for some features
app.commandLine.appendSwitch('disable-accelerated-2d-canvas');
app.commandLine.appendSwitch('disable-accelerated-jpeg-decoding');
break;
case 2:
// Level 2: Software rendering only
app.commandLine.appendSwitch('disable-gpu');
app.commandLine.appendSwitch('disable-gpu-compositing');
this.gpuEnabled = false;
break;
case 3:
// Level 3: Most conservative settings
app.commandLine.appendSwitch('disable-gpu');
app.commandLine.appendSwitch('disable-gpu-compositing');
app.commandLine.appendSwitch('disable-software-rasterizer');
app.commandLine.appendSwitch('disable-2d-canvas-image-chromium');
this.gpuEnabled = false;
break;
default:
console.warn('Maximum fallback level reached');
}
this.fallbackLevel = level;
}
// Check if GPU is working properly
async checkGPUStatus() {
try {
const gpuInfo = app.getGPUFeatureStatus();
// Check for critical GPU failures
const criticalFeatures = ['gpu_compositing', 'webgl', 'webgl2'];
const failures = criticalFeatures.filter(feature =>
gpuInfo[feature] && gpuInfo[feature].includes('disabled')
);
if (failures.length > 0) {
console.warn('GPU features disabled:', failures);
return false;
}
return true;
} catch (err) {
console.error('GPU status check failed:', err);
return false;
}
}
// Handle GPU process crashes
setupCrashHandling() {
let crashCount = 0;
app.on('gpu-process-crashed', (event, killed) => {
crashCount++;
console.error(`GPU process crashed (count: ${crashCount}), killed: ${killed}`);
if (crashCount >= 3 && this.fallbackLevel < this.maxFallbacks) {
console.log('Too many GPU crashes, applying fallback...');
this.applyFallback(this.fallbackLevel + 1);
// Restart the app if needed
if (!killed) {
setTimeout(() => {
app.relaunch();
app.exit();
}, 1000);
}
}
});
}
// Get current GPU status
getStatus() {
return {
gpuEnabled: this.gpuEnabled,
fallbackLevel: this.fallbackLevel,
isHardwareAccelerated: this.fallbackLevel < 2
};
}
}
module.exports = GPUFallback;