Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
2.6 kB
3
Indexable
Never
//app.js
const taskForm = document.querySelector('#taskForm1')
const Username = document.querySelector('#Username')
const Password = document.querySelector('#Password')

 const { ipcRenderer } = require('electron')


taskForm.addEventListener("submit",async e=>{
  e.preventDefault();
const user ={
        name: Username.value,
        pass: Password.value
    }
   
   console.log(user)
    ipcRenderer.invoke('new', user).then(()=> console.log('new user entered')).catch((err)=> console.error('Error'))

     
      
}),
     
   
    ipcRenderer.on('new-user-created', (e, arg) => {
        
             const newUser= JSON.parse(arg);
             console.log(newUser)
    })
      
   
//main.js
/*const electron = require("electron");
const url = require("url");
const path = require("path");*/

const { app, BrowserWindow, ipcMain } = require('electron');
const user = require('./models/user.js')
let mainWindow, win;

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 700,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      traceProcessWarnings: true,
    },
  });
  win.loadFile('index.html');
}

function createWindow_1() {
  const mainWindow = new BrowserWindow({
    width: 1400, height: 1050,
  });

  mainWindow.loadFile('main.html');
}



/*   mainWindow.on('closed', () => {
       mainWindow = null;
   })
}

app.on("ready", createWindow);

app.on('window-all-closed', () => {
   if(process.platform !== 'darwin'){
       app.quit()
   }
});

app.on('activate',() => {
   if (win === null){
       createWindow()
   }
});*/
/*
ipcMain.handle('new', async (e, arg) => {
   const newUser = new user(arg)

   const userSaved = await newUser.save()
   console.log(userSaved)
  e.sender.send('new-user-created',JSON.stringify(userSaved))
 })

 ipcMain.handle("get-tasks", async (e, arg) => {
    const tasks = await Task.find();
    e.sender.send("get-tasks", JSON.stringify(tasks));
  });
  
  ipcMain.handle("delete-task", async (e, args) => {
    const taskDeleted = await Task.findByIdAndDelete(args);
    e.sender.send("delete-task-success", JSON.stringify(taskDeleted));
  });
  
  ipcMain.handle("update-task", async (e, args) => {
    console.log(args);
    const updatedTask = await Task.findByIdAndUpdate(
      args.idTaskToUpdate,
      { name: args.name, pass: args.pass },
      { new: true }
    );
    e.sender.send("update-task-success", JSON.stringify(updatedTask));
  });

*/
module.exports = { createWindow_1, createWindow }
app.whenReady().then(createWindow_1)
app.whenReady().then(createWindow)