Я также создаю электронное приложение с использованием угря, хотя я не уверен, что это уместно здесь.Я недавно вернулся к этому проекту, и я уверен, что он работал раньше.Все работает, кроме кнопок свертывания и закрытия, которые являются пользовательскими.
Вот HTML
<div id="title-bar">
<div id="title-bar-btns">
<button id="min-btn" onclick="window_minimise()">—</button>
<button id="close-btn" onclick="window_close()">✕</button>
</div>
</div>
И JS
function window_minimise(){
const remote = require('electron').remote;
var window = remote.getCurrentWindow();
window.minimize();
}
function window_close(){
const remote = require('electron').remote;
eel.quit_app();
var window = remote.getCurrentWindow();
window.close();
}
И код Python
@eel.expose
def quit_app():
sys.exit(0)
Я попытался запустить его в своем браузере через http://localhost:8000/html/index.html, и когда я нажимаю минимизировать, я получаю эту ошибку
Uncaught ReferenceError: require не определен в window_minimise (index.js: 111) в HTMLButtonElement.onclick (index.html: 18)
И закрыть
Uncaught ReferenceError: require не определен в window_close (index.js): 117) at HTMLButtonElement.onclick (index.html: 19)
Кто-нибудь знает, что может быть не так и как я могу это исправить?
Спасибо.
РЕДАКТИРОВАТЬ:
Вот мой электронный файл main.js
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1200, height: 748, icon:'web/images/favicon-32x32.png', resizable: false,
frame: false, show: false, backgroundColor: '#171717'}) // Needs to be changed based on theme
mainWindow.once('ready-to-show', () => {
mainWindow.show()
})
mainWindow.setMenu(null);
// and load the index.html of the app.
mainWindow.loadURL('http://localhost:8000/html/index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active unti, l the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
В нем есть некоторые ошибки (пропущены точки с запятой и let mainWindow
), но эти ошибки также есть вэлектронный-быстрый старт main.js, так что я в замешательстве.