-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
22 lines (22 loc) · 916 Bytes
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const dialog = require('electron').remote.dialog;
var ipc = require('electron').ipcRenderer;
ipc.on('save', function (event) {
var content = document.getElementById("textarea").value;
var fs = require('fs');
// Or with ECMAScript 6
const { dialog } = require('electron').remote;
// You can obviously give a direct path without use the dialog (C:/Program Files/path/myfileexample.txt)
dialog.showSaveDialog((fileName) => {
if (fileName === undefined) {
console.log("You didn't save the file");
return;
}
// fileName is a string that contains the path and filename created in the save file dialog.
fs.writeFile(fileName, content, (err) => {
if (err) {
alert("An error ocurred creating the file " + err.message);
}
alert("The file has been succesfully saved");
});
});
});