【发布时间】:2019-10-10 20:59:14
【问题描述】:
我也在使用 eel 构建一个电子应用程序,尽管我不确定这是否相关。我最近回到了这个项目,我确信它以前是有效的。除了自定义的最小化和关闭按钮之外,一切正常。
这里是 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 运行它,当我点击最小化时出现此错误
未捕获的引用错误:未定义要求 在 window_minimise (index.js:111) 在 HTMLButtonElement.onclick (index.html:18)
然后关闭
未捕获的引用错误:未定义要求 在 window_close (index.js:117) 在 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),但这些错误也在 electron-quick-start main.js 中,所以我很困惑。
【问题讨论】:
标签: javascript python electron eel