元芳怎么了
2022-12-09 15:36:17
所以首先,我知道以下問題Custom HTML Dialog in Electron already exists。當最新版本的電子出現一些問題時,我的問題擴展了這個問題。所以一些背景:我實際上開始了我的一個項目,就像v2.0.5我已經擁有的 Electron() 上的一個非常舊的版本,因為我懶得更新 electron。我有一個工作對話類,你可以這樣做:let dialog = new dialog_class("./pages/dialog.html")dialog.display().then((response) => console.log(response));但是我必須將我的版本更新到 current( v9.1.1) 所以我的對話當然壞了,但我不知道如何/為什么。我非常像這樣創(chuàng)建我的對話框:constructor(link){ this.link = link; this.window = new electron.remote.BrowserWindow({...});}display(){ return new Promise((callback)=>{ this.window.loadURL(...);//url.format function in place of ... this.window.on(`close`, () => { if (!this.cancelCloseEvent) callback(false); }); }}destroy(){ this.window.closable = true; this.widow.close();}但是,當我運行此功能時:function openDialog(){ let dialog = new dialog_class("./pages/dialog.html") dialog.display().then((response) => console.log(response));}我可以完美打開對話框,但只能關閉一次對話框。就像我可以打開它,關閉它然后再次打開它但不能再次關閉它。當我第二次嘗試關閉它時,它會保持對話框打開并拋出這個:electron/js2c/renderer_init.js:82 Uncaught TypeError: Object has been destroyed at BrowserWindow.get (electron/js2c/browser_init.js:125) at electron/js2c/browser_init.js:233 at IpcMainImpl.<anonymous> (electron/js2c/browser_init.js:233) at IpcMainImpl.emit (events.js:223) at WebContents.<anonymous> (electron/js2c/browser_init.js:173) at WebContents.emit (events.js:223)我不知道為什么會這樣,因為每次我運行openDialog它都應該創(chuàng)建一個新的 BrowserWindow,所以我不知道它是如何引用舊窗口的。注意:這里顯示的所有代碼應該足以解決我的問題。但以防萬一這里是整個dialog_class:https ://pastebin.com/7pAwZJHF
1 回答

HUH函數
TA貢獻1836條經驗 獲得超4個贊
dialog.js
display(context) {
return new Promise((cb) => {
electron.ipcRenderer.on("callback", (event, val) => {
this._cancelCloseEvent = true;
cb(val);
// this.destroy(); WRONG!!! Remove this and destory your window on test.js which is having this object instance
});
}
...
test.js
dialog.display().then(function(value) {
response.innerText = value;
dialog.destroy();
// dialog = null; unnecessary!
});
添加回答
舉報
0/150
提交
取消