Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

node.js - Electron frameless window not closing

So i'm developing a program using Electron (11.1.1) and the button i'm using to close the program is not working I've also downloaded this tutorial and tried to run it and it also fails to close. I'm not really sure if this is a problem with my code but here is my close function just in case.

const electron = require('electron')
const path = require('path')
const remote = electron.remote

function closeWindow(){
 console.log("CLOSE")
 var window = remote.BrowserWindow.getFocusedWindow();
 window.close();
}

I know the button works because when I code another function with console.log it seems to print that but when i run the function above it doesn't seen to print anything (Also node intergration is set to true)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Alright so I have fixed the problem.

In Electron 10+ the tag "enableRemoteModule" is set to false by default. So to get the Remote Module to work you need to set it to true in the BrowserWindow WebPreferences. You can do this by adding webPreferences: {nodeIntergration: true, enableRemoteModule: true} into your BrowserWindow object!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...