Делаю предложение на electron по tutorial -у если кому интересно будет
Добрался до создания модального окна при нажатии на кнопку и не как не получается это сделать.
main.js
const {app, BrowserWindow, Menu} = require('electron')
const shell = require('electron').shell
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600
})
win.loadFile('src/index.html').then(r => win)
win.webContents.openDevTools()
var menu = Menu.buildFromTemplate([
{
label: 'Menu',
submenu: [
{label: 'Adjust Notification Value'},
{
label: 'Coin Market Cap',
click() {
shell.openExternal('https://coinmarketcap.com')
}
},
{type: "separator"},
{
label: 'Exit',
click() {
app.quit()
}
}
]
},
{
label: 'Info'
}
])
Menu.setApplicationMenu(menu);
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cripto</title>
<!-- https://electronjs.org/docs/tutorial/security#csp-meta-tag -->
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<link rel="stylesheet" href="../assets/css/main.css">
</head>
<body>
<div class="row">
<div id="price-container">
<p class="subtext">Current BTC USD</p>
<h1 id="price">Loading...</h1>
</div>
<div id="goal-container">
<p><img src="../assets/images/up.svg" alt=""><span id="targetPrice">Choose a Target Price</span></p>
</div>
<div id="right-container">
<button id="notifyBtn">Notify me when...</button>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
add.js
const electron = require('electron').remote
const path = require('path')
const {BrowserWindow} = electron.BrowserWindow
const notifyBtn = document.getElementById('notifyBtn')
notifyBtn.addEventListener('click', (event) => {
const modalPath = path.join('file://', __dirname, 'add.js')
let win = new BrowserWindow({ frame: false })
win.on('close', () => { win = null })
win.loadURL(modalPath)
win.show()
})
add.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<!-- https://electronjs.org/docs/tutorial/security#csp-meta-tag -->
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/css/add.css">
</head>
<body>
<p class="notify">Notify me when BTC reaches...</p>
<div class="row2">
<div>
<input id="notifyVal" placeholder="USD">
</div>
<button id="updateBtn">Update</button>
</div>
<a id="closeBtn">Close window</a>
<script src="add.js"></script>
</body>
</html>
На electronjs пишу первый раз, не как не пойму в чём проблема. При дебаге, при нажатии на кнопку, до add.js, дебаг не доходит. Такое чувство, что он эту страницу просто не видит. Возможно, в новых версиях где то зарезолвить что то нужно?