-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (50 loc) · 1.73 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="public/css/w3.css">
<meta charset="UTF-8">
<title>first App</title>
</head>
<body>
<div class="w3-main">
<div class="w3-margin">
<textarea id="editor" class="w3-input w3-border" rows="5"></textarea>
<button id="saveBtn" class="w3-button w3-green w3-margin-top">save</button>
<button id="openBtn" class="w3-button w3-red w3-margin-top">open</button>
<a class="w3-button w3-margin-top w3-blue" href="https://electronjs.org" target="_blank">Open Electron.js</a>
</div>
</div>
<script>
const os=require('os');
const path = require('path');
const fs=require('fs');
const {dialog}=require('electron').remote;
console.log();
let openBtn=document.getElementById('openBtn');
openBtn.addEventListener('click',()=>{
dialog.showOpenDialog({
filters:[{name:'text',extensions:['.txt','.png','*']}],
defaultPath:path.join(os.homedir())
},(fileNames)=>{
if(fileNames === undefined) return ;
fs.readFile(fileNames[0], (err, data) => {
if (err) throw err;
document.getElementById('editor').value=data.toString();
});
} )
});
let saveBtn=document.getElementById('saveBtn');
saveBtn.addEventListener('click',()=>{
dialog.showSaveDialog({
filters:[{name:'text',extensions:['.txt','.png','*']}],
},fileName=>{
let myDataToSave=document.getElementById('editor').value;
console.log(myDataToSave);
fs.writeFile(fileName.toString(), myDataToSave, (err) => {
if (err) throw err;
});
});
});
</script>
</body>
</html>