-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
109 lines (86 loc) · 2.89 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
const { app, Menu, BrowserWindow, ipcMain, nativeTheme } = require('electron')
const getMainmenuTemplate = require('./utils/menuItems')
app.disableHardwareAcceleration()
let startWindow, browserWindow
let isSingleInstance = app.requestSingleInstanceLock()
if (!isSingleInstance) {
app.quit()
}
nativeTheme.themeSource = 'dark'
app.on('second-instance', (e, agr, cwd) => {
if (startWindow) {
if (startWindow.isMinimized()) startWindow.restore()
startWindow.focus()
}
else if (browserWindow) {
if (browserWindow.isMinimized()) browserWindow.restore()
browserWindow.focus()
}
else {
return
}
})
// if (app.hasSingleInstanceLock())
function createWindow() {
startWindow = new BrowserWindow({
height: 600, width: 800, webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true
},
icon: `${__dirname}/public/jamb-logo.ico`,
});
startWindow.loadFile('public/index.html')
startWindow.webContents.send('getIp', '')
const mainMenu = Menu.buildFromTemplate(getMainmenuTemplate())
Menu.setApplicationMenu(mainMenu)
}
app.whenReady()
.then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
}).catch(err => { console.log(err) })
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.releaseSingleInstanceLock()
app.quit()
}
})
ipcMain.on('sendip', function (e, ipAddress) {
try {
browserWindow = new BrowserWindow({
webPreferences: {
contextIsolation: false,
enableRemoteModule: true,
allowRunningInsecureContent: true
},
icon: `${__dirname}/public/jamb-logo.ico`,
show: false,
title: "FlahCBT",
fullscreen: true
});
browserWindow.loadURL(`http://${ipAddress}:9091`)
browserWindow.show()
browserWindow.webContents.on('did-fail-load', () => {
browserWindow.close()
startWindow.show()
startWindow.webContents.send('getIp', '')
startWindow.webContents.send('error', 'Could not Load page. Please check your connection, check IP Address and try again.')
})
browserWindow.webContents.on('did-finish-load', () => {
if (startWindow) {
startWindow.close()
startWindow = null
}
})
} catch (err) {
console.log(err)
startWindow.show()
startWindow.webContents.send('getIp', '')
startWindow.webContents.send('error', 'Could not Load page. Please check your connection, check IP Address and try again.')
}
})