Fixed SIGINT and SIGTERM exit calls to save settings

This commit is contained in:
itdominator 2025-06-19 00:00:04 -05:00
parent 53bbfe2bc7
commit 18ac9b323d

View File

@ -9,9 +9,61 @@ const { newton } = require('./app');
let window = null; let window = null;
let hasExitSaved = false;
const createWindow = () => {
window = newton.createWindow(
newton.args.getStartType(),
newton.args.debugMode(),
newton.args.getArgs(),
);
}
const handleExitSignal = (code) => {
if (!hasExitSaved) {
newton.settings.saveConfig();
hasExitSaved = true;
}
process.exit(code);
}
const loadProcessSignalHandlers = () => {
process.on('SIGINT', () => {
// https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
handleExitSignal(128 + 2);
});
process.on('SIGTERM', () => {
// https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
handleExitSignal(128 + 15);
});
process.on('uncaughtException', (error) => {
if (error.message != null) {
console.log(error.message);
}
if (error.stack != null) {
console.log(error.stack);
}
});
process.on('unhandledRejection', function(error = {}) {
if (error.message != null) {
console.log(error.message);
}
if (error.stack != null) {
console.log(error.stack);
}
});
}
const loadHandlers = () => { const loadHandlers = () => {
ipcMain.handle('getLspConfigData', (eve) => newton.fs.getLspConfigData()); ipcMain.handle('getLspConfigData', (eve) => newton.fs.getLspConfigData());
ipcMain.handle('getFileContents', (eve, path) => newton.fs.getFileContents(path)); ipcMain.handle('getFileContents', (eve, path) => newton.fs.getFileContents(path));
@ -21,16 +73,8 @@ const loadHandlers = () => {
ipcMain.handle('saveFileAs', (eve, content) => newton.fs.saveFileAs(content)); ipcMain.handle('saveFileAs', (eve, content) => newton.fs.saveFileAs(content));
} }
const createWindow = () => {
window = newton.createWindow(
newton.args.getStartType(),
newton.args.debugMode(),
newton.args.getArgs(),
);
}
app.whenReady().then(async () => { app.whenReady().then(async () => {
loadProcessSignalHandlers();
newton.args.loadArgs(); newton.args.loadArgs();
if ( !await newton.ipc.isIPCServerUp() ) { if ( !await newton.ipc.isIPCServerUp() ) {
@ -68,22 +112,4 @@ app.on('window-all-closed', () => {
newton.settings.saveConfig(); newton.settings.saveConfig();
}); });
process.on('uncaughtException', (error) => {
if (error.message != null) {
console.log(error.message);
}
if (error.stack != null) {
console.log(error.stack);
}
});
process.on('unhandledRejection', function(error = {}) {
if (error.message != null) {
console.log(error.message);
}
if (error.stack != null) {
console.log(error.stack);
}
});