-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
67 lines (54 loc) · 1.62 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
const {app, BrowserWindow, globalShortcut, dialog} = require('electron')
const url = require('url')
const path = require('path')
const fse = require('fs-extra')
const appPath = app.getAppPath()
const dotenv = require('dotenv')
let logPath = 'logs'
if (process.env.PORTABLE_EXECUTABLE_DIR !== undefined) {
logPath = path.join(process.env.PORTABLE_EXECUTABLE_DIR, '/logs')
} else if (fse.existsSync(path.join(appPath, '../../logs'))) {
logPath = path.join(appPath, '../../logs')
}
dotenv.config({ path: path.join(__dirname, '.env') })
const port = process.env.PORT
const hostname = process.env.HOSTNAME
if (!fse.existsSync(logPath)) {
fse.mkdirSync(logPath)
}
process.on('uncaughtException', function (error) {
const log = require('electron-log')
const errorLogPath = path.join(logPath, 'main.log')
log.transports.file.resolvePath = () => errorLogPath
log.error(error)
dialog.showErrorBox('Failed to start application', 'Something went wrong! A log of the error has been made and can be located at \n' + errorLogPath.replace(/\\/g, '\\\n'))
app.quit()
})
require('./app.js');
let win
function createWindow(){
win = new BrowserWindow({
width: 1920,
height: 1080,
minWidth:1510,
minHeight:442,
webPreferences: {
devTools: true,
},
icon: __dirname + '/details/logo.ico',
})
win.loadURL('http://' + hostname + ':' + port)
win.on('closed', () => {
win = null
})
win.maximize()
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
app.quit()
})
app.on('activate', function () {
if (win === null) {
createWindow()
}
})