在关闭回调上访问远程窗口内的窗口

时间:2018-07-02 10:43:47

标签: electron

我正在尝试在其关闭处理程序中访问远程窗口

    const BrowserWindow = this.$electron.remote.BrowserWindow;
    let win = new BrowserWindow({ width: 800, height: 600 });
    const closeHandler = (event) => {
      console.log(event.sender.getURL());
    };
    win.on('close', closeHandler);
    win.on('closed', () => {
      win.removeListener('close', closeHandler);
      win = null;
    });

我收到以下错误

Uncaught Error: Could not call remote function 'getURL'. Check that the function signature is correct. Underlying error: Object has been destroyed
Error: Could not call remote function 'getURL'. Check that the function signature is correct. Underlying error: Object has been destroyed
at callFunction (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/rpc-server.js:257:11)
at EventEmitter.<anonymous> (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/rpc-server.js:357:5)
at emitMany (events.js:146:13)
at EventEmitter.emit (events.js:223:7)
at WebContents.<anonymous> (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/api/web-contents.js:275:13)
at emitTwo (events.js:125:13)
at WebContents.emit (events.js:213:7)
at callFunction (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/rpc-server.js:257:11)
at EventEmitter.<anonymous> (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/rpc-server.js:357:5)
at emitMany (events.js:146:13)
at EventEmitter.emit (events.js:223:7)
at WebContents.<anonymous> (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/api/web-contents.js:275:13)
at emitTwo (events.js:125:13)
at WebContents.emit (events.js:213:7)
at Object.exception (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/api/remote.js:209:30)
at metaToValue (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/api/remote.js:213:28)
at Object.remoteMemberFunction (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/api/remote.js:113:16)
at closeHandler (webpack-internal:///34:18:34)
at CallbacksRegistry.apply (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/common/api/callbacks-registry.js:46:25)
at EventEmitter.ipcRenderer.on (/Users/teamwork/Documents/code/my-project/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/api/remote.js:261:21)
at emitThree (events.js:135:13)
at EventEmitter.emit (events.js:216:7)

我认为这是因为注册到远程对象的回调被异步调用-https://github.com/electron/electron/blob/master/docs/api/remote.md#passing-callbacks-to-the-main-process

这样在执行回调时窗口已经被破坏了吗?

但是那没有意义,因为是将其设置为null的关闭事件,并允许主进程对其进行垃圾收集。

0 个答案:

没有答案