-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
60 lines (50 loc) · 1.41 KB
/
index.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
58
59
60
const electron = require('electron')
const path = require('path')
let data = {};
try{
data = JSON.parse(require("fs").readFileSync("./data.json", "utf-8"))
}catch(e){
require("fs").writeFileSync("./data.json", '{"width": 1017, "height": 600}')
data = {width: 1017, height: 600}
}
const app = electron.app
function createWindow () {
const win = new electron.BrowserWindow({
autoHideMenuBar: true,
width: data?.width || 1017,
height: data?.height || 600,
webPreferences: {
preload:path.join(__dirname, 'app.js'),
nodeIntegration: true
}
})
win.on("resize", (x) =>{
data.width = win.getSize()[0]
data.height = win.getSize()[1]
require("fs").writeFileSync("./data.json", JSON.stringify(data))
})
win.on('close', async e => {
e.preventDefault()
const { response } = await electron.dialog.showMessageBox(win, {
type: 'question',
title: ' Confirm ',
message: 'Are you sure that you want to close this window?',
buttons: ['Yes', 'No'],
})
response === 0 && win.destroy()
})
win.loadFile('public/index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})