2021-09-04 18:23:58 +00:00
|
|
|
const {
|
|
|
|
app,
|
|
|
|
BrowserWindow,
|
|
|
|
ipcMain
|
|
|
|
} = require('electron')
|
2021-07-17 07:02:56 +00:00
|
|
|
const path = require('path')
|
2021-09-04 18:23:58 +00:00
|
|
|
const fs = require('fs')
|
2022-01-11 21:16:14 +00:00
|
|
|
const os = require('os');
|
2021-09-13 16:27:50 +00:00
|
|
|
app.setName("FreeDATA");
|
2021-09-04 15:11:20 +00:00
|
|
|
|
2021-09-04 18:54:01 +00:00
|
|
|
var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config")
|
2021-09-13 16:27:50 +00:00
|
|
|
var configFolder = path.join(appDataFolder, "FreeDATA");
|
2021-09-04 18:23:58 +00:00
|
|
|
var configPath = path.join(configFolder, 'config.json')
|
2021-09-04 14:33:17 +00:00
|
|
|
|
2021-11-19 16:30:17 +00:00
|
|
|
// create config folder if not exists
|
2021-09-04 18:23:58 +00:00
|
|
|
if (!fs.existsSync(configFolder)) {
|
|
|
|
fs.mkdirSync(configFolder);
|
|
|
|
}
|
2021-09-04 14:33:17 +00:00
|
|
|
|
2021-09-04 18:23:58 +00:00
|
|
|
// create config file if not exists
|
2021-09-04 18:54:01 +00:00
|
|
|
var configContent = `
|
|
|
|
{
|
2022-01-10 08:06:08 +00:00
|
|
|
"tnc_host": "127.0.0.1",
|
2021-09-04 18:54:01 +00:00
|
|
|
"tnc_port": "3000",
|
2022-01-10 08:06:08 +00:00
|
|
|
"daemon_host": "127.0.0.1",
|
2021-09-04 18:54:01 +00:00
|
|
|
"daemon_port": "3001",
|
|
|
|
"mycall": "AA0AA",
|
|
|
|
"mygrid": "JN40aa",
|
2022-01-10 08:06:08 +00:00
|
|
|
"deviceid": "RIG_MODEL_DUMMY_NOVFO",
|
|
|
|
"deviceport": "/dev/ttyACM1",
|
2021-09-04 18:54:01 +00:00
|
|
|
"serialspeed": "9600",
|
2022-01-10 08:06:08 +00:00
|
|
|
"ptt": "USB",
|
|
|
|
"spectrum": "waterfall",
|
2022-01-15 13:24:02 +00:00
|
|
|
"tnclocation": "localhost",
|
|
|
|
"stop_bits" : "1",
|
|
|
|
"data_bits" : "8",
|
2022-01-18 18:38:05 +00:00
|
|
|
"handshake" : "None",
|
|
|
|
"radiocontrol" : "direct",
|
|
|
|
"deviceport_rigctl" : "3",
|
|
|
|
"deviceid_rigctl" : "3",
|
|
|
|
"serialspeed_rigctl" : "9600",
|
|
|
|
"pttprotocol_rigctl" : "USB",
|
|
|
|
"rigctld_port" : "4532",
|
2022-02-02 20:12:16 +00:00
|
|
|
"rigctld_ip" : "127.0.0.1",
|
|
|
|
"enable_scatter" : "False",
|
|
|
|
"enable_fft" : "False",
|
2022-01-18 18:38:05 +00:00
|
|
|
|
2021-09-04 18:54:01 +00:00
|
|
|
}
|
|
|
|
`;
|
2021-09-04 18:23:58 +00:00
|
|
|
if (!fs.existsSync(configPath)) {
|
2021-09-04 18:54:01 +00:00
|
|
|
fs.writeFileSync(configPath, configContent)
|
2021-09-04 18:23:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 15:59:33 +00:00
|
|
|
|
|
|
|
|
2021-11-19 16:30:17 +00:00
|
|
|
var chatDB = path.join(configFolder, 'chatDB.json')
|
|
|
|
// create chat database file if not exists
|
|
|
|
var configContent = `
|
|
|
|
{ "chatDB" : [{
|
|
|
|
"id" : "00000000",
|
|
|
|
"timestamp" : 1234566,
|
|
|
|
"mycall" : "AA0AA",
|
|
|
|
"dxcall" : "AB0AB",
|
|
|
|
"dxgrid" : "JN1200",
|
|
|
|
"message" : "hallowelt"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
if (!fs.existsSync(chatDB)) {
|
|
|
|
fs.writeFileSync(chatDB, configContent)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-10 15:59:33 +00:00
|
|
|
/*
|
|
|
|
// Creates receivedFiles folder if not exists
|
|
|
|
// https://stackoverflow.com/a/26227660
|
|
|
|
var appDataFolder = process.env.HOME
|
2021-09-13 16:27:50 +00:00
|
|
|
var applicationFolder = path.join(appDataFolder, "FreeDATA");
|
2021-09-10 15:59:33 +00:00
|
|
|
var receivedFilesFolder = path.join(applicationFolder, "receivedFiles");
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/13544465
|
|
|
|
fs.mkdir(receivedFilesFolder, {
|
|
|
|
recursive: true
|
|
|
|
}, function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-04 18:23:58 +00:00
|
|
|
const config = require(configPath);
|
|
|
|
const exec = require('child_process').exec;
|
2021-07-23 15:40:44 +00:00
|
|
|
|
2021-07-17 07:02:56 +00:00
|
|
|
let win = null;
|
|
|
|
let data = null;
|
2021-09-04 14:33:17 +00:00
|
|
|
var daemonProcess = null;
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
function createWindow() {
|
|
|
|
win = new BrowserWindow({
|
2022-01-10 08:06:08 +00:00
|
|
|
width: 1050,
|
2021-11-07 11:17:23 +00:00
|
|
|
height: 430,
|
2021-08-28 13:50:59 +00:00
|
|
|
autoHideMenuBar: true,
|
2022-01-13 05:06:48 +00:00
|
|
|
icon: __dirname + '/src/icon_cube_border.png',
|
2021-07-24 07:06:22 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
2021-08-28 13:50:59 +00:00
|
|
|
// hide menu bar
|
|
|
|
win.setMenuBarVisibility(false)
|
2021-09-04 18:23:58 +00:00
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
//open dev tools
|
2021-09-08 16:22:41 +00:00
|
|
|
/*win.webContents.openDevTools({
|
2021-07-24 07:06:22 +00:00
|
|
|
mode: 'undocked',
|
|
|
|
activate: true,
|
|
|
|
})
|
2021-09-05 15:30:46 +00:00
|
|
|
*/
|
2021-07-24 07:06:22 +00:00
|
|
|
win.loadFile('src/index.html')
|
2021-11-19 16:30:17 +00:00
|
|
|
|
|
|
|
chat = new BrowserWindow({
|
2021-07-24 07:06:22 +00:00
|
|
|
height: 900,
|
|
|
|
width: 600,
|
2021-11-19 16:30:17 +00:00
|
|
|
show: false,
|
2021-07-24 07:06:22 +00:00
|
|
|
parent: win,
|
|
|
|
webPreferences: {
|
2021-11-19 16:30:17 +00:00
|
|
|
preload: require.resolve('./preload-chat.js'),
|
2021-07-24 07:06:22 +00:00
|
|
|
nodeIntegration: true,
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
2021-11-19 16:30:17 +00:00
|
|
|
|
|
|
|
chat.loadFile('src/chat-module.html')
|
2021-11-19 17:49:36 +00:00
|
|
|
chat.setMenuBarVisibility(false)
|
2021-11-19 16:30:17 +00:00
|
|
|
|
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;
|
2021-11-19 16:30:17 +00:00
|
|
|
chat = null;
|
2021-07-17 07:02:56 +00:00
|
|
|
})
|
|
|
|
|
2021-11-19 16:30:17 +00:00
|
|
|
|
|
|
|
chat.on('closed', function () {
|
2021-07-24 07:06:22 +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.
|
|
|
|
})
|
2021-11-19 16:30:17 +00:00
|
|
|
|
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
|
2021-11-19 16:30:17 +00:00
|
|
|
chat.on('close', function(evt) {
|
2021-07-24 07:06:22 +00:00
|
|
|
evt.preventDefault();
|
2021-11-19 16:30:17 +00:00
|
|
|
chat.hide()
|
2021-07-24 07:06:22 +00:00
|
|
|
});
|
2021-11-19 16:30:17 +00:00
|
|
|
|
2021-07-17 07:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
2021-07-24 07:06:22 +00:00
|
|
|
createWindow()
|
2021-09-04 18:23:58 +00:00
|
|
|
|
2022-01-11 21:16:14 +00:00
|
|
|
// start daemon by checking os
|
2021-09-04 14:33:17 +00:00
|
|
|
// https://stackoverflow.com/a/5775120
|
2021-12-20 16:12:34 +00:00
|
|
|
console.log("Trying to start daemon binary")
|
2022-01-11 21:16:14 +00:00
|
|
|
|
|
|
|
if(os.platform()=='linux' || os.platform()=='darwin'){
|
2022-01-16 17:35:12 +00:00
|
|
|
daemonProcess = exec('./tnc/daemon', function callback(err, stdout, stderr) {
|
2022-01-11 21:16:14 +00:00
|
|
|
if (err) {
|
|
|
|
console.log(os.platform())
|
|
|
|
console.error(err)
|
|
|
|
console.error("Can't start daemon binary");
|
|
|
|
console.error("--> this is only working with the app bundle and a precompiled binaries");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(stdout);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(os.platform()=='win32' || os.platform()=='win64'){
|
2022-01-16 17:35:12 +00:00
|
|
|
daemonProcess = exec('./tnc/daemon.exe', function callback(err, stdout, stderr) {
|
2022-01-11 21:16:14 +00:00
|
|
|
if (err) {
|
|
|
|
console.log(os.platform())
|
|
|
|
console.error(err)
|
|
|
|
console.error("Can't start daemon binary");
|
|
|
|
console.error("--> this is only working with the app bundle and a precompiled binaries");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(stdout);
|
|
|
|
});
|
|
|
|
}
|
2021-12-20 16:12:34 +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-09-04 14:33:17 +00:00
|
|
|
// kill daemon process
|
|
|
|
daemonProcess.kill('SIGINT');
|
2021-07-17 07:02:56 +00:00
|
|
|
|
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-11-19 16:30:17 +00:00
|
|
|
|
|
|
|
ipcMain.on('request-show-chat-window', (event, arg) => {
|
|
|
|
chat.show()
|
2021-08-07 17:46:02 +00:00
|
|
|
});
|
2021-11-19 16:30:17 +00:00
|
|
|
|
|
|
|
|
2021-07-17 07:02:56 +00:00
|
|
|
ipcMain.on('request-update-tnc-state', (event, arg) => {
|
|
|
|
win.webContents.send('action-update-tnc-state', arg);
|
2021-08-07 17:46:02 +00:00
|
|
|
//data.webContents.send('action-update-tnc-state', arg);
|
2021-07-17 07:02:56 +00:00
|
|
|
});
|
|
|
|
|
2021-08-07 18:57:36 +00:00
|
|
|
/*
|
2021-07-23 15:40:44 +00:00
|
|
|
ipcMain.on('request-update-data-state', (event, arg) => {
|
|
|
|
//win.webContents.send('action-update-data-state', arg);
|
2021-08-07 17:46:02 +00:00
|
|
|
//data.webContents.send('action-update-data-state', arg);
|
2021-07-23 15:40:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.on('request-update-heard-stations', (event, arg) => {
|
2021-07-25 14:35:50 +00:00
|
|
|
win.webContents.send('action-update-heard-stations', arg);
|
2021-07-23 15:40:44 +00:00
|
|
|
});
|
2021-08-07 18:57:36 +00:00
|
|
|
*/
|
2021-07-17 07:02:56 +00:00
|
|
|
ipcMain.on('request-update-daemon-state', (event, arg) => {
|
|
|
|
win.webContents.send('action-update-daemon-state', arg);
|
|
|
|
});
|
|
|
|
|
2021-10-17 14:00:23 +00:00
|
|
|
ipcMain.on('request-update-hamlib-test', (event, arg) => {
|
|
|
|
win.webContents.send('action-update-hamlib-test', arg);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-17 07:02:56 +00:00
|
|
|
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-09-04 18:23:58 +00:00
|
|
|
win.webContents.send('run-tnc-command', arg);
|
2021-07-19 19:01:38 +00:00
|
|
|
});
|
2021-08-16 18:04:03 +00:00
|
|
|
|
|
|
|
ipcMain.on('request-update-rx-buffer', (event, arg) => {
|
2021-09-04 18:23:58 +00:00
|
|
|
win.webContents.send('action-update-rx-buffer', arg);
|
2021-09-08 16:22:41 +00:00
|
|
|
});
|
2021-10-17 14:59:15 +00:00
|
|
|
|
2021-10-17 15:22:07 +00:00
|
|
|
ipcMain.on('request-update-rx-msg-buffer', (event, arg) => {
|
2021-11-19 16:30:17 +00:00
|
|
|
chat.webContents.send('action-update-rx-msg-buffer', arg);
|
2021-10-17 14:59:15 +00:00
|
|
|
});
|