Newton-Editor/newton/main.js

89 lines
2.2 KiB
JavaScript
Raw Normal View History

const { app, ipcMain } = require('electron');
2025-05-28 02:10:45 +00:00
app.commandLine.appendSwitch('disable-renderer-backgrounding');
app.commandLine.appendSwitch('disable-background-timer-throttling');
app.commandLine.appendSwitch('disable-backgrounding-occluded-windows');
2025-05-28 02:10:45 +00:00
const { newton } = require('./app');
let window = null;
2025-05-28 02:10:45 +00:00
2025-05-28 02:10:45 +00:00
const loadHandlers = () => {
ipcMain.handle('getLspConfigData', (eve) => newton.fs.getLspConfigData());
2025-06-13 03:56:03 +00:00
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));
2025-06-13 03:56:03 +00:00
ipcMain.handle('closeFile', (eve, path) => newton.fs.closeFile(path));
ipcMain.handle('saveFileAs', (eve, content) => newton.fs.saveFileAs(content));
2025-05-28 02:10:45 +00:00
}
const createWindow = () => {
window = newton.createWindow(
newton.args.getStartType(),
newton.args.debugMode(),
newton.args.getArgs(),
);
}
app.whenReady().then(async () => {
newton.args.loadArgs();
if ( !await newton.ipc.isIPCServerUp() ) {
newton.ipc.loadIPCServer();
} else {
console.log("IPCServer: Is loaded... sending files to existing app.");
newton.ipc.sendFilesToIPC(
newton.args.getArgs()
);
app.quit();
}
newton.settings.loadsettings();
2025-06-13 03:56:03 +00:00
newton.fs.loadFilesWatcher();
2025-05-28 02:10:45 +00:00
loadHandlers();
createWindow();
newton.fs.setWindow(window);
newton.ipc.setWindow(window);
2025-06-08 04:38:42 +00:00
});
2025-05-28 02:10:45 +00:00
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
2025-05-28 02:10:45 +00:00
};
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
};
2025-06-08 04:38:42 +00:00
newton.settings.saveConfig();
});
2025-05-28 02:10:45 +00:00
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);
}
});