Close a sub-window


#1

hi all
i have an app with 2 windows , i can call an ipc messeage from the main( from render prossecc under the main) to show the sub window . but when i click the close button it give me an error

Uncaught Exception: 
Error: Object has been destroyed
at Error(native)
at EventEmitter.<anonymous> 
...

here is my app.js code :

const electron = require('electron');
const app = electron.app;  // Module to control application life.
const BrowserWindow = electron.BrowserWindow;  // Module to create native browser window.
const ipc = electron.ipcMain;
const Menu = electron.Menu;
const mysql      = require('mysql');

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

app.on('ready', function() {
    mainWindow = new BrowserWindow({width: 1280, height: 700,minWidth:1280, minHeight: 700 ,maximizable : true});
    mainWindow.loadURL('file://' + __dirname + '/app/index.html');

   
    const newProject = new BrowserWindow({width: 1000, height: 700 ,minWidth: 1000, minHeight: 700 ,maximizable : true,show: false})
    newProject.loadURL('file://'+ __dirname +'/project/project.html');


    ipc.on('show-project-win', function(){
       newProject.show();
    });

    newProject.on('closed',function(e){
        e.preventDefault();
        newProject.hide();
    });

    mainWindow.on('closed', function() {
        connection.end();
        mainWindow = null;
    }    );
});

#2

i found the solution in this post :
https://discuss.atom.io/t/object-has-been-destroyed-when-open-secondary-child-window/30880/4?u=spyshow


#3

Closing this as a duplicate of the other post linked above.


#4