-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
76 lines (62 loc) · 1.63 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
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const pcars = require('./lib/index')
require('dotenv').config()
const dev = (process.env.NODE_ENV === 'development')
const start = (webContents) => {
const sendEvent = (channel, args) => {
if ((typeof webContents.send) === 'function') {
webContents.send(channel, args)
} else {
console.log('can not send event')
}
}
const listenEvent = (channel, callable) => {
ipcMain.on(channel, function (event, arg) {
callable(arg, event)
})
}
const player = new pcars.TactPlayer(
new pcars.BHapticsTactJsAdapter(),
new pcars.ConfigLoader(__dirname),
sendEvent,
listenEvent
)
player.launch()
}
const createWindow = () => {
const mainWindow = new BrowserWindow({
width:685,
height:850,
resizable:false,
minimizable : false,
maximizable : false,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
frame:false,
title:'haptic',
})
mainWindow.loadFile('./view/main/index.html')
.then(() => {
dev && mainWindow.webContents.openDevTools()
start(mainWindow.webContents)
})
.catch((err) => console.error(err))
}
app.allowRendererProcessReuse = false;
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
ipcMain.on('close', (evt, arg) => {
app.quit();
});