Need help with my applications I am making


#1

So i am new to Electron and still learning but I updated my electron prebuilt in the app modules and I am getting this error and stuck on how to fix it.

Uncaught Exception:
TypeError: Cannot read property ‘on’ of null
at EventEmitter. (/home/corey/stuff/apps/built-apps/Google-Play-Music/GooglePlayMusic-linux-x64/resources/app/main.js:28:13)
at emitOne (events.js:101:20)
at EventEmitter.emit (events.js:188:7)

This is my code

var app = require(‘electron’).app
var BrowserWindow = require(‘electron’).BrowserWindow
// Report crashes to our server.

// Keep a global reference of the window object, if you don’t, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on(‘window-all-closed’, function() {
if (process.platform != ‘darwin’)
app.quit();
});

// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on(‘ready’, function() {
// In the main process.
const {BrowserWindow} = require(‘electron’)

let win = new BrowserWindow({width: 1200, height: 900})
win.on(‘closed’, () => {
win = null
})

win.loadURL(‘https://play.google.com/music/listen?u=0#/now’)
// Emitted when the window is closed.
mainWindow.on(‘closed’, function() {
// Remove mainWindow.on(‘closed’, function() { if you want the menu back
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});


#2

Looks like that line u haven’t assigned mainWindow anything after declaring it as null.


#3

What do I set it to or do next? I don’t know what the arguments or options are for MainWindow.on

or is what you said my solution doing mainWindow.on(‘closed’, function() { ?


#4

Try this…

var app = require('electron').app
var BrowserWindow = require('electron').BrowserWindow
// Report crashes to our server.

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
  if (process.platform != 'darwin')
    app.quit();
});

// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
  // In the main process.
  const {BrowserWindow} = require('electron')

  mainWindow = new BrowserWindow({width: 1200, height: 900})

  mainWindow.loadURL('https://play.google.com/music/listen?u=0#/now')

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Remove mainWindow.on('closed', function() { if you want the menu back
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
});

#5

Hey that fixed the problem and runs perfectly thanks for that so what did you do exactly?


#6

I removed your reference to the variable 'win’
And used the 'mainWindow variable you declared initially.
Glad it worked for u :slight_smile:


#7

It did help indeed, I will continue learning and developing apps, thanks heaps for your time! :slight_smile:


#8

My pleasure mate.
Always great to have another developer in the world :grin:


#9

I agree with that! :smiley:


#10

I have another question how do I set the windows size of a new window opened in a application?


#11

You can set the size in this line here, by changing the height and width values:
mainWindow = new BrowserWindow({width: 1200, height: 900})


#12

So by doing that any new window opened in the already sized set app window will be able to be set like the main parent window?


#13

Ah, no. But every time you create a new window, you’ll be building it using the new BrowserWindow(options) constructor, in which you’ll use an object literal like {width: 1200, height: 900} to set the properties of the window.


#14

So where do I place this exactly?


#15

I need a bit more context on what you’re trying to do.

You’ll call that whenever you want to open a link out into a new window. It won’t work with the Play Store link you’re using, because you don’t have access to that code, but if it opens out new pages, you could potentially listen for that and apply a new size to them.

But really, I need a better idea of what you’re trying to do.


#16

It wasn’t for this play music app I made it was for something else I want to be able to set the default size on new pages that open up in a new windows which open in a smaller window than the one I set for my app.


#17

So what’s the code you’re using for opening new windows? Or have you not got that far?