2021-07-24 07:06:22 +00:00
|
|
|
const {app,BrowserWindow,ipcMain} = require('electron')
|
2021-07-17 07:02:56 +00:00
|
|
|
const path = require('path')
|
2021-07-23 15:40:44 +00:00
|
|
|
var config = require('./config.json');
|
|
|
|
|
2021-07-17 07:02:56 +00:00
|
|
|
let win = null;
|
|
|
|
let data = null;
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
function createWindow() {
|
|
|
|
win = new BrowserWindow({
|
|
|
|
width: 1220,
|
|
|
|
height: 920,
|
|
|
|
webPreferences: {
|
|
|
|
//preload: path.join(__dirname, 'preload-main.js'),
|
|
|
|
preload: require.resolve('./preload-main.js'),
|
|
|
|
nodeIntegration: true,
|
|
|
|
contextIsolation: false,
|
|
|
|
enableRemoteModule: false, //https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655 https://github.com/electron/remote
|
|
|
|
}
|
|
|
|
})
|
|
|
|
//open dev tools
|
|
|
|
win.webContents.openDevTools({
|
|
|
|
mode: 'undocked',
|
|
|
|
activate: true,
|
|
|
|
})
|
|
|
|
win.loadFile('src/index.html')
|
2021-07-17 07:02:56 +00:00
|
|
|
data = new BrowserWindow({
|
2021-07-24 07:06:22 +00:00
|
|
|
height: 900,
|
|
|
|
width: 600,
|
|
|
|
parent: win,
|
|
|
|
webPreferences: {
|
|
|
|
preload: require.resolve('./preload-data.js'),
|
|
|
|
nodeIntegration: true,
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
2021-07-19 19:01:38 +00:00
|
|
|
//open dev tools
|
2021-07-24 07:06:22 +00:00
|
|
|
data.webContents.openDevTools({
|
|
|
|
mode: 'undocked',
|
|
|
|
activate: true,
|
|
|
|
})
|
|
|
|
data.loadFile('src/data-module.html')
|
|
|
|
data.hide()
|
2021-07-17 07:02:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Emitted when the window is closed.
|
2021-07-24 07:06:22 +00:00
|
|
|
win.on('closed', function() {
|
2021-07-17 07:02:56 +00:00
|
|
|
// Dereference the window object, usually you would store windows
|
|
|
|
// in an array if your app supports multi windows, this is the time
|
|
|
|
// when you should delete the corresponding element.
|
|
|
|
win = null;
|
|
|
|
data = null;
|
|
|
|
})
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
/*
|
|
|
|
data.on('closed', function () {
|
|
|
|
// Dereference the window object, usually you would store windows
|
|
|
|
// in an array if your app supports multi windows, this is the time
|
|
|
|
// when you should delete the corresponding element.
|
|
|
|
})
|
|
|
|
*/
|
2021-07-17 07:02:56 +00:00
|
|
|
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
// https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron
|
|
|
|
data.on('close', function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
data.hide()
|
|
|
|
});
|
2021-07-17 07:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
2021-07-24 07:06:22 +00:00
|
|
|
createWindow()
|
2021-07-17 07:02:56 +00:00
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
app.on('activate', () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
createWindow()
|
|
|
|
}
|
|
|
|
})
|
2021-07-17 07:02:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
2021-07-17 07:02:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2021-07-19 19:01:38 +00:00
|
|
|
// IPC HANDLER
|
2021-07-17 07:02:56 +00:00
|
|
|
ipcMain.on('show-data-window', (event, arg) => {
|
|
|
|
data.show()
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.on('request-update-tnc-state', (event, arg) => {
|
|
|
|
win.webContents.send('action-update-tnc-state', arg);
|
|
|
|
data.webContents.send('action-update-tnc-state', arg);
|
|
|
|
});
|
|
|
|
|
2021-07-23 15:40:44 +00:00
|
|
|
ipcMain.on('request-update-data-state', (event, arg) => {
|
|
|
|
//win.webContents.send('action-update-data-state', arg);
|
|
|
|
data.webContents.send('action-update-data-state', arg);
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.on('request-update-heard-stations', (event, arg) => {
|
|
|
|
//win.webContents.send('action-update-heard-stations', arg);
|
|
|
|
});
|
|
|
|
|
2021-07-17 07:02:56 +00:00
|
|
|
ipcMain.on('request-update-daemon-state', (event, arg) => {
|
|
|
|
win.webContents.send('action-update-daemon-state', arg);
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.on('request-update-daemon-connection', (event, arg) => {
|
|
|
|
win.webContents.send('action-update-daemon-connection', arg);
|
|
|
|
});
|
|
|
|
|
2021-07-19 19:01:38 +00:00
|
|
|
ipcMain.on('run-tnc-command', (event, arg) => {
|
2021-07-24 07:06:22 +00:00
|
|
|
win.webContents.send('run-tnc-command', arg);
|
2021-07-19 19:01:38 +00:00
|
|
|
});
|
2021-07-24 07:06:22 +00:00
|
|
|
|