// main.js // const { app, BrowserWindow} = require('electron'); const { app, BrowserWindow, ipcMain, Menu } = require('electron'); const fs = require('fs'); const path = require('path'); const jquery = require('jquery'); let onlineStatus = true; const { dialog } = require('electron'); const saveFile = require('./savexml') require('dotenv').config({ path: path.join(__dirname, '.env') }); let mainWindow; const auto_close= process.env.DISABLE_AUTO_CLOSE; const auto_close_time = parseInt(process.env.AUTO_CLOSE_TIME) * 1000; async function createWindow() { mainWindow = new BrowserWindow({ width: 1200, height: 800, webPreferences: { nodeIntegration: true, contextIsolation: false, }, }); // mainWindow.removeMenu() mainWindow.loadFile('dashboard.html'); // Create an HTML file for your interface if(process.env.ENABLE_DEV_TOOLS === 'TRUE') { if (mainWindow) { mainWindow.webContents.toggleDevTools(); } } else{ mainWindow.webContents.on('did-finish-load', () => { const customMenu = buildCustomMenu(); Menu.setApplicationMenu(customMenu); }); } mainWindow.on('closed', function () { mainWindow = null; }); setInterval(checkInternetConnection, 5000); } //Function for Remove the FrocewReload, Reload, ToggleDeveloperOption function buildCustomMenu() { const template = [ { label: 'File', submenu: [ { label: 'Exit', click: () => app.quit(), }, ], }, { label: 'Edit', submenu: [ { role: 'copy', }, { role: 'cut', }, { role: 'paste', }, { role: 'undo', }, { role: 'redo', }, ].filter(Boolean), }, { label: 'View', submenu: [ { label: 'Actual Size', click: () => { mainWindow.webContents.setZoomLevel(0); }, }, { label: 'Zoom In', click: () => { const currentZoomLevel = mainWindow.webContents.getZoomLevel(); mainWindow.webContents.setZoomLevel(currentZoomLevel + 1); }, }, { label: 'Zoom Out', click: () => { const currentZoomLevel = mainWindow.webContents.getZoomLevel(); mainWindow.webContents.setZoomLevel(currentZoomLevel - 1); }, }, { role: 'togglefullscreen', }, ].filter(Boolean), }, { label: 'Window', submenu: [ { role: 'minimize', }, { role: 'close', }, ].filter(Boolean), }, ]; return Menu.buildFromTemplate(template); } //End of Function for Remove the FrocewReload, Reload, ToggleDeveloperOption async function checkInternetConnection() { try { const response = await fetch('https://www.google.com'); if (response.ok && onlineStatus) { onlineStatus = false; if (auto_close === 'TRUE') { }else{ dialog.showMessageBox(mainWindow, { type: 'info', message: `Internet is available. Click OK to close the app. Otherwise app will auto close in ${auto_close_time/1000} Seconds`, buttons: ['OK'], }); //Send the tigger to AutoSave the question Paper when System come's online mainWindow.webContents.send('button-click'); setTimeout(() => { app.quit(); }, auto_close_time); } } else if (!response.ok && !onlineStatus) { onlineStatus = true; } } catch (error) { console.error('Error checking internet connection'); } } app.on('ready', createWindow); app.on('window-all-closed', function () { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', function () { if (mainWindow === null) { createWindow(); } });