Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k 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 Answer

0 votes
by (71.8m points)

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

const createWindowTypeA = (): void => {

}


const createWindow = (): void => {

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...