Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
in Technique[技术] by (71.8m points)

reactjs - Error: Object has been destroyed when trying to re-open a second BrowserWindow - Electron.js

In an electron-react-typescript app I use a button in the mainwindow to open a new window. If I close this second window clicking on the 'x' on the top-tight corner, when clicking the button in the mainwindow I get this message: "Error invoking remote method. TypeError: Object has been destroyed". I found this: Object has been destroyed Exception after reopen BrowserWindow on button click in Electron . But that suggestion doesn't help me, because clicking on the button in the mainwindow I call this function :

window.api.electronIpcOn('window-A-opened')

which already activate the function in main.ts :

ipcMain.handle("open-type-A-window")

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

  //WindowTypeA.destroy();

});

I also tried with a windowsList: main.ts

let windowsList = []; const windowDestroy = (win) {
  let i = windowsList.indexOf(win);
  if (i > -1) {
    windowsList.splice(i, 1);
    win = null;
  }
}

const createWindow = (): void => { 
  windowsList.push(WindowTypeA);

  WindowTypeA.on('closed', function () {
    windowDestroy(WindowTypeA);
  });
} 

but still the same error: "Error invoking remote method. TypeError: Object has been destroyed"

.... So... any suggestions ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Solved !!! By splitting the creation of the windows: mainwindow and second-window :

const createWindowTypeA = (): void => {

}


const createWindow = (): void => {

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...