Skip to content

Instantly share code, notes, and snippets.

View imansigupta's full-sized avatar
🏠
Working from home

Mansi Gupta imansigupta

🏠
Working from home
View GitHub Profile
@imansigupta
imansigupta / package.json
Created June 10, 2020 10:50
script to be added in package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ."
},
@imansigupta
imansigupta / package.json
Created June 10, 2020 10:53
complete package.json
{
"name": "electron_code",
"version": "1.0.0",
"description": "Electron.js practice code",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ."
},
"keywords": [
@imansigupta
imansigupta / main.js
Created June 10, 2020 10:58
a code snippet from main.js
const { app, BrowserWindow } = require('electron');
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 1536,
height: 900,
frame: true,
webPreferences: {
@imansigupta
imansigupta / index.html
Created June 10, 2020 11:02
A code snippet from index.html
<!DOCTYPE html>
<html lang="en">
<head>
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
<meta charset="UTF-8">
<p id="content_styler">
Electron enables you to create desktop applications with pure JavaScript by providing a runtime with rich native (operating system) APIs. You could see it as a variant of the Node.js runtime that is focused on desktop applications instead of web servers.
</p>
<button id="activate_button" onclick="performFunction()">Click Me!</button>
<script>
function performFunction() {
var p = document.getElementById("content_styler");
p.innerHTML = "I am the changed text";
}
</script>
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 1536,
height: 900,
frame: true,
webPreferences: {
nodeIntegration: true
}
});
const ipcRenderer = require('electron').ipcRenderer;
const btnclick = document.getElementById('activate_button');
btnclick.addEventListener('click', function() {
var arg = "secondparam";
ipcRenderer.send("btnclick", arg); // ipcRender.send will pass the information to main process
});
const { app, BrowserWindow, ipcMain } = require('electron');
//ipcMain.on will receive the “btnclick” info from renderprocess
ipcMain.on("btnclick", function(event, arg) {
var url = "https://www.google.com";
// inform the render process that the assigned task finished.
// event.sender.send in ipcMain will return the reply to renderprocess
event.sender.send("btnclick-task-finished", url);
});