import { app, shell, BrowserWindow, ipcMain, Tray } from 'electron' import { join } from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import icon from '../../resources/icon.png?asset' const { loginUser, forgotPassword, insertUser, updateUser } = require('../../database/Models/Users') const { insertEtudiant, getSingleEtudiant, FilterDataByNiveau, updateEtudiant } = require('../../database/Models/Etudiants') const { insertNiveau } = require('../../database/Models/Niveau') const { insertNote } = require('../../database/Models/Notes') // declare mainWindow in the global scope let mainWindow let tray = null function createWindow() { // Create the browser window. mainWindow = new BrowserWindow({ width: 1000, minWidth: 1000, height: 670, minHeight: 670, show: false, autoHideMenuBar: true, fullscreen: true, // This will make the window fullscreen when opened ...(process.platform === 'linux' ? { icon } : {}), webPreferences: { preload: join(__dirname, '../preload/index.js'), nodeIntegration: true, contextIsolation: true, sandbox: false } }) mainWindow.on('ready-to-show', () => { mainWindow.show() }) mainWindow.webContents.setWindowOpenHandler((details) => { shell.openExternal(details.url) return { action: 'deny' } }) // HMR for renderer base on electron-vite cli. // Load the remote URL for development or the local html file for production. if (is.dev && process.env['ELECTRON_RENDERER_URL']) { mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) } else { mainWindow.loadFile(join(__dirname, '../renderer/index.html')) } } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(() => { // Set app user model id for windows electronApp.setAppUserModelId('com.electron') // Default open or close DevTools by F12 in development // and ignore CommandOrControl + R in production. // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils app.on('browser-window-created', (_, window) => { optimizer.watchWindowShortcuts(window) }) // IPC test ipcMain.on('pingpong', () => console.log('pongsss')) createWindow() app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) // In this file you can include the rest of your app"s specific main process // code. You can also put them in separate files and require them here. // Event for handling login ipcMain.handle('login', async (event, credentials) => { const { username, password } = credentials const users = await loginUser(username, password) if (users) { return { success: true, user: users } } else { return { success: false } } }) // Event for handling insert other user ipcMain.handle('insertUser', async (event, credentials) => { const { username, email, password, roles } = credentials const users = await insertUser(username, email, password, roles) return users }) // event for handlign forgot password ipcMain.handle('forgotPassword', async (event, credentials) => { const { email, password, passwordConfirmation } = credentials const updated = await forgotPassword(email, password, passwordConfirmation) if (updated) { return updated } }) // event for updating users ipcMain.handle('updateUsers', async (event, credentials) => { const { username, email, passwordVerif, password, id } = credentials const update = await updateUser(username, email, password, id) return update }) // event for quit app ipcMain.handle('quit', async () => { app.quit() }) // event for minimizing the app ipcMain.handle('minimize', async () => { if (mainWindow) { mainWindow.minimize() } }) // event for insert etudiants ipcMain.handle('insertEtudiant', async (event, credentials) => { const { nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription } = credentials const insert = await insertEtudiant( nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription ) return insert }) // event for fetching single ipcMain.handle('getByNiveau', async (event, credentials) => { const { niveau } = credentials const getSingle = await FilterDataByNiveau(niveau) return getSingle }) // event for fetching single ipcMain.handle('single', async (event, credentials) => { const { id } = credentials const getSingle = await getSingleEtudiant(id) return getSingle }) // event for inserting niveau ipcMain.handle('insertNiveau', async (event, credentials) => { const { nom } = credentials const insert = await insertNiveau(nom) return insert }) // event for updating etudiants ipcMain.handle('updateETudiants', async (event, credentials) => { const { nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription, id } = credentials const updating = await updateEtudiant( nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription, id ) return updating }) // event for adding notes ipcMain.handle('insertNote', async (event, credentials) => { const { etudiant_id, Algebre, Analyse, Mecanique_Generale_I, Resistance_Materiaux, Electricite, Chimie_Generale_1, Algorithmique, Thermodynamique_Physique, Mecanique_Fluide, Optique_Geometrique, Calcul_Numerique, Calcul_Vectoriel_Integral, Francais, Anglais, Dessin_Technique, Programmation } = credentials const insert = await insertNote( etudiant_id, Algebre, Analyse, Mecanique_Generale_I, Resistance_Materiaux, Electricite, Chimie_Generale_1, Algorithmique, Thermodynamique_Physique, Mecanique_Fluide, Optique_Geometrique, Calcul_Numerique, Calcul_Vectoriel_Integral, Francais, Anglais, Dessin_Technique, Programmation ) return insert })