[英]Th Electron Window OnBlur Event [unhandled error]
This error occurs seldom in the app when it loads (Not all the time).加载时应用程序中很少发生此错误(并非总是)。 The index.js is the main file,selected in package.json , and the script.js is the file connected to main html file of the electron app.
The index.js is the main file,selected in package.json , and the script.js is the file connected to main html file of the electron app.
const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = require('url');
let window;
var APP_DIR = '/app/';
var IMG_DIR = '/images/';
function createWindow() {
window = new BrowserWindow({
webPreferences: { nodeIntegration: true },
width:610,
height:679,
icon: path.join(__dirname, APP_DIR, IMG_DIR, 'icon.png'),
frame: false,
resizable: false,
fullscreenable: false
});
window.loadURL(url.format({
pathname: path.join(__dirname, APP_DIR, 'index.html'),
protocol: 'file:',
slashes: true
}));
}
app.on('ready', createWindow);
script.js (where the error occurs) script.js (发生错误的地方)
var {BrowserWindow} = require('electron').remote;
BrowserWindow.getFocusedWindow().on('blur', function() {
windowBlurHandler(); //a function
});
How can I fix it?我该如何解决?
Function BrowserWindow.getFocusedWindow()
returns null
when all windows are blurred.当所有 windows 都模糊时,Function
BrowserWindow.getFocusedWindow()
返回null
。 You are getting the error because listeners cannot be registered on null
.您收到错误是因为无法在
null
上注册侦听器。
Try something like this instead:尝试这样的事情:
const mainWindow = require('electron').remote.getCurrentWindow()
mainWindow.on('blur', function() {
windowBlurHandler()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.