-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.js
58 lines (52 loc) · 1.8 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { app, contextBridge, BrowserWindow, ipcMain, dialog } = require('electron');
const fs = require('fs');
const path = require('path');
const createWindow = () => {
const win = new BrowserWindow({
width: 1400,
height: 1200,
webPreferences: {
preload: path.resolve(__dirname, 'electron-scripts', 'preload.js'),
devTools: true
}
});
// Uses Webpack Dev Server in Development
// Must open
// win.loadURL('http://localhost:8080/index.html');
win.loadFile('./dist/index.html');
// const contents = win.webContents
// console.log(contents)
};
app.whenReady().then(() => {
// Setup an Event listener to listen on the 'export-chart' channel.
// ipcMain.on('export-chart', (event, code, data) => {
// // Make a Direcotry
// // Write the Data file in directory
// // Write the Code as a File in the Directory
// fs.mkdirSync(path.resolve(__dirname, 'temp'));
// fs.writeFileSync(path.resolve(__dirname, 'temp', 'data.json'), data)
// fs.writeFileSync(path.resolve(__dirname, 'temp', 'code.js'), code)
// })
// EXPORT FUNCTIONALITY
// ipcMain.handle & ipcRenderer.invoke allows for a two-way communication between renderer and main
// BarChartCodePreview > ipcMain.handle > > .then( {canceled, filePaths})
ipcMain.handle('show-save-dialog', (event) => {
const saveDialogPromise = dialog.showOpenDialog({
properties: ['openDirectory'],
buttonLabel: 'Export'
})
.then(({ canceled, filePaths }) => {
if (canceled) {
console.log('Request Canceled')
return
} else {
console.log('File Selected:', filePaths)
return filePaths[0]
}
})
.catch(err => console.log('ERROR on "show-save-dialog" event: ', err))
// return promise
return saveDialogPromise
});
createWindow();
});