【问题标题】:Error: Object has been destroyed when trying to re-open a second BrowserWindow - Electron.js错误:尝试重新打开第二个 BrowserWindow - Electron.js 时对象已被破坏
【发布时间】:2021-04-17 16:50:11
【问题描述】:

在电子反应打字稿应用程序中,我使用主窗口中的按钮打开一个新窗口。 如果我点击右上角的“x”关闭第二个窗口, 单击主窗口中的按钮时,我收到以下消息: "Error invoking remote method. TypeError: Object has been destroyed"。 我发现了这个:Object has been destroyed Exception after reopen BrowserWindow on button click in Electron。 但是这个建议对我没有帮助,因为点击主窗口中的按钮我调用了这个函数:

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

已经激活了 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();

});

我也尝试了一个 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);
  });
} 

但还是同样的错误:"Error invoking remote method. TypeError: Object has been destroyed"

....所以...有什么建议吗?

【问题讨论】:

    标签: reactjs typescript electron electron-window


    【解决方案1】:

    解决了!!!通过拆分窗口的创建:主窗口和次窗口:

    const createWindowTypeA = (): void => {
    
    }
    
    
    const createWindow = (): void => {
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 2018-05-28
      • 1970-01-01
      • 2012-09-28
      • 1970-01-01
      • 2011-09-17
      相关资源
      最近更新 更多