Hello guys i am trying to add a button in my main menu to import/export data and the button to import data should read a csv file from the filesystem by opening a dialog where the user can select the choosen file.
I can't integrate this after a long period of searching for solution.
can anyone show me how to do it please?
here is my index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- head code -->
</head>
<body>
<!-- body -->
<div class="main">
<a href="#"><button class="btn">Import</button></a>
</div>
</body>
</html>
here is the index.js
const { app, BrowserWindow } = require('electron')
const path = require('path')
const createWindow = () => {
const mainWindow = new BrowserWindow({
width: 1200,
height: 900,
resizable:false,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
},
icon: path.join(__dirname, 'assets/icons/logo.png')
})
mainWindow.loadFile('index.html')
mainWindow.setMenu(null);
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
preload.js
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
})