本文介紹了點擊事件關閉 Electron 應用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我已經查看了有關無框窗口"的 Electron 文檔,但我似乎無法為自己的工作制作一個按鈕來關閉應用程序......
I have looked at the documentation for Electron regarding the 'frameless-window', but I just can't seem to make a button of my own work to close the application...
任何幫助將不勝感激!謝謝!
Any help would be appreciated! Thanks!
const electron = require('electron');
const url = require('url');
const path = require('path');
const {app, BrowserWindow} = electron;
let mainWindow;
// Listen for app to be ready
app.on('ready', function() {
// create new window
mainWindow = new BrowserWindow({width: 800, height: 600, frame: false});
// Load html into window
mainWindow.loadURL(url.format({
pathname:path.join(__dirname,'main.html'),
protocol: 'file:',
slashes: true
}));
const closeApp = document.getElementById('closeApp');
closeApp.addEventListener('click', () => {
app.quit();
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" >
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Electron "Hello World"</title>
</head>
<body>
<header>
<p id="closeApp">close app</p>
</header>
</body>
</html>
推薦答案
在您的渲染器進程中(從 main.html
加載的 JavaScript)您應該能夠加載 Electron 和 Node 模塊.
In your renderer process (javascript loaded from main.html
) you should be able to load Electron and Node modules.
const {ipcRenderer} = require('electron');
const closeApp = document.getElementById('closeApp');
closeApp.addEventListener('click', () => {
ipcRenderer.send('close-me')
});
在 ma??in.js 您發(fā)布的腳本
const {ipcMain} = require('electron')
ipcMain.on('close-me', (evt, arg) => {
app.quit()
})
這篇關于點擊事件關閉 Electron 應用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!