-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.js
160 lines (137 loc) · 4.39 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const { app, BrowserWindow, ipcMain, crashReporter, Menu, shell, dialog } = require('electron');
const path = require('path');
const url = require('url');
const log = require('electron-log');
const { autoUpdater } = require('electron-updater');
const jetpack = require('fs-jetpack');
function isDev() {
return require.main.filename.indexOf('app.asar') === -1;
};
app.allowRendererProcessReuse = false
// Logger for autoUpdater
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
log.info('App starting...');
let win = null;
app.on('ready', function () {
// Initialize the window to our specified dimensions
win = new BrowserWindow({
width: 1000,
height: 600,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, 'preload.js')
}
});
win.maximize();
// Specify entry point
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file',
slashes: true
}));
if (isDev()) {
win.toggleDevTools();
}
// Remove window once app is closed
win.on('closed', function () {
win = null;
});
//signal from core.component to check for update
ipcMain.on('ready', (coreCompEvent, arg) => {
if (!isDev()) {
autoUpdater.checkForUpdates().then(() => {
log.info('done checking for updates');
coreCompEvent.sender.send('release-info', autoUpdater.updateInfoAndProvider.info);
});
autoUpdater.on('update-available', (event, info) => {
log.info('update available');
coreCompEvent.sender.send('available', true);
});
autoUpdater.on('update-not-available', (event, info) => {
log.info('no update available..');
});
autoUpdater.on('error', (event, error) => {
log.info('error');
coreCompEvent.sender.send('error', error);
});
autoUpdater.on('update-downloaded', (event, info) => {
// autoUpdater.quitAndInstall();
coreCompEvent.sender.send('update-downloaded');
});
}
})
ipcMain.once('quit-and-install', (event, arg) => {
autoUpdater.quitAndInstall(false);
})
//Check for updates and install
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
crashReporter.start({
productName: "ORNL-AMO",
companyName: "ornl-amo",
submitURL: "https://ornl-amo.sp.backtrace.io:6098/post?format=minidump&token=9e914fbd14a36589b7e2ce09cf8c3b4b5b3e37368da52bf1dabff576f156126c",
uploadToServer: true
});
var template = [{
label: "Application",
submenu: [
{ label: "Quit", accelerator: "Command+Q", click: function () { app.quit(); } },
{ label: "Dev Tools", accelerator: "CmdOrCtrl+I", click: function () { win.toggleDevTools(); } }
]
}, {
label: "Edit",
submenu: [
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ type: "separator" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
win.setMenuBarVisibility(false);
win.webContents.on('new-window', function (e, url) {
// make sure local urls stay in electron perimeter
if ('file://' === url.substr(0, 'file://'.length)) {
return;
}
e.preventDefault();
shell.openExternal(url);
});
});
app.on('window-all-closed', function () {
app.quit();
});
// Listen for message from core.component to either download updates or not
ipcMain.once('update', (event, arg) => {
log.info('update')
autoUpdater.downloadUpdate();
});
ipcMain.once('later', (event, arg) => {
update = null;
});
ipcMain.once('relaunch', () => {
console.log('ipcMain relaunch emitted');
app.relaunch();
app.exit();
});
ipcMain.on("saveFile", (event, arg) => {
delete arg.fileData.dataBackupFilePath;
jetpack.writeAsync(arg.fileName, arg.fileData);
});
ipcMain.on("openDialog", (event, arg) => {
let saveDialogOptions = {
filters: [{
name: "JSON Files",
extensions: ["json"]
}],
defaultPath: arg.fileName
}
dialog.showSaveDialog(win, saveDialogOptions).then(results => {
win.webContents.send('backup-file-path', results.filePath);
});
});