bradtraversy / electronshoppinglist Goto Github PK
View Code? Open in Web Editor NEWShopping list desktop app built on electron
Shopping list desktop app built on electron
I have followed your instructions precisely as shown in your video, yet I always get an error saying-
TypeError: Cannot read property 'on' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: electron .
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
I am very confused because it worked yesterday, but won't work today. I feel like it has something to due with the packages. Maybe you can't install the same package 2x's? Please help and thank you for your time!
Index.js File -
const electron = require('electron');
const path = require('path');
const url = require('url');
const {app, BrowserWindow} = electron;
let mainWin;
// Listen for app to be ready
app.on('ready', function(){
// Create new window
mainWin = new BrowserWindow({});
mainWin.loadURL(url.format({
pathname: path.join(__dirname, 'app', 'index.html'),
protocol: 'file:',
slashes: true
}));
mainWin.on('closed', function(){
app.quit();
});
});
Package.json File -
{
"name": "calculator",
"version": "1.0.0",
"description": "Simple Calculator",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"author": "Carter Snook",
"license": "ISC",
"dependencies": {
"electron": "^4.1.1"
}
}
I had to modify the code in main.js to make the app working on macOS :
// If OSX, add empty object to menu
if(process.platform == 'darwin'){
mainMenuTemplate.unshift({label: app.getName()});
}
Hi Brad, First of all thank you for your awesome course!
Currently when we click on add item
button on add window we get an error as require is not defined
.
Robb and Israel had proposed a solution in your video to enable nodeIntegration
in browserWindow
with a parameter as:
new BrowserWindow(
{
webPreferences: {
nodeIntegration: true
}
}
)
Adding this as an issue for tracking. :)
i tried even with npm start electron
its not working :(
CANNOT RUN WITH NODE 12.4.0
Electron Packager requires Node 4.0 or above.
C:\Users\aaron\Examples\electronshoppinglist>npm run package-win
> [email protected] package-win C:\Users\aaron\Examples\electronshoppinglist
> electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName="Shopping List"
CANNOT RUN WITH NODE 12.4.0
Electron Packager requires Node 4.0 or above.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] package-win: `electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName="Shopping List"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] package-win script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\aaron\AppData\Roaming\npm-cache\_logs\2019-07-11T22_33_19_783Z-debug.log```
This happened when I had to close all other windows when we close the main window. Couldn't find a solution to this. The error is for mainWindow.on("closed", function () { app.quit(); });
Below is my code.
const electron = require("electron");
const url = require("url");
const path = require("path");
const { app, BrowserWindow, Menu } = electron;
let mainWindow;
let addWindow;
//Listen for app to be ready
app.on("ready", function () {
//Create new window
mainwindow = new BrowserWindow({});
//Load the html file
mainwindow.loadURL(
url.format({
pathname: path.join(__dirname, "mainWindow.html"),
protocol: "file:",
slashes: true,
})
);
// Quit app when closed
mainWindow.on("closed", function () {
app.quit();
});
//Build the menu from template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
//Insert the menu
Menu.setApplicationMenu(mainMenu);
});
//Handle create add window
function createAddWindow() {
addWindow = new BrowserWindow({
width: 300,
height: 200,
title: "Add shopping list item",
});
//Load the html file
addWindow.loadURL(
url.format({
pathname: path.join(__dirname, "addWindow.html"),
protocol: "file:",
slashes: true,
})
);
}
//Create menu template
const mainMenuTemplate = [
{
label: "File",
submenu: [
{
label: "Add Item",
click() {
createAddWindow();
},
},
{
label: "Clear Items",
},
{
label: "Quit",
accelerator: process.platform == "darwin" ? "Command+Q" : "Ctrl+Q",
click() {
app.quit();
},
},
],
},
];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.