fix(startup): make renderer initialization deterministic
This commit is contained in:
parent
b11b28e417
commit
cfeb01e82a
5
lib/startup-renderer.js
Normal file
5
lib/startup-renderer.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function configureStartupRenderer(app) {
|
||||||
|
app.disableHardwareAcceleration();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { configureStartupRenderer };
|
||||||
24
main.js
24
main.js
@ -1,6 +1,8 @@
|
|||||||
process.env.UV_THREADPOOL_SIZE = process.env.UV_THREADPOOL_SIZE || '8';
|
process.env.UV_THREADPOOL_SIZE = process.env.UV_THREADPOOL_SIZE || '8';
|
||||||
const { monitorEventLoopDelay, PerformanceObserver } = require('perf_hooks');
|
const { monitorEventLoopDelay, PerformanceObserver } = require('perf_hooks');
|
||||||
const { app, BrowserWindow, ipcMain, dialog, clipboard, nativeTheme, Tray, Menu, nativeImage } = require('electron');
|
const { app, BrowserWindow, ipcMain, dialog, clipboard, nativeTheme, Tray, Menu, nativeImage } = require('electron');
|
||||||
|
const { configureStartupRenderer } = require('./lib/startup-renderer');
|
||||||
|
configureStartupRenderer(app);
|
||||||
nativeTheme.themeSource = 'dark';
|
nativeTheme.themeSource = 'dark';
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -27,16 +29,6 @@ const stats = require('./lib/stats');
|
|||||||
const { createCollectors } = require('./lib/diagnostics-collectors');
|
const { createCollectors } = require('./lib/diagnostics-collectors');
|
||||||
const { createAgent } = require('./lib/diagnostics-agent');
|
const { createAgent } = require('./lib/diagnostics-agent');
|
||||||
|
|
||||||
function _gpuDisableFlagPath() {
|
|
||||||
try { return path.join(app.getPath('userData'), 'gpu-disabled.flag'); } catch { return null; }
|
|
||||||
}
|
|
||||||
(function maybeDisableHardwareAcceleration() {
|
|
||||||
let disable = false;
|
|
||||||
try { if (/^RDP/i.test(process.env.SESSIONNAME || '')) disable = true; } catch {}
|
|
||||||
if (!disable) { try { const f = _gpuDisableFlagPath(); if (f && fs.existsSync(f)) disable = true; } catch {} }
|
|
||||||
if (disable) { try { app.disableHardwareAcceleration(); } catch {} }
|
|
||||||
})();
|
|
||||||
|
|
||||||
const _eventLoopDelay = monitorEventLoopDelay({ resolution: 10 });
|
const _eventLoopDelay = monitorEventLoopDelay({ resolution: 10 });
|
||||||
_eventLoopDelay.enable();
|
_eventLoopDelay.enable();
|
||||||
let _eldLastLog = 0;
|
let _eldLastLog = 0;
|
||||||
@ -1236,6 +1228,7 @@ function createWindow() {
|
|||||||
minWidth: 800,
|
minWidth: 800,
|
||||||
minHeight: 550,
|
minHeight: 550,
|
||||||
backgroundColor: '#16181c',
|
backgroundColor: '#16181c',
|
||||||
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
@ -1245,6 +1238,9 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.setBackgroundThrottling(false);
|
mainWindow.webContents.setBackgroundThrottling(false);
|
||||||
|
mainWindow.once('ready-to-show', () => {
|
||||||
|
mainWindow.show();
|
||||||
|
});
|
||||||
|
|
||||||
mainWindow.webContents.on('render-process-gone', (_event, details) => {
|
mainWindow.webContents.on('render-process-gone', (_event, details) => {
|
||||||
_writeCrashLog('RENDER PROCESS GONE', new Error(details.reason || 'unknown'), details);
|
_writeCrashLog('RENDER PROCESS GONE', new Error(details.reason || 'unknown'), details);
|
||||||
@ -1288,12 +1284,12 @@ function createWindow() {
|
|||||||
app.on('child-process-gone', (_event, details) => {
|
app.on('child-process-gone', (_event, details) => {
|
||||||
_writeCrashLog('CHILD PROCESS GONE', new Error(details.reason || 'unknown'), details);
|
_writeCrashLog('CHILD PROCESS GONE', new Error(details.reason || 'unknown'), details);
|
||||||
debugLog(`CHILD PROCESS GONE: type=${details.type} reason=${details.reason} exitCode=${details.exitCode}`);
|
debugLog(`CHILD PROCESS GONE: type=${details.type} reason=${details.reason} exitCode=${details.exitCode}`);
|
||||||
if (details && details.type === 'GPU') {
|
|
||||||
try { const f = _gpuDisableFlagPath(); if (f) fs.writeFileSync(f, new Date().toISOString(), 'utf-8'); } catch {}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html')).catch((err) => {
|
||||||
|
_writeCrashLog('LOAD FILE FAILED', err);
|
||||||
|
debugLog(`LOAD FILE FAILED: ${err && err.stack ? err.stack : err}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTray() {
|
function createTray() {
|
||||||
|
|||||||
9
tests/startup-renderer.test.js
Normal file
9
tests/startup-renderer.test.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const { configureStartupRenderer } = require('../lib/startup-renderer');
|
||||||
|
|
||||||
|
test('configureStartupRenderer disables hardware acceleration', () => {
|
||||||
|
let calls = 0;
|
||||||
|
configureStartupRenderer({ disableHardwareAcceleration() { calls++; } });
|
||||||
|
assert.equal(calls, 1);
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user