簡體   English   中英

Th Electron Window OnBlur 事件 [未處理的錯誤]

[英]Th Electron Window OnBlur Event [unhandled error]

加載時應用程序中很少發生此錯誤(並非總是)。 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.

在此處輸入圖像描述 index.js

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 (發生錯誤的地方)

var {BrowserWindow} = require('electron').remote;

BrowserWindow.getFocusedWindow().on('blur', function() {
    windowBlurHandler(); //a function
});

我該如何解決?

當所有 windows 都模糊時,Function BrowserWindow.getFocusedWindow()返回null 您收到錯誤是因為無法在null上注冊偵聽器。

嘗試這樣的事情:

const mainWindow = require('electron').remote.getCurrentWindow()

mainWindow.on('blur', function() {
  windowBlurHandler()
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM