重新打开BrowserWindow并单击Electron中的按钮后,对象已被破坏异常 [英] Object has been destroyed Exception after reopen BrowserWindow on button click in Electron

查看:105
本文介绍了重新打开BrowserWindow并单击Electron中的按钮后,对象已被破坏异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Electron Framework的新手,正在用Electron开发简单的桌面应用程序.问题是,当我在电子应用程序中打开一个新窗口并使用菜单栏关闭按钮将其关闭,然后再次尝试将其打开时,它会抛出对象已被破坏的异常".即使单击关闭按钮,如何保留BrowserWindow对象?

I am new to Electron Framework, developing simple desktop application with Electron. Problem is that, when i open a new window in electron app and close it using menu bar close button and again try to open it, then it throws "Object has been destroyed Exception". How do i retain BrowserWindow object even though close button clicked???

推荐答案

应该关闭BrowserWindow对象.重新打开时,您需要实例化一个新对象,而不是尝试重用该引用.

The BrowserWindow object is supposed to be destroyed when closed. You'll need to instantiate a new one when reopening instead of trying to reuse the reference.

如何实例化它取决于您是在主进程(即"Main.js")还是在渲染器进程中进行操作.

How you instantiate it depends on if you're doing it from the main process (i.e. "Main.js") or the renderer process.

在主过程中,它看起来像:

From the main process, it would look like:

var electron = require("electron");
var url = require("url");
var path = require("path");
var newWindow = new electron.BrowserWindow({
    width: 700,
    height: 500
});

newWindow.loadURL(url.format({
    pathname: path.join(__dirname, '/SomeStuff.html'),
    protocol: 'file:',
    slashes: true
}));

如果从渲染器进程实例化,则需要使用远程"对象来访问主进程.这样就可以了:

If instantiating from the renderer process, you need to use the "remote" object to access the main process. So it'd be like:

var newWindow = new electron.remote.BrowserWindow({
    width: 700,
    height: 500
});

这篇关于重新打开BrowserWindow并单击Electron中的按钮后,对象已被破坏异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆