-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
103 lines (79 loc) · 2.4 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
/* eslint strict: 0 */
'use strict';
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const electron = require('electron');
const remote = electron.remote;
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Menu = electron.Menu;
const crashReporter = electron.crashReporter;
const shell = electron.shell;
const ipcMain = require('electron').ipcMain;
const nativeImage = require('electron').nativeImage;
// handle Squirrel.Windows events
var path = require('path');
var spawn = require('child_process').spawn;
var run = function(args, done) {
var updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
spawn(updateExe, args, {
detached: true
}).on('close', done);
};
if (process.platform === 'win32') {
var cmd = process.argv[1];
var target = path.basename(process.execPath);
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
run(['--createShortcut=' + target + ''], app.quit);
}
if (cmd === '--squirrel-uninstall') {
run(['--removeShortcut=' + target + ''], app.quit);
}
if (cmd === '--squirrel-obsolete') {
app.quit();
}
}
let mainWindow;
crashReporter.start({
productName: 'Millie',
companyName: 'Delightful Code',
submitURL: 'https://robteix.com/errors',
autoSubmit: true
});
if (process.env.NODE_ENV === 'development') {
require('electron-debug')();
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
// logs
// for writing error logs
const Console = require('console').Console;
const fs = require('fs');
const output = fs.createWriteStream(app.getPath('userData') + '/user.log');
const errorOutput = fs.createWriteStream(app.getPath('userData') + '/error.log');
const logger = new Console(output, errorOutput);
process.on('uncaughtException', function (error) {
logger.error(error);
});
app.on('ready', () => {
let icon = nativeImage.createFromPath('./app/img/millie.png');
mainWindow = new BrowserWindow({
width: 1024, height: 728,
minWidth: 800, minHeight: 600,
icon: icon});
mainWindow.loadURL(`file://${__dirname}/app/app.html`);
mainWindow.on('closed', () => {
mainWindow = null;
});
if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools();
}
});
ipcMain.on('set-badge', function(event, arg) {
if (process.platform === "darwin") {
app.dock.setBadge(''+arg);
}
event.returnValue = 'ok';
});
/*
*/