2025-06-01 13:49:18 -05:00
|
|
|
const { app, ipcMain } = require('electron');
|
2025-05-27 21:10:45 -05:00
|
|
|
|
2025-06-15 17:47:11 -05:00
|
|
|
app.commandLine.appendSwitch('disable-renderer-backgrounding');
|
|
|
|
app.commandLine.appendSwitch('disable-background-timer-throttling');
|
|
|
|
app.commandLine.appendSwitch('disable-backgrounding-occluded-windows');
|
|
|
|
|
2025-05-27 21:10:45 -05:00
|
|
|
const { newton } = require('./app');
|
|
|
|
|
|
|
|
|
2025-06-15 17:47:11 -05:00
|
|
|
|
2025-06-19 00:00:04 -05:00
|
|
|
let window = null;
|
|
|
|
let hasExitSaved = false;
|
2025-06-14 02:07:12 -05:00
|
|
|
|
2025-05-27 21:10:45 -05:00
|
|
|
|
2025-06-15 17:47:11 -05:00
|
|
|
|
2025-06-14 02:07:12 -05:00
|
|
|
const createWindow = () => {
|
|
|
|
window = newton.createWindow(
|
|
|
|
newton.args.getStartType(),
|
2025-06-19 01:26:17 -05:00
|
|
|
newton.args.getDebugMode(),
|
2025-06-14 02:07:12 -05:00
|
|
|
newton.args.getArgs(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-06-19 00:00:04 -05:00
|
|
|
const handleExitSignal = (code) => {
|
|
|
|
if (!hasExitSaved) {
|
2025-06-19 00:57:55 -05:00
|
|
|
newton.settings.saveConfig(window);
|
2025-06-19 00:00:04 -05:00
|
|
|
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 = () => {
|
2025-06-19 01:17:13 -05:00
|
|
|
ipcMain.handle('quit', (eve) => app.quit());
|
|
|
|
ipcMain.handle('toggleFullScreen', (eve) => { window.setFullScreen(!window.isFullScreen()); });
|
2025-06-19 00:00:04 -05:00
|
|
|
ipcMain.handle('getLspConfigData', (eve) => newton.fs.getLspConfigData());
|
|
|
|
ipcMain.handle('getFileContents', (eve, path) => newton.fs.getFileContents(path));
|
|
|
|
ipcMain.handle('openFiles', (eve, startPath) => newton.fs.openFiles(startPath));
|
|
|
|
ipcMain.handle('saveFile', (eve, path, content) => newton.fs.saveFile(path, content));
|
|
|
|
ipcMain.handle('closeFile', (eve, path) => newton.fs.closeFile(path));
|
2025-07-13 14:41:46 -05:00
|
|
|
ipcMain.handle('saveFileAs', (eve) => newton.fs.saveFileAs());
|
|
|
|
ipcMain.handle('chooseFolder', (eve) => newton.fs.chooseFolder());
|
2025-06-19 00:00:04 -05:00
|
|
|
}
|
2025-06-01 13:49:18 -05:00
|
|
|
|
2025-06-14 02:07:12 -05:00
|
|
|
app.whenReady().then(async () => {
|
2025-06-19 00:00:04 -05:00
|
|
|
loadProcessSignalHandlers();
|
2025-06-08 22:21:24 -05:00
|
|
|
newton.args.loadArgs();
|
2025-06-14 02:07:12 -05:00
|
|
|
|
2025-07-14 23:00:36 -05:00
|
|
|
newton.ipc.configure( newton.args.getIpcPort() );
|
2025-06-14 02:07:12 -05:00
|
|
|
if ( !await newton.ipc.isIPCServerUp() ) {
|
|
|
|
newton.ipc.loadIPCServer();
|
|
|
|
} else {
|
|
|
|
console.log("IPCServer: Is loaded... sending files to existing app.");
|
2025-06-15 18:15:39 -05:00
|
|
|
newton.ipc.sendFilesToIPC(
|
2025-06-14 02:07:12 -05:00
|
|
|
newton.args.getArgs()
|
|
|
|
);
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
|
2025-06-19 20:03:02 -05:00
|
|
|
newton.settings.loadSettings();
|
2025-06-12 22:56:03 -05:00
|
|
|
newton.fs.loadFilesWatcher();
|
2025-06-14 02:07:12 -05:00
|
|
|
|
2025-05-27 21:10:45 -05:00
|
|
|
loadHandlers();
|
2025-06-14 02:07:12 -05:00
|
|
|
createWindow();
|
2025-06-01 13:49:18 -05:00
|
|
|
|
|
|
|
newton.fs.setWindow(window);
|
2025-06-15 00:43:33 -05:00
|
|
|
newton.ipc.setWindow(window);
|
2025-06-14 02:07:12 -05:00
|
|
|
|
2025-06-07 23:38:42 -05:00
|
|
|
});
|
2025-05-27 21:10:45 -05:00
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
2025-06-14 02:07:12 -05:00
|
|
|
createWindow();
|
2025-05-27 21:10:45 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
};
|
2025-06-19 01:26:17 -05:00
|
|
|
});
|