-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
118 lines (95 loc) · 2.56 KB
/
main.js
File metadata and controls
118 lines (95 loc) · 2.56 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const electron = require('electron')
require('electron-reload')(__dirname);
const {autoUpdater} = require('electron-updater');
const fs = require('fs-plus');
const os = require('os');
const path = require('path');
const fetch = require("node-fetch");
const {app, BrowserWindow, ipcMain} = electron;
let mainWindow = null;
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true
},
frame: false,
});
//mainWindow.setMenu(null)
mainWindow.maximize();
// and load the index.html of the app.
mainWindow.loadFile('index.html')
mainWindow.on('closed', () => {
mainWindow = null
})
mainWindow.webContents.once('dom-ready', () => {
autoUpdater.autoDownload = false;
autoUpdater.checkForUpdates()
})
}
ipcMain.on('download', (event, data) => {
data.image = data.image.replace(/^data:image\/png;base64,/, "");
if(!data.filename.endsWith(".png")){
data.filename += ".png"
}
const savePath = path.join(os.homedir(), 'Desktop', data.filename);
fs.writeFile(savePath, data.image, 'base64', err => {
if (err) {
event.sender.send('download-done', "error")
throw err;
} else {
event.sender.send('download-done', savePath)
}
});
});
ipcMain.on("close", () => {
mainWindow.close();
})
ipcMain.on("toggleMaximize", () => {
if(mainWindow.isMaximized()){
mainWindow.unmaximize()
} else {
mainWindow.maximize()
}
})
ipcMain.on("minimize", () => {
mainWindow.minimize();
})
ipcMain.on("update", () => {
autoUpdater.downloadUpdate()
})
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})
const sendStatusToWindow = (status, text = "") => {
if(mainWindow){
mainWindow.webContents.send(status, text)
}
}
autoUpdater.on("checking-for-update", () => {
sendStatusToWindow("checking-for-update")
})
autoUpdater.on("update-available", info => {
sendStatusToWindow("update-available")
})
autoUpdater.on("update-not-available", info => {
sendStatusToWindow("update-not-available")
})
autoUpdater.on("error", err => {
sendStatusToWindow("error")
})
autoUpdater.on("download-progress", (progressObj) => {
sendStatusToWindow("download-progress", `Downloaded ${progressObj.percent}% at ${progressObj.bytesPerSecond}`)
})
autoUpdater.on("update-downloaded", info => {
sendStatusToWindow("update-downloaded")
autoUpdater.quitAndInstall(true, true);
})