Release v2.1.60 with automatic startup and native crash diagnostics
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
This commit is contained in:
1 parent
ba01b17f8e
commit
a9d1159f7e
4 files changed
+158
-25
No files matched your search
+71
-1
@@ -92,4 +92,74 @@ function summarizeStartupPixels(image) {
|
||||
return { empty: false, width: size.width, height: size.height, whiteRatio: pixels ? Math.round(white / pixels * 1000) / 1000 : 0, darkRatio: pixels ? Math.round(dark / pixels * 1000) / 1000 : 0 };
|
||||
}
|
||||
|
||||
module.exports = { createStartupWindow, resolveStartupLanguage, createStartupQuery, createStartupDiagnostics, summarizeStartupPixels };
|
||||
function createNativeStartupLog({ fs, path, directory, commandLine, now = Date.now, pid = process.pid }) {
|
||||
const logDirectory = path.join(directory, 'startup-logs');
|
||||
const nativePath = path.join(logDirectory, `native-${now()}-${pid}.log`);
|
||||
const nativePattern = /^native-\d+-\d+\.log(?:\.previous)?$/;
|
||||
const reportPattern = /^report-\d+-\d+-\d+\.txt$/;
|
||||
const maxBytes = 2 * 1024 * 1024;
|
||||
let reportSequence = 0;
|
||||
let latestReport = null;
|
||||
let enabled = false;
|
||||
const list = pattern => {
|
||||
try {
|
||||
return fs.readdirSync(logDirectory, { withFileTypes: true })
|
||||
.filter(entry => entry.isFile() && pattern.test(entry.name))
|
||||
.map(entry => ({ name: entry.name, path: path.join(logDirectory, entry.name), modified: fs.statSync(path.join(logDirectory, entry.name)).mtimeMs }))
|
||||
.sort((a, b) => b.modified - a.modified || b.name.localeCompare(a.name));
|
||||
} catch { return []; }
|
||||
};
|
||||
const prune = (pattern, keep, preserve = []) => {
|
||||
const files = list(pattern);
|
||||
const protectedFiles = files.filter(file => preserve.includes(file.path));
|
||||
for (const file of files.filter(file => !preserve.includes(file.path)).slice(Math.max(0, keep - protectedFiles.length))) {
|
||||
try { fs.unlinkSync(file.path); } catch {}
|
||||
}
|
||||
};
|
||||
try {
|
||||
fs.mkdirSync(logDirectory, { recursive: true });
|
||||
fs.writeFileSync(nativePath, '', { flag: 'wx', mode: 0o600 });
|
||||
commandLine.appendSwitch('enable-logging', 'file');
|
||||
commandLine.appendSwitch('log-file', nativePath);
|
||||
commandLine.appendSwitch('log-level', '2');
|
||||
enabled = true;
|
||||
prune(nativePattern, 12, [nativePath, nativePath + '.previous']);
|
||||
} catch {}
|
||||
const maintain = () => {
|
||||
if (!enabled) return false;
|
||||
let descriptor;
|
||||
try {
|
||||
const size = fs.statSync(nativePath).size;
|
||||
if (size <= maxBytes) return true;
|
||||
descriptor = fs.openSync(nativePath, 'r');
|
||||
const buffer = Buffer.alloc(maxBytes);
|
||||
const bytes = fs.readSync(descriptor, buffer, 0, buffer.length, size - buffer.length);
|
||||
fs.closeSync(descriptor);
|
||||
descriptor = undefined;
|
||||
fs.writeFileSync(nativePath + '.previous', buffer.subarray(0, bytes), { mode: 0o600 });
|
||||
fs.truncateSync(nativePath, 0);
|
||||
prune(nativePattern, 12, [nativePath, nativePath + '.previous']);
|
||||
return true;
|
||||
} catch { return false; }
|
||||
finally { if (descriptor !== undefined) { try { fs.closeSync(descriptor); } catch {} } }
|
||||
};
|
||||
const files = () => list(nativePattern).sort((a, b) => Number(b.path === nativePath) - Number(a.path === nativePath))
|
||||
.map(file => ({ label: file.name, path: file.path, maxBytes }));
|
||||
const reports = () => list(reportPattern).sort((a, b) => Number(b.path === latestReport) - Number(a.path === latestReport))
|
||||
.map(file => ({ label: file.name, path: file.path, maxBytes: 5 * 1024 * 1024 }));
|
||||
const saveReport = text => {
|
||||
if (typeof text !== 'string' || Buffer.byteLength(text, 'utf8') > 5 * 1024 * 1024) return null;
|
||||
try {
|
||||
fs.mkdirSync(logDirectory, { recursive: true });
|
||||
const target = path.join(logDirectory, `report-${now()}-${pid}-${reportSequence++}.txt`);
|
||||
fs.writeFileSync(target, text, { flag: 'wx', mode: 0o600 });
|
||||
latestReport = target;
|
||||
prune(reportPattern, 10, [target]);
|
||||
return target;
|
||||
} catch { return null; }
|
||||
};
|
||||
prune(reportPattern, 10);
|
||||
return { enabled, nativePath, logDirectory, files, reports, saveReport, maintain };
|
||||
}
|
||||
|
||||
module.exports = { createStartupWindow, resolveStartupLanguage, createStartupQuery, createStartupDiagnostics, summarizeStartupPixels, createNativeStartupLog };
|
||||
Reference in new issue
Block a user