diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 5dfe1b07..cc5757d9 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Create a report to help us improve FreeDATA -title: '' +title: "" labels: bug -assignees: '' - +assignees: "" --- **Describe the bug** @@ -12,6 +11,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -27,9 +27,10 @@ https://wiki.freedata.app/en/usage/logging If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Version [e.g. 22] - - Platform [Raspberry Pi, Desktop] + +- OS: [e.g. iOS] +- Version [e.g. 22] +- Platform [Raspberry Pi, Desktop] **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index e301d68c..51d1465c 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,10 +1,9 @@ --- name: Feature request about: Suggest an idea for this project -title: '' +title: "" labels: feature request -assignees: '' - +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/workflows/prettier.yaml b/.github/workflows/prettier.yaml new file mode 100644 index 00000000..b1a75af4 --- /dev/null +++ b/.github/workflows/prettier.yaml @@ -0,0 +1,21 @@ +name: Prettier + +# This action works with pull requests and pushes +on: [push] + +jobs: + prettier: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + # Make sure the actual branch is checked out when running on pull requests + ref: ${{ github.head_ref }} + + - name: Prettify code + uses: creyD/prettier_action@v4.2 + with: + # This part is also where you can pass other options, for example: + prettier_options: --write **/*.{js,md,css,html} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..26938359 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +# Ignore artifacts: +build +coverage +assets +gui/src/waterfall \ No newline at end of file diff --git a/README.md b/README.md index 4bbd5cd2..4cfdeb4c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # FreeDATA + My attempt to create a free and open-source TNC with a GUI for [codec2](https://github.com/drowe67/codec2) with the idea of sending messages and data from one network based application. [mailing-list](https://groups.io/g/freedata) @@ -8,10 +9,10 @@ My attempt to create a free and open-source TNC with a GUI for [codec2](https:// ![Build](https://github.com/DJ2LS/FreeDATA/actions/workflows/build_multiplatform.yml/badge.svg) [![CodeFactor](https://www.codefactor.io/repository/github/dj2ls/freedata/badge)](https://www.codefactor.io/repository/github/dj2ls/freedata) - Please keep in mind, this project is still under development with many issues which need to be solved. ### existing/planned TNC features + - [x] network based - [x] raw data transfer - [x] fft output @@ -24,32 +25,37 @@ Please keep in mind, this project is still under development with many issues wh - [x] channel measurement - [ ] hybrid ARQ - [ ] tbc... + ### existing/planned Chat features - - [x] chat messages - - [x] file transfer - - [x] file transfer with chat message - - [x] database for not loosing messages - - [x] smileys - - [ ] database network sync - - [ ] voice messages - - [ ] image compression - - [ ] status messages - - [ ] avatars - - [ ] tbc... + +- [x] chat messages +- [x] file transfer +- [x] file transfer with chat message +- [x] database for not loosing messages +- [x] smileys +- [ ] database network sync +- [ ] voice messages +- [ ] image compression +- [ ] status messages +- [ ] avatars +- [ ] tbc... ## Data Preview + ![preview](https://github.com/DJ2LS/FreeDATA/blob/main/documentation/data_preview.gif?raw=true "Preview") ## Chat Preview + ![preview](https://github.com/DJ2LS/FreeDATA/blob/main/documentation/chat_preview_fast.gif?raw=true "Preview") - ## Installation + Please check the [wiki](https://wiki.freedata.app) for installation instructions Please check the ['Releases'](https://github.com/DJ2LS/FreeDATA/releases) section for downloading precompiled builds ## Credits -* David Rowe and the FreeDV team for developing the modem and libraries - -FreeDV Codec 2 : https://github.com/drowe67/codec2 -* xssfox, her repository helped a lot in an early stage of development - -xssfox : https://github.com/xssfox/freedv-tnc + +- David Rowe and the FreeDV team for developing the modem and libraries - + FreeDV Codec 2 : https://github.com/drowe67/codec2 +- xssfox, her repository helped a lot in an early stage of development - + xssfox : https://github.com/xssfox/freedv-tnc diff --git a/documentation/FreeDATA-daemon_network_documentation.md b/documentation/FreeDATA-daemon_network_documentation.md index b084356c..557eccfd 100644 --- a/documentation/FreeDATA-daemon_network_documentation.md +++ b/documentation/FreeDATA-daemon_network_documentation.md @@ -1,21 +1,25 @@ -# FreeDATA - DAEMON network documentation - +# FreeDATA - DAEMON network documentation ## GET DAEMON STATE + #### Description: + Get the current daemon state #### Parameters -- Type: GET + +- Type: GET - Command: DAEMON_STATE - Parameter: --- (str) -#### Example +#### Example + ``` {"type" : "GET", "command" : "DAEMON_STATE"} ``` #### Returns + ``` { "COMMAND": "DAEMON_STATE", @@ -24,67 +28,74 @@ Get the current daemon state "HAMLIB_VERSION": str(hamlib_version), "INPUT_DEVICES": [], "OUTPUT_DEVICES": [], - "SERIAL_DEVICES": [], - "CPU": "", - "RAM": "", + "SERIAL_DEVICES": [], + "CPU": "", + "RAM": "", "VERSION": "0.1-prototype" } ``` - ## SET CALLSIGN + #### Description: + Save your callsign to the daemon #### Parameters -- Type: SET + +- Type: SET - Command: MYCALLSIGN - Parameter: callsign (str) - timestamp: unix timestamp (str) -#### Example +#### Example + ``` {"type" : "SET", "command": "MYCALLSIGN" , "parameter": "", "timestamp" : "123456789"} ``` - - ## SET GRIDSQUARE + #### Description: + Save your gridsquare/maidenhead-locator to the daemon #### Parameters -- Type: SET + +- Type: SET - Command: MYGRID - Parameter: gridsquare (str) - timestamp: unix timestamp (str) -#### Example +#### Example + ``` {"type" : "SET", "command": "MYGRID" , "parameter": "", "timestamp" : "123456789"} ``` - - ## TEST HAMLIB + #### Description: + Test your hamlib settings #### Parameters -- Type: GET + +- Type: GET - Command: TEST_HAMLIB - Parameter: obj - - devicename - - deviceport - - pttprotocol - - pttport - - serialspeed - - data_bits - - stop_bits - - handshake + - devicename + - deviceport + - pttprotocol + - pttport + - serialspeed + - data_bits + - stop_bits + - handshake - timestamp: unix timestamp (str) -#### Example +#### Example + ``` { "type": "GET", @@ -102,29 +113,32 @@ Test your hamlib settings } ``` - ## START TNC + #### Description: + Start the tnc process #### Parameters -- Type: GET + +- Type: GET - Command: TEST_HAMLIB - Parameter: obj - - mycall - - mygrid - - rx_audio - - tx_audio - - devicename - - deviceport - - pttprotocol - - pttport - - serialspeed - - data_bits - - stop_bits - - handshake + - mycall + - mygrid + - rx_audio + - tx_audio + - devicename + - deviceport + - pttprotocol + - pttport + - serialspeed + - data_bits + - stop_bits + - handshake + +#### Example -#### Example ``` { type: 'SET', @@ -148,23 +162,19 @@ Start the tnc process ``` ## STOP TNC + #### Description: + Stop the tnc process #### Parameters -- Type: SET + +- Type: SET - Command: STOPTNC - Parameter: --- -#### Example +#### Example + ``` {"type" : "SET", "command": "STOPTNC" , "parameter": "---" } ``` - - - - - - - - diff --git a/gui/daemon.js b/gui/daemon.js index f380114a..10bab25b 100644 --- a/gui/daemon.js +++ b/gui/daemon.js @@ -1,74 +1,72 @@ -var net = require('net'); -const path = require('path') -const { - ipcRenderer -} = require('electron') -const log = require('electron-log'); -const daemonLog = log.scope('daemon'); - - +var net = require("net"); +const path = require("path"); +const { ipcRenderer } = require("electron"); +const log = require("electron-log"); +const daemonLog = log.scope("daemon"); // https://stackoverflow.com/a/26227660 -var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config") +var appDataFolder = + process.env.APPDATA || + (process.platform == "darwin" + ? process.env.HOME + "/Library/Application Support" + : process.env.HOME + "/.config"); var configFolder = path.join(appDataFolder, "FreeDATA"); -var configPath = path.join(configFolder, 'config.json') +var configPath = path.join(configFolder, "config.json"); const config = require(configPath); var daemon = new net.Socket(); -var socketchunk = ''; // Current message, per connection. +var socketchunk = ""; // Current message, per connection. // global to keep track of daemon connection error emissions -var daemonShowConnectStateError = 1 +var daemonShowConnectStateError = 1; // global for storing ip information var daemon_port = config.daemon_port; var daemon_host = config.daemon_host; -setTimeout(connectDAEMON, 500) +setTimeout(connectDAEMON, 500); function connectDAEMON() { - if (daemonShowConnectStateError == 1) { - daemonLog.info('connecting to daemon'); - } + if (daemonShowConnectStateError == 1) { + daemonLog.info("connecting to daemon"); + } - //clear message buffer after reconnecting or initial connection - socketchunk = ''; - - if (config.tnclocation == 'localhost') { - daemon.connect(3001, '127.0.0.1') - } else { - daemon.connect(daemon_port, daemon_host) + //clear message buffer after reconnecting or initial connection + socketchunk = ""; - } + if (config.tnclocation == "localhost") { + daemon.connect(3001, "127.0.0.1"); + } else { + daemon.connect(daemon_port, daemon_host); + } - //client.setTimeout(5000); + //client.setTimeout(5000); } -daemon.on('connect', function(err) { - daemonLog.info('daemon connection established'); - let Data = { - daemon_connection: daemon.readyState, - }; - ipcRenderer.send('request-update-daemon-connection', Data); +daemon.on("connect", function (err) { + daemonLog.info("daemon connection established"); + let Data = { + daemon_connection: daemon.readyState, + }; + ipcRenderer.send("request-update-daemon-connection", Data); - daemonShowConnectStateError = 1 -}) + daemonShowConnectStateError = 1; +}); -daemon.on('error', function(err) { - if (daemonShowConnectStateError == 1) { - daemonLog.error('daemon connection error'); - daemonLog.info('Make sure the daemon is started.'); - daemonLog.info('Run "python daemon.py" in the tnc directory.'); - daemonLog.debug(err) - - daemonShowConnectStateError = 0 - } - setTimeout(connectDAEMON, 500) - daemon.destroy(); - let Data = { - daemon_connection: daemon.readyState, - }; - ipcRenderer.send('request-update-daemon-connection', Data); +daemon.on("error", function (err) { + if (daemonShowConnectStateError == 1) { + daemonLog.error("daemon connection error"); + daemonLog.info("Make sure the daemon is started."); + daemonLog.info('Run "python daemon.py" in the tnc directory.'); + + daemonShowConnectStateError = 0; + } + setTimeout(connectDAEMON, 500); + daemon.destroy(); + let Data = { + daemon_connection: daemon.readyState, + }; + ipcRenderer.send("request-update-daemon-connection", Data); }); /* @@ -82,242 +80,264 @@ client.on('close', function(data) { }); */ -daemon.on('end', function(data) { - - daemonLog.warn('daemon connection ended'); - daemon.destroy(); - setTimeout(connectDAEMON, 500) - let Data = { - daemon_connection: daemon.readyState, - }; - ipcRenderer.send('request-update-daemon-connection', Data); +daemon.on("end", function (data) { + daemonLog.warn("daemon connection ended"); + daemon.destroy(); + setTimeout(connectDAEMON, 500); + let Data = { + daemon_connection: daemon.readyState, + }; + ipcRenderer.send("request-update-daemon-connection", Data); }); //exports.writeCommand = function(command){ -writeDaemonCommand = function(command) { +writeDaemonCommand = function (command) { + // we use the writingCommand function to update our TCPIP state because we are calling this function a lot + // if socket opened, we are able to run commands + if (daemon.readyState == "open") { + //uiMain.setDAEMONconnection('open') + daemon.write(command + "\n"); + } - // we use the writingCommand function to update our TCPIP state because we are calling this function a lot - // if socket opened, we are able to run commands - if (daemon.readyState == 'open') { - //uiMain.setDAEMONconnection('open') - daemon.write(command + '\n'); - } + if (daemon.readyState == "closed") { + //uiMain.setDAEMONconnection('closed') + } - if (daemon.readyState == 'closed') { - //uiMain.setDAEMONconnection('closed') - } + if (daemon.readyState == "opening") { + //uiMain.setDAEMONconnection('opening') + } - if (daemon.readyState == 'opening') { - //uiMain.setDAEMONconnection('opening') - } - - let Data = { - daemon_connection: daemon.readyState, - }; - ipcRenderer.send('request-update-daemon-connection', Data); -} + let Data = { + daemon_connection: daemon.readyState, + }; + ipcRenderer.send("request-update-daemon-connection", Data); +}; // "https://stackoverflow.com/questions/9070700/nodejs-net-createserver-large-amount-of-data-coming-in" -daemon.on('data', function(socketdata) { - - /* +daemon.on("data", function (socketdata) { + /* inspired by: stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data-coming-in */ + socketdata = socketdata.toString("utf8"); // convert data to string + socketchunk += socketdata; // append data to buffer so we can stick long data together - socketdata = socketdata.toString('utf8'); // convert data to string - socketchunk += socketdata// append data to buffer so we can stick long data together + // check if we received begin and end of json data + if (socketchunk.startsWith('{"') && socketchunk.endsWith('"}\n')) { + var data = ""; + // split data into chunks if we received multiple commands + socketchunk = socketchunk.split("\n"); + data = JSON.parse(socketchunk[0]); - // check if we received begin and end of json data - if (socketchunk.startsWith('{"') && socketchunk.endsWith('"}\n')) { - - var data = '' - - // split data into chunks if we received multiple commands - socketchunk = socketchunk.split("\n"); - data = JSON.parse(socketchunk[0]) - - - // search for empty entries in socketchunk and remove them - for (i = 0; i < socketchunk.length; i++) { - if (socketchunk[i] === ''){ - socketchunk.splice(i, 1); - } - } - - - //iterate through socketchunks array to execute multiple commands in row - for (i = 0; i < socketchunk.length; i++) { - - //check if data is not empty - if(socketchunk[i].length > 0){ - - //try to parse JSON - try { - - data = JSON.parse(socketchunk[i]) - - } catch (e) { - console.log(e); // "SyntaxError - daemonLog.error(e); - daemonLog.debug(socketchunk[i]) - socketchunk = '' - - } - - } - - - - - if (data['command'] == 'daemon_state') { - let Data = { - input_devices: data['input_devices'], - output_devices: data['output_devices'], - python_version: data['python_version'], - hamlib_version: data['hamlib_version'], - serial_devices: data['serial_devices'], - tnc_running_state: data['daemon_state'][0]['status'], - ram_usage: data['ram'], - cpu_usage: data['cpu'], - version: data['version'], - }; - ipcRenderer.send('request-update-daemon-state', Data); - } - - if (data['command'] == 'test_hamlib') { - let Data = { - hamlib_result: data['result'], - - }; - ipcRenderer.send('request-update-hamlib-test', Data); - } - - - - } - - //finally delete message buffer - socketchunk = ''; - + // search for empty entries in socketchunk and remove them + for (i = 0; i < socketchunk.length; i++) { + if (socketchunk[i] === "") { + socketchunk.splice(i, 1); + } } + + //iterate through socketchunks array to execute multiple commands in row + for (i = 0; i < socketchunk.length; i++) { + //check if data is not empty + if (socketchunk[i].length > 0) { + //try to parse JSON + try { + data = JSON.parse(socketchunk[i]); + } catch (e) { + console.log(e); // "SyntaxError + daemonLog.error(e); + daemonLog.debug(socketchunk[i]); + socketchunk = ""; + } + } + + if (data["command"] == "daemon_state") { + let Data = { + input_devices: data["input_devices"], + output_devices: data["output_devices"], + python_version: data["python_version"], + hamlib_version: data["hamlib_version"], + serial_devices: data["serial_devices"], + tnc_running_state: data["daemon_state"][0]["status"], + ram_usage: data["ram"], + cpu_usage: data["cpu"], + version: data["version"], + }; + ipcRenderer.send("request-update-daemon-state", Data); + } + + if (data["command"] == "test_hamlib") { + let Data = { + hamlib_result: data["result"], + }; + ipcRenderer.send("request-update-hamlib-test", Data); + } + } + + //finally delete message buffer + socketchunk = ""; + } }); function hexToBytes(hex) { - for (var bytes = [], c = 0; c < hex.length; c += 2) - bytes.push(parseInt(hex.substr(c, 2), 16)); - return bytes; + for (var bytes = [], c = 0; c < hex.length; c += 2) + bytes.push(parseInt(hex.substr(c, 2), 16)); + return bytes; } -exports.getDaemonState = function() { - //function getDaemonState(){ - command = '{"type" : "get", "command" : "daemon_state"}' - writeDaemonCommand(command) -} +exports.getDaemonState = function () { + //function getDaemonState(){ + command = '{"type" : "get", "command" : "daemon_state"}'; + writeDaemonCommand(command); +}; // START TNC // ` `== multi line string -exports.startTNC = function(mycall, mygrid, rx_audio, tx_audio, radiocontrol, devicename, deviceport, pttprotocol, pttport, serialspeed, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port, enable_fft, enable_scatter, low_bandwidth_mode, tuning_range_fmin, tuning_range_fmax, enable_fsk, tx_audio_level, respond_to_cq, rx_buffer_size, enable_explorer, explorer_stats, auto_tune) { - var json_command = JSON.stringify({ - type: 'set', - command: 'start_tnc', - parameter: [{ - mycall: mycall, - mygrid: mygrid, - rx_audio: rx_audio, - tx_audio: tx_audio, - radiocontrol: radiocontrol, - devicename: devicename, - deviceport: deviceport, - pttprotocol: pttprotocol, - pttport: pttport, - serialspeed: serialspeed, - data_bits: data_bits, - stop_bits: stop_bits, - handshake: handshake, - rigctld_port: rigctld_port, - rigctld_ip: rigctld_ip, - enable_scatter: enable_scatter, - enable_fft: enable_fft, - enable_fsk: enable_fsk, - low_bandwidth_mode : low_bandwidth_mode, - tuning_range_fmin : tuning_range_fmin, - tuning_range_fmax : tuning_range_fmax, - tx_audio_level : tx_audio_level, - respond_to_cq : respond_to_cq, - rx_buffer_size : rx_buffer_size, - enable_explorer : enable_explorer, - enable_stats: explorer_stats, - enable_auto_tune: auto_tune - }] - }) +exports.startTNC = function ( + mycall, + mygrid, + rx_audio, + tx_audio, + radiocontrol, + devicename, + deviceport, + pttprotocol, + pttport, + serialspeed, + data_bits, + stop_bits, + handshake, + rigctld_ip, + rigctld_port, + enable_fft, + enable_scatter, + low_bandwidth_mode, + tuning_range_fmin, + tuning_range_fmax, + enable_fsk, + tx_audio_level, + respond_to_cq, + rx_buffer_size, + enable_explorer, + explorer_stats, + auto_tune +) { + var json_command = JSON.stringify({ + type: "set", + command: "start_tnc", + parameter: [ + { + mycall: mycall, + mygrid: mygrid, + rx_audio: rx_audio, + tx_audio: tx_audio, + radiocontrol: radiocontrol, + devicename: devicename, + deviceport: deviceport, + pttprotocol: pttprotocol, + pttport: pttport, + serialspeed: serialspeed, + data_bits: data_bits, + stop_bits: stop_bits, + handshake: handshake, + rigctld_port: rigctld_port, + rigctld_ip: rigctld_ip, + enable_scatter: enable_scatter, + enable_fft: enable_fft, + enable_fsk: enable_fsk, + low_bandwidth_mode: low_bandwidth_mode, + tuning_range_fmin: tuning_range_fmin, + tuning_range_fmax: tuning_range_fmax, + tx_audio_level: tx_audio_level, + respond_to_cq: respond_to_cq, + rx_buffer_size: rx_buffer_size, + enable_explorer: enable_explorer, + enable_stats: explorer_stats, + enable_auto_tune: auto_tune, + }, + ], + }); - daemonLog.debug(json_command); - writeDaemonCommand(json_command) - -} + daemonLog.debug(json_command); + writeDaemonCommand(json_command); +}; // STOP TNC -exports.stopTNC = function() { - command = '{"type" : "set", "command": "stop_tnc" , "parameter": "---" }' - writeDaemonCommand(command) -} +exports.stopTNC = function () { + command = '{"type" : "set", "command": "stop_tnc" , "parameter": "---" }'; + writeDaemonCommand(command); +}; // TEST HAMLIB -exports.testHamlib = function(radiocontrol, devicename, deviceport, serialspeed, pttprotocol, pttport, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port) { - - var json_command = JSON.stringify({ - type: 'get', - command: 'test_hamlib', - parameter: [{ - radiocontrol: radiocontrol, - devicename: devicename, - deviceport: deviceport, - pttprotocol: pttprotocol, - pttport: pttport, - serialspeed: serialspeed, - data_bits: data_bits, - stop_bits: stop_bits, - handshake: handshake, - rigctld_port: rigctld_port, - rigctld_ip: rigctld_ip - }] - }) - daemonLog.debug(json_command); - writeDaemonCommand(json_command) -} - - +exports.testHamlib = function ( + radiocontrol, + devicename, + deviceport, + serialspeed, + pttprotocol, + pttport, + data_bits, + stop_bits, + handshake, + rigctld_ip, + rigctld_port +) { + var json_command = JSON.stringify({ + type: "get", + command: "test_hamlib", + parameter: [ + { + radiocontrol: radiocontrol, + devicename: devicename, + deviceport: deviceport, + pttprotocol: pttprotocol, + pttport: pttport, + serialspeed: serialspeed, + data_bits: data_bits, + stop_bits: stop_bits, + handshake: handshake, + rigctld_port: rigctld_port, + rigctld_ip: rigctld_ip, + }, + ], + }); + daemonLog.debug(json_command); + writeDaemonCommand(json_command); +}; //Save myCall -exports.saveMyCall = function(callsign) { - command = '{"type" : "set", "command": "mycallsign" , "parameter": "' + callsign + '"}' - writeDaemonCommand(command) -} +exports.saveMyCall = function (callsign) { + command = + '{"type" : "set", "command": "mycallsign" , "parameter": "' + + callsign + + '"}'; + writeDaemonCommand(command); +}; // Save myGrid -exports.saveMyGrid = function(grid) { - command = '{"type" : "set", "command": "mygrid" , "parameter": "' + grid + '"}' - writeDaemonCommand(command) -} +exports.saveMyGrid = function (grid) { + command = + '{"type" : "set", "command": "mygrid" , "parameter": "' + grid + '"}'; + writeDaemonCommand(command); +}; -ipcRenderer.on('action-update-daemon-ip', (event, arg) => { - daemon.destroy(); - let Data = { - busy_state: "-", - arq_state: "-", - //channel_state: "-", - frequency: "-", - mode: "-", - bandwidth: "-", - dbfs_level: 0 - }; - ipcRenderer.send('request-update-tnc-state', Data); - daemon_port = arg.port; - daemon_host = arg.adress; - connectDAEMON(); +ipcRenderer.on("action-update-daemon-ip", (event, arg) => { + daemon.destroy(); + let Data = { + busy_state: "-", + arq_state: "-", + //channel_state: "-", + frequency: "-", + mode: "-", + bandwidth: "-", + dbfs_level: 0, + }; + ipcRenderer.send("request-update-tnc-state", Data); + daemon_port = arg.port; + daemon_host = arg.adress; + connectDAEMON(); }); diff --git a/gui/main.js b/gui/main.js index c251f169..eb393979 100644 --- a/gui/main.js +++ b/gui/main.js @@ -1,26 +1,20 @@ -const { - app, - BrowserWindow, - ipcMain, - dialog, - shell -} = require('electron'); -const { autoUpdater } = require('electron-updater'); -const path = require('path'); -const fs = require('fs'); -const os = require('os'); -const spawn = require('child_process').spawn; +const { app, BrowserWindow, ipcMain, dialog, shell } = require("electron"); +const { autoUpdater } = require("electron-updater"); +const path = require("path"); +const fs = require("fs"); +const os = require("os"); +const spawn = require("child_process").spawn; -const log = require('electron-log'); -const mainLog = log.scope('main'); -const daemonProcessLog = log.scope('freedata-daemon'); -const mime = require('mime'); -const net = require('net'); +const log = require("electron-log"); +const mainLog = log.scope("main"); +const daemonProcessLog = log.scope("freedata-daemon"); +const mime = require("mime"); +const net = require("net"); //Useful for debugging event emitter memory leaks //require('events').EventEmitter.defaultMaxListeners = 10; //process.traceProcessWarnings=true; -const sysInfo = log.scope('system information'); +const sysInfo = log.scope("system information"); sysInfo.info("SYSTEM INFORMATION ----------------------------- "); sysInfo.info("APP VERSION : " + app.getVersion()); sysInfo.info("PLATFORM : " + os.platform()); @@ -33,21 +27,24 @@ sysInfo.info("TYPE : " + os.type()); sysInfo.info("VERSION : " + os.version()); sysInfo.info("UPTIME : " + os.uptime()); - - app.setName("FreeDATA"); -var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config"); +var appDataFolder = + process.env.APPDATA || + (process.platform == "darwin" + ? process.env.HOME + "/Library/Application Support" + : process.env.HOME + "/.config"); var configFolder = path.join(appDataFolder, "FreeDATA"); -var configPath = path.join(configFolder, 'config.json'); +var configPath = path.join(configFolder, "config.json"); // create config folder if not exists if (!fs.existsSync(configFolder)) { - fs.mkdirSync(configFolder); + fs.mkdirSync(configFolder); } // create config file if not exists with defaults -const configDefaultSettings = '{\ +const configDefaultSettings = + '{\ "tnc_host": "127.0.0.1",\ "tnc_port": "3000",\ "daemon_host": "127.0.0.1",\ @@ -56,28 +53,21 @@ const configDefaultSettings = '{\ "mygrid": "JN40aa",\ "radiocontrol" : "disabled",\ "hamlib_deviceid": "RIG_MODEL_DUMMY_NOVFO",\ - "enable_hamlib_deviceport" : "False",\ - "hamlib_deviceport": "/dev/ttyACM1",\ - "enable_hamlib_stop_bits" : "False",\ - "hamlib_stop_bits" : "1",\ - "enable_hamlib_data_bits" : "False",\ - "hamlib_data_bits" : "8",\ - "enable_hamlib_handshake" : "False",\ - "hamlib_handshake" : "None",\ - "enable_hamlib_serialspeed" : "False",\ - "hamlib_serialspeed" : "9600",\ - "enable_hamlib_pttprotocol" : "False",\ - "hamlib_dtrstate" : "OFF",\ - "enable_hamlib_dtrstate" : "False",\ - "hamlib_pttprotocol" : "USB",\ - "enable_hamlib_pttport" : "False",\ - "hamlib_pttport": "/dev/ttyACM1",\ - "hamlib_dcd": "None",\ + "hamlib_deviceport": "ignore",\ + "hamlib_stop_bits": "ignore",\ + "hamlib_data_bits": "ignore",\ + "hamlib_handshake": "ignore",\ + "hamlib_serialspeed": "ignore",\ + "hamlib_dtrstate": "ignore",\ + "hamlib_pttprotocol": "ignore",\ + "hamlib_ptt_port": "ignore",\ + "hamlib_dcd": "ignore",\ "hamlbib_serialspeed_ptt": "9600",\ "hamlib_rigctld_port" : "4532",\ "hamlib_rigctld_ip" : "127.0.0.1",\ "hamlib_rigctld_path" : "",\ "hamlib_rigctld_server_port" : "4532",\ + "hamlib_rigctld_custom_args": "",\ "spectrum": "waterfall",\ "tnclocation": "localhost",\ "enable_scatter" : "False",\ @@ -98,11 +88,12 @@ const configDefaultSettings = '{\ "wftheme": 2, \ "high_graphics" : "True",\ "explorer_stats" : "False", \ - "auto_tune" : "False" \ + "auto_tune" : "False", \ + "enable_is_writing" : "True" \ }'; if (!fs.existsSync(configPath)) { - fs.writeFileSync(configPath, configDefaultSettings) + fs.writeFileSync(configPath, configDefaultSettings); } // load settings @@ -114,21 +105,17 @@ var config = require(configPath); sysInfo.info("CONFIG VALIDATION ----------------------------- "); var parsedConfig = JSON.parse(configDefaultSettings); -for (key in parsedConfig) { - if (config.hasOwnProperty(key)) { - sysInfo.info("FOUND SETTTING [" + key + "]: " + config[key]); - } else { - sysInfo.error("MISSING SETTTING [" + key + "] : " + parsedConfig[key]); - config[key] = parsedConfig[key]; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - } +for (key in parsedConfig) { + if (config.hasOwnProperty(key)) { + sysInfo.info("FOUND SETTTING [" + key + "]: " + config[key]); + } else { + sysInfo.error("MISSING SETTTING [" + key + "] : " + parsedConfig[key]); + config[key] = parsedConfig[key]; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + } } sysInfo.info("------------------------------------------ "); - - - - /* var chatDB = path.join(configFolder, 'chatDB.json') // create chat database file if not exists @@ -148,7 +135,6 @@ if (!fs.existsSync(chatDB)) { } */ - /* // Creates receivedFiles folder if not exists // https://stackoverflow.com/a/26227660 @@ -165,259 +151,235 @@ fs.mkdir(receivedFilesFolder, { */ - - - - - let win = null; let data = null; let logViewer = null; var daemonProcess = null; - // create a splash screen -function createSplashScreen(){ - splashScreen = new BrowserWindow({ - height: 250, - width: 250, - transparent: true, - frame: false, - alwaysOnTop: true - }); - splashScreen.loadFile('src/splash.html'); - splashScreen.center(); +function createSplashScreen() { + splashScreen = new BrowserWindow({ + height: 250, + width: 250, + transparent: true, + frame: false, + alwaysOnTop: true, + }); + splashScreen.loadFile("src/splash.html"); + splashScreen.center(); } - function createWindow() { - win = new BrowserWindow({ - width: config.screen_width, - height: config.screen_height, - show: false, - autoHideMenuBar: true, - icon: 'src/img/icon.png', - webPreferences: { - //preload: path.join(__dirname, 'preload-main.js'), - backgroundThrottle: false, - preload: require.resolve('./preload-main.js'), - nodeIntegration: true, - contextIsolation: false, - enableRemoteModule: false, - sandbox: false - //https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655 - //https://github.com/electron/remote - } - }) - // hide menu bar - win.setMenuBarVisibility(false) - - //open dev tools - /*win.webContents.openDevTools({ + win = new BrowserWindow({ + width: config.screen_width, + height: config.screen_height, + show: false, + autoHideMenuBar: true, + icon: "src/img/icon.png", + webPreferences: { + //preload: path.join(__dirname, 'preload-main.js'), + backgroundThrottle: false, + preload: require.resolve("./preload-main.js"), + nodeIntegration: true, + contextIsolation: false, + enableRemoteModule: false, + sandbox: false, + //https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655 + //https://github.com/electron/remote + }, + }); + // hide menu bar + win.setMenuBarVisibility(false); + + //open dev tools + /*win.webContents.openDevTools({ mode: 'undocked', activate: true, }) */ - win.loadFile('src/index.html') - - chat = new BrowserWindow({ - height: 600, - width: 1000, - show: false, - //parent: win, - webPreferences: { - preload: require.resolve('./preload-chat.js'), - nodeIntegration: true, + win.loadFile("src/index.html"); - } - }) + chat = new BrowserWindow({ + height: 600, + width: 1000, + show: false, + //parent: win, + webPreferences: { + preload: require.resolve("./preload-chat.js"), + nodeIntegration: true, + }, + }); - chat.loadFile('src/chat-module.html'); - chat.setMenuBarVisibility(false); + chat.loadFile("src/chat-module.html"); + chat.setMenuBarVisibility(false); - - logViewer = new BrowserWindow({ - height: 900, - width: 600, - show: false, - //parent: win, - webPreferences: { - preload: require.resolve('./preload-log.js'), - nodeIntegration: true, + logViewer = new BrowserWindow({ + height: 900, + width: 600, + show: false, + //parent: win, + webPreferences: { + preload: require.resolve("./preload-log.js"), + nodeIntegration: true, + }, + }); - } - }) + logViewer.loadFile("src/log-module.html"); + logViewer.setMenuBarVisibility(false); - logViewer.loadFile('src/log-module.html'); - logViewer.setMenuBarVisibility(false); + // Emitted when the window is closed. + logViewer.on("close", function (evt) { + if (logViewer !== null) { + evt.preventDefault(); + logViewer.hide(); + } else { + this.close(); + } + }); - // Emitted when the window is closed. - logViewer.on('close', function(evt) { - if (logViewer !== null){ - evt.preventDefault(); - logViewer.hide(); - } else { - this.close() - } - }) - - - - - - - - // Emitted when the window is closed. - win.on('closed', function() { - console.log("closing all windows.....") - /* + // Emitted when the window is closed. + win.on("closed", function () { + console.log("closing all windows....."); + /* win = null; chat = null; logViewer = null; */ - close_all(); - - }) - - - win.once('ready-to-show', () => { - - log.transports.file.level = "debug" - autoUpdater.logger = log.scope('updater'); - - autoUpdater.channel = config.update_channel - - autoUpdater.autoInstallOnAppQuit = false; - autoUpdater.autoDownload = true; - autoUpdater.checkForUpdatesAndNotify(); - //autoUpdater.quitAndInstall(); - }); + close_all(); + }); - - chat.on('closed', function () { - - }) - + win.once("ready-to-show", () => { + log.transports.file.level = "debug"; + autoUpdater.logger = log.scope("updater"); - // https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron - chat.on('close', function(evt) { - evt.preventDefault(); - chat.hide(); - }); - + autoUpdater.channel = config.update_channel; + + autoUpdater.autoInstallOnAppQuit = false; + autoUpdater.autoDownload = true; + autoUpdater.checkForUpdatesAndNotify(); + //autoUpdater.quitAndInstall(); + }); + + chat.on("closed", function () {}); + + // https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron + chat.on("close", function (evt) { + evt.preventDefault(); + chat.hide(); + }); } app.whenReady().then(() => { + // show splash screen + createSplashScreen(); - // show splash screen - createSplashScreen(); + // create main window + createWindow(); - // create main window - createWindow(); + // wait some time, then close splash screen and show main windows + setTimeout(function () { + splashScreen.close(); + win.show(); + }, 3000); - // wait some time, then close splash screen and show main windows - setTimeout(function() { - splashScreen.close(); - win.show(); - }, 3000); + //Generate daemon binary path + var daemonPath = ""; + switch (os.platform().toLowerCase()) { + case "darwin": + case "linux": + daemonPath = path.join(process.resourcesPath, "tnc", "freedata-daemon"); - //Generate daemon binary path - var daemonPath = ""; - switch (os.platform().toLowerCase()){ - case "darwin": - case "linux": - daemonPath = path.join(process.resourcesPath, 'tnc', 'freedata-daemon') - - break; - case "win32": - case "win64": - daemonPath = path.join(process.resourcesPath, 'tnc', 'freedata-daemon.exe') - break; - default: - console.log("Unhandled OS Platform: ", os.platform()); - break; - } + break; + case "win32": + case "win64": + daemonPath = path.join( + process.resourcesPath, + "tnc", + "freedata-daemon.exe" + ); + break; + default: + console.log("Unhandled OS Platform: ", os.platform()); + break; + } - //Start daemon binary if it exists - if (fs.existsSync(daemonPath)){ - mainLog.info('Starting freedata-daemon binary'); - daemonProcess = spawn(daemonPath,[], - { - cwd: path.join(daemonPath,".."), - }); - // return process messages - daemonProcess.on('error', (err) => { - daemonProcessLog.error(`error when starting daemon: ${err}`); - }); - daemonProcess.on('message', (data) => { - daemonProcessLog.info(`${data}`); - }); - daemonProcess.stdout.on('data', (data) => { - daemonProcessLog.info(`${data}`); - }); - daemonProcess.stderr.on('data', (data) => { - daemonProcessLog.info(`${data}`); - let arg = { - entry: `${data}` - }; - // send info to log only if log screen available - // it seems an error occurs when updating - if (logViewer !== null && logViewer !== ''){ - try{ - logViewer.webContents.send('action-update-log', arg); - } catch (e) { - // empty for keeping error stuff silent - // this is important to avoid error messages if we are going to close the app while - // an logging information will be pushed to the logger - } - } - }); - daemonProcess.on('close', (code) => { - daemonProcessLog.warn(`daemonProcess exited with code ${code}`); - }); - } else { - daemonProcess=null; - daemonPath=null; - mainLog.info("Daemon binary doesn't exist--normal for dev environments.") - } - win.send("action-set-app-version",app.getVersion()); + //Start daemon binary if it exists + if (fs.existsSync(daemonPath)) { + mainLog.info("Starting freedata-daemon binary"); + daemonProcess = spawn(daemonPath, [], { + cwd: path.join(daemonPath, ".."), + }); + // return process messages + daemonProcess.on("error", (err) => { + daemonProcessLog.error(`error when starting daemon: ${err}`); + }); + daemonProcess.on("message", (data) => { + daemonProcessLog.info(`${data}`); + }); + daemonProcess.stdout.on("data", (data) => { + daemonProcessLog.info(`${data}`); + }); + daemonProcess.stderr.on("data", (data) => { + daemonProcessLog.info(`${data}`); + let arg = { + entry: `${data}`, + }; + // send info to log only if log screen available + // it seems an error occurs when updating + if (logViewer !== null && logViewer !== "") { + try { + logViewer.webContents.send("action-update-log", arg); + } catch (e) { + // empty for keeping error stuff silent + // this is important to avoid error messages if we are going to close the app while + // an logging information will be pushed to the logger + } + } + }); + daemonProcess.on("close", (code) => { + daemonProcessLog.warn(`daemonProcess exited with code ${code}`); + }); + } else { + daemonProcess = null; + daemonPath = null; + mainLog.info("Daemon binary doesn't exist--normal for dev environments."); + } + win.send("action-set-app-version", app.getVersion()); }); -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow(); - } -}) +app.on("activate", () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow(); + } +}); -app.on('window-all-closed', () => { - close_all(); - -}) +app.on("window-all-closed", () => { + close_all(); +}); // IPC HANDLER //Show/update task bar/button progressbar -ipcMain.on('request-show-electron-progressbar',(event,data)=>{ - win.setProgressBar(data/100); +ipcMain.on("request-show-electron-progressbar", (event, data) => { + win.setProgressBar(data / 100); }); -ipcMain.on('request-show-chat-window', () => { - chat.show(); - }); +ipcMain.on("request-show-chat-window", () => { + chat.show(); +}); // UPDATE TNC CONNECTION -ipcMain.on('request-update-tnc-ip',(event,data)=>{ - win.webContents.send('action-update-tnc-ip', data); +ipcMain.on("request-update-tnc-ip", (event, data) => { + win.webContents.send("action-update-tnc-ip", data); }); // UPDATE DAEMON CONNECTION -ipcMain.on('request-update-daemon-ip',(event,data)=>{ - win.webContents.send('action-update-daemon-ip', data); +ipcMain.on("request-update-daemon-ip", (event, data) => { + win.webContents.send("action-update-daemon-ip", data); }); - -ipcMain.on('request-update-tnc-state', (event, arg) => { - win.webContents.send('action-update-tnc-state', arg); - //data.webContents.send('action-update-tnc-state', arg); +ipcMain.on("request-update-tnc-state", (event, arg) => { + win.webContents.send("action-update-tnc-state", arg); + //data.webContents.send('action-update-tnc-state', arg); }); /* @@ -430,30 +392,32 @@ ipcMain.on('request-update-heard-stations', (event, arg) => { win.webContents.send('action-update-heard-stations', arg); }); */ -ipcMain.on('request-update-daemon-state', (event, arg) => { - win.webContents.send('action-update-daemon-state', arg); +ipcMain.on("request-update-daemon-state", (event, arg) => { + win.webContents.send("action-update-daemon-state", arg); }); -ipcMain.on('request-update-hamlib-test', (event, arg) => { - win.webContents.send('action-update-hamlib-test', arg); +ipcMain.on("request-update-hamlib-test", (event, arg) => { + win.webContents.send("action-update-hamlib-test", arg); }); - - -ipcMain.on('request-update-tnc-connection', (event, arg) => { - win.webContents.send('action-update-tnc-connection', arg); +ipcMain.on("request-update-tnc-connection", (event, arg) => { + win.webContents.send("action-update-tnc-connection", arg); }); -ipcMain.on('request-update-daemon-connection', (event, arg) => { - win.webContents.send('action-update-daemon-connection', arg); +ipcMain.on("request-update-daemon-connection", (event, arg) => { + win.webContents.send("action-update-daemon-connection", arg); }); -ipcMain.on('run-tnc-command', (event, arg) => { - win.webContents.send('run-tnc-command', arg); +ipcMain.on("run-tnc-command", (event, arg) => { + win.webContents.send("run-tnc-command", arg); }); -ipcMain.on('request-update-rx-buffer', (event, arg) => { - win.webContents.send('action-update-rx-buffer', arg); +ipcMain.on("tnc-fec-iswriting", (event, arg) => { + win.webContents.send("run-tnc-command-fec-iswriting"); +}); + +ipcMain.on("request-update-rx-buffer", (event, arg) => { + win.webContents.send("action-update-rx-buffer", arg); }); /* @@ -461,480 +425,472 @@ ipcMain.on('request-update-rx-msg-buffer', (event, arg) => { chat.webContents.send('action-update-rx-msg-buffer', arg); }); */ -ipcMain.on('request-new-msg-received', (event, arg) => { - chat.webContents.send('action-new-msg-received', arg); +ipcMain.on("request-new-msg-received", (event, arg) => { + chat.webContents.send("action-new-msg-received", arg); }); -ipcMain.on('request-update-transmission-status', (event, arg) => { - chat.webContents.send('action-update-transmission-status', arg); - win.webContents.send('action-update-transmission-status',arg); +ipcMain.on("request-update-transmission-status", (event, arg) => { + chat.webContents.send("action-update-transmission-status", arg); + win.webContents.send("action-update-transmission-status", arg); }); -ipcMain.on('request-update-reception-status', (event, arg) => { - win.webContents.send('action-update-reception-status',arg); +ipcMain.on("request-update-reception-status", (event, arg) => { + win.webContents.send("action-update-reception-status", arg); }); -ipcMain.on('request-open-tnc-log', () => { - logViewer.show(); +ipcMain.on("request-open-tnc-log", () => { + logViewer.show(); }); //file selector -ipcMain.on('get-file-path',(event,data)=>{ - dialog.showOpenDialog({defaultPath: path.join(__dirname, '../'), - buttonLabel: 'Select rigctld', properties: ['openFile']}).then(filePaths => { - win.webContents.send('return-file-paths', {path: filePaths,}) - +ipcMain.on("get-file-path", (event, data) => { + dialog + .showOpenDialog({ + defaultPath: path.join(__dirname, "../"), + buttonLabel: "Select rigctld", + properties: ["openFile"], + }) + .then((filePaths) => { + win.webContents.send("return-file-paths", { path: filePaths }); }); }); //folder selector -ipcMain.on('get-folder-path',(event,data)=>{ - dialog.showOpenDialog({defaultPath: path.join(__dirname, '../'), - buttonLabel: 'Select folder', properties: ['openDirectory']}).then(folderPaths => { - win.webContents.send('return-folder-paths', {path: folderPaths,}) - +ipcMain.on("get-folder-path", (event, data) => { + dialog + .showOpenDialog({ + defaultPath: path.join(__dirname, "../"), + buttonLabel: "Select folder", + properties: ["openDirectory"], + }) + .then((folderPaths) => { + win.webContents.send("return-folder-paths", { path: folderPaths }); }); }); //open folder -ipcMain.on('open-folder',(event,data)=>{ - shell.showItemInFolder(data.path) +ipcMain.on("open-folder", (event, data) => { + shell.showItemInFolder(data.path); }); //select file -ipcMain.on('select-file',(event,data)=>{ - dialog.showOpenDialog({defaultPath: path.join(__dirname, '../'), - buttonLabel: 'Select file', properties: ['openFile']}).then(filepath => { - -console.log(filepath.filePaths[0]) - - try { - //fs.readFile(filepath.filePaths[0], 'utf8', function (err, data) { - //Has to be binary - fs.readFile(filepath.filePaths[0],'binary', function (err, data) { - - console.log(data.length) - - console.log(data) - - var filename = path.basename(filepath.filePaths[0]) - var mimeType = mime.getType(filename) - console.log(mimeType) - if (mimeType == '' || mimeType == null){ - mimeType = 'plain/text' - } - chat.webContents.send('return-selected-files', {data : data, mime: mimeType, filename: filename}) +ipcMain.on("select-file", (event, data) => { + dialog + .showOpenDialog({ + defaultPath: path.join(__dirname, "../"), + buttonLabel: "Select file", + properties: ["openFile"], }) - - } catch (err) { - console.log(err); - } + .then((filepath) => { + console.log(filepath.filePaths[0]); - }); + try { + //fs.readFile(filepath.filePaths[0], 'utf8', function (err, data) { + //Has to be binary + fs.readFile(filepath.filePaths[0], "binary", function (err, data) { + console.log(data.length); + console.log(data); + + var filename = path.basename(filepath.filePaths[0]); + var mimeType = mime.getType(filename); + console.log(mimeType); + if (mimeType == "" || mimeType == null) { + mimeType = "plain/text"; + } + chat.webContents.send("return-selected-files", { + data: data, + mime: mimeType, + filename: filename, + }); + }); + } catch (err) { + console.log(err); + } + }); }); //save file to folder -ipcMain.on('save-file-to-folder',(event,data)=>{ +ipcMain.on("save-file-to-folder", (event, data) => { + console.log(data.file); - console.log(data.file) - - dialog.showSaveDialog({defaultPath: data.filename}).then(filepath => { + dialog.showSaveDialog({ defaultPath: data.filename }).then((filepath) => { + console.log(filepath.filePath); + console.log(data.file); - console.log(filepath.filePath) - console.log(data.file) - - try { - let arraybuffer = Buffer.from(data.file,"base64").toString('utf-8'); - console.log(arraybuffer) - //Has to be binary - fs.writeFile(filepath.filePath, arraybuffer, 'binary', function (err, data) { - }) - } catch (err) { - console.log(err); - } - - }); - - - + try { + let arraybuffer = Buffer.from(data.file, "base64").toString("utf-8"); + console.log(arraybuffer); + //Has to be binary + fs.writeFile( + filepath.filePath, + arraybuffer, + "binary", + function (err, data) {} + ); + } catch (err) { + console.log(err); + } + }); }); - - //tnc messages START -------------------------------------- +// FEC iswriting received +ipcMain.on("request-show-fec-toast-iswriting", (event, data) => { + //win.webContents.send("action-show-fec-toast-iswriting", data); + chat.webContents.send("action-show-feciswriting", data); +}); + // CQ TRANSMITTING -ipcMain.on('request-show-cq-toast-transmitting',(event,data)=>{ - win.webContents.send('action-show-cq-toast-transmitting', data); +ipcMain.on("request-show-cq-toast-transmitting", (event, data) => { + win.webContents.send("action-show-cq-toast-transmitting", data); }); // CQ RECEIVED -ipcMain.on('request-show-cq-toast-received',(event,data)=>{ - win.webContents.send('action-show-cq-toast-received', data); +ipcMain.on("request-show-cq-toast-received", (event, data) => { + win.webContents.send("action-show-cq-toast-received", data); }); // QRV TRANSMITTING -ipcMain.on('request-show-qrv-toast-transmitting',(event,data)=>{ - win.webContents.send('action-show-qrv-toast-transmitting', data); +ipcMain.on("request-show-qrv-toast-transmitting", (event, data) => { + win.webContents.send("action-show-qrv-toast-transmitting", data); }); // QRV RECEIVED -ipcMain.on('request-show-qrv-toast-received',(event,data)=>{ - win.webContents.send('action-show-qrv-toast-received', data); +ipcMain.on("request-show-qrv-toast-received", (event, data) => { + win.webContents.send("action-show-qrv-toast-received", data); }); // BEACON TRANSMITTING -ipcMain.on('request-show-beacon-toast-transmitting',(event,data)=>{ - win.webContents.send('action-show-beacon-toast-transmitting', data); +ipcMain.on("request-show-beacon-toast-transmitting", (event, data) => { + win.webContents.send("action-show-beacon-toast-transmitting", data); }); // BEACON RECEIVED -ipcMain.on('request-show-beacon-toast-received',(event,data)=>{ - win.webContents.send('action-show-beacon-toast-received', data); +ipcMain.on("request-show-beacon-toast-received", (event, data) => { + win.webContents.send("action-show-beacon-toast-received", data); }); // PING TRANSMITTING -ipcMain.on('request-show-ping-toast-transmitting',(event,data)=>{ - win.webContents.send('action-show-ping-toast-transmitting', data); +ipcMain.on("request-show-ping-toast-transmitting", (event, data) => { + win.webContents.send("action-show-ping-toast-transmitting", data); }); // PING RECEIVED -ipcMain.on('request-show-ping-toast-received',(event,data)=>{ - win.webContents.send('action-show-ping-toast-received', data); +ipcMain.on("request-show-ping-toast-received", (event, data) => { + win.webContents.send("action-show-ping-toast-received", data); }); // PING RECEIVED ACK -ipcMain.on('request-show-ping-toast-received-ack',(event,data)=>{ - win.webContents.send('action-show-ping-toast-received-ack', data); +ipcMain.on("request-show-ping-toast-received-ack", (event, data) => { + win.webContents.send("action-show-ping-toast-received-ack", data); }); // ARQ DATA CHANNEL OPENING -ipcMain.on('request-show-arq-toast-datachannel-opening',(event,data)=>{ - win.webContents.send('action-show-arq-toast-datachannel-opening', data); +ipcMain.on("request-show-arq-toast-datachannel-opening", (event, data) => { + win.webContents.send("action-show-arq-toast-datachannel-opening", data); }); // ARQ DATA CHANNEL WAITING -ipcMain.on('request-show-arq-toast-datachannel-waiting',(event,data)=>{ - win.webContents.send('action-show-arq-toast-datachannel-waiting', data); +ipcMain.on("request-show-arq-toast-datachannel-waiting", (event, data) => { + win.webContents.send("action-show-arq-toast-datachannel-waiting", data); }); - // ARQ DATA CHANNEL OPEN -ipcMain.on('request-show-arq-toast-datachannel-opened',(event,data)=>{ - win.webContents.send('action-show-arq-toast-datachannel-opened', data); +ipcMain.on("request-show-arq-toast-datachannel-opened", (event, data) => { + win.webContents.send("action-show-arq-toast-datachannel-opened", data); }); // ARQ DATA RECEIVED OPENER -ipcMain.on('request-show-arq-toast-datachannel-received-opener',(event,data)=>{ - win.webContents.send('action-show-arq-toast-datachannel-received-opener', data); +ipcMain.on( + "request-show-arq-toast-datachannel-received-opener", + (event, data) => { + win.webContents.send( + "action-show-arq-toast-datachannel-received-opener", + data + ); + } +); + +// ARQ TRANSMISSION FAILED +ipcMain.on("request-show-arq-toast-transmission-failed", (event, data) => { + win.webContents.send("action-show-arq-toast-transmission-failed", data); }); // ARQ TRANSMISSION FAILED -ipcMain.on('request-show-arq-toast-transmission-failed',(event,data)=>{ - win.webContents.send('action-show-arq-toast-transmission-failed', data); -}); - -// ARQ TRANSMISSION FAILED -ipcMain.on('request-show-arq-toast-transmission-failed-ver',(event,data)=>{ - win.webContents.send('action-show-arq-toast-transmission-failed-ver', data); +ipcMain.on("request-show-arq-toast-transmission-failed-ver", (event, data) => { + win.webContents.send("action-show-arq-toast-transmission-failed-ver", data); }); // ARQ TRANSMISSION RECEIVING -ipcMain.on('request-show-arq-toast-transmission-receiving',(event,data)=>{ - win.webContents.send('action-show-arq-toast-transmission-receiving', data); +ipcMain.on("request-show-arq-toast-transmission-receiving", (event, data) => { + win.webContents.send("action-show-arq-toast-transmission-receiving", data); }); // ARQ TRANSMISSION RECEIVED -ipcMain.on('request-show-arq-toast-transmission-received',(event,data)=>{ - win.webContents.send('action-show-arq-toast-transmission-received', data); +ipcMain.on("request-show-arq-toast-transmission-received", (event, data) => { + win.webContents.send("action-show-arq-toast-transmission-received", data); }); // ARQ TRANSMISSION TRANSMITTING -ipcMain.on('request-show-arq-toast-transmission-transmitting',(event,data)=>{ - win.webContents.send('action-show-arq-toast-transmission-transmitting', data); -}); +ipcMain.on( + "request-show-arq-toast-transmission-transmitting", + (event, data) => { + win.webContents.send( + "action-show-arq-toast-transmission-transmitting", + data + ); + } +); // ARQ TRANSMISSION TRANSMITTED -ipcMain.on('request-show-arq-toast-transmission-transmitted',(event,data)=>{ - win.webContents.send('action-show-arq-toast-transmission-transmitted', data); +ipcMain.on("request-show-arq-toast-transmission-transmitted", (event, data) => { + win.webContents.send("action-show-arq-toast-transmission-transmitted", data); }); // ARQ SESSION CONNECTING -ipcMain.on('request-show-arq-toast-session-connecting',(event,data)=>{ - win.webContents.send('action-show-arq-toast-session-connecting', data); +ipcMain.on("request-show-arq-toast-session-connecting", (event, data) => { + win.webContents.send("action-show-arq-toast-session-connecting", data); }); // ARQ SESSION WAITING -ipcMain.on('request-show-arq-toast-session-waiting',(event,data)=>{ - win.webContents.send('action-show-arq-toast-session-waiting', data); +ipcMain.on("request-show-arq-toast-session-waiting", (event, data) => { + win.webContents.send("action-show-arq-toast-session-waiting", data); }); // ARQ SESSION CONNECTED -ipcMain.on('request-show-arq-toast-session-connected',(event,data)=>{ - win.webContents.send('action-show-arq-toast-session-connected', data); +ipcMain.on("request-show-arq-toast-session-connected", (event, data) => { + win.webContents.send("action-show-arq-toast-session-connected", data); }); // ARQ SESSION CLOSE -ipcMain.on('request-show-arq-toast-session-close',(event,data)=>{ - win.webContents.send('action-show-arq-toast-session-close', data); +ipcMain.on("request-show-arq-toast-session-close", (event, data) => { + win.webContents.send("action-show-arq-toast-session-close", data); }); // ARQ SESSION FAILED -ipcMain.on('request-show-arq-toast-session-failed',(event,data)=>{ - win.webContents.send('action-show-arq-toast-session-failed', data); +ipcMain.on("request-show-arq-toast-session-failed", (event, data) => { + win.webContents.send("action-show-arq-toast-session-failed", data); }); - - //tnc messages END -------------------------------------- //restart and install udpate -ipcMain.on('request-restart-and-install',(event,data)=>{ - close_sub_processes() - autoUpdater.quitAndInstall(); +ipcMain.on("request-restart-and-install", (event, data) => { + close_sub_processes(); + autoUpdater.quitAndInstall(); }); // LISTENER FOR UPDATER EVENTS -autoUpdater.on('update-available', (info) => { - mainLog.info('update available'); +autoUpdater.on("update-available", (info) => { + mainLog.info("update available"); - let arg = { - status: "update-available", - info: info - }; - win.webContents.send('action-updater', arg); - + let arg = { + status: "update-available", + info: info, + }; + win.webContents.send("action-updater", arg); }); -autoUpdater.on('update-not-available', (info) => { - mainLog.info('update not available'); - let arg = { - status: "update-not-available", - info: info - }; - win.webContents.send('action-updater', arg); +autoUpdater.on("update-not-available", (info) => { + mainLog.info("update not available"); + let arg = { + status: "update-not-available", + info: info, + }; + win.webContents.send("action-updater", arg); }); - -autoUpdater.on('update-downloaded', (info) => { - mainLog.info('update downloaded'); - let arg = { - status: "update-downloaded", - info: info - }; - win.webContents.send('action-updater', arg); - // we need to call this at this point. +autoUpdater.on("update-downloaded", (info) => { + mainLog.info("update downloaded"); + let arg = { + status: "update-downloaded", + info: info, + }; + win.webContents.send("action-updater", arg); + // we need to call this at this point. // if an update is available and we are force closing the app // the entire screen crashes... //mainLog.info('quit application and install update'); //autoUpdater.quitAndInstall(); - - }); -autoUpdater.on('checking-for-update', () => { -mainLog.info('checking for update'); - let arg = { - status: "checking-for-update", - version: app.getVersion() - }; - win.webContents.send('action-updater', arg); +autoUpdater.on("checking-for-update", () => { + mainLog.info("checking for update"); + let arg = { + status: "checking-for-update", + version: app.getVersion(), + }; + win.webContents.send("action-updater", arg); }); -autoUpdater.on('download-progress', (progress) => { - let arg = { - status: "download-progress", - progress: progress - }; - win.webContents.send('action-updater', arg); +autoUpdater.on("download-progress", (progress) => { + let arg = { + status: "download-progress", + progress: progress, + }; + win.webContents.send("action-updater", arg); }); -autoUpdater.on('error', (error) => { - mainLog.info('update error'); - let arg = { - status: "error", - progress: error - }; - win.webContents.send('action-updater', arg); +autoUpdater.on("error", (error) => { + mainLog.info("update error"); + let arg = { + status: "error", + progress: error, + }; + win.webContents.send("action-updater", arg); mainLog.error("AUTO UPDATER : " + error); }); +function close_sub_processes() { + mainLog.warn("closing sub processes"); - -function close_sub_processes(){ - mainLog.warn('closing sub processes'); - - // closing the tnc binary if not closed when closing application and also our daemon which has been started by the gui - try { - if (daemonProcess != null) { - daemonProcess.kill(); - } - } catch (e) { - mainLog.error(e) + // closing the tnc binary if not closed when closing application and also our daemon which has been started by the gui + try { + if (daemonProcess != null) { + daemonProcess.kill(); } - + } catch (e) { + mainLog.error(e); + } - mainLog.warn('closing tnc and daemon'); - try { - - if(os.platform()=='win32' || os.platform()=='win64'){ - spawn('Taskkill', ['/IM', 'freedata-tnc.exe', '/F']) - spawn('Taskkill', ['/IM', 'freedata-daemon.exe', '/F']) - } - - if(os.platform()=='linux'){ - - spawn('pkill', ['-9', 'freedata-tnc']) - spawn('pkill', ['-9', 'freedata-daemon']) - } - - if(os.platform()=='darwin'){ - - spawn('pkill', ['-9', 'freedata-tnc']) - spawn('pkill', ['-9', 'freedata-daemon']) - - } - } catch (e) { - mainLog.error(e) + mainLog.warn("closing tnc and daemon"); + try { + if (os.platform() == "win32" || os.platform() == "win64") { + spawn("Taskkill", ["/IM", "freedata-tnc.exe", "/F"]); + spawn("Taskkill", ["/IM", "freedata-daemon.exe", "/F"]); } -}; + if (os.platform() == "linux") { + spawn("pkill", ["-9", "freedata-tnc"]); + spawn("pkill", ["-9", "freedata-daemon"]); + } - -function close_all() { - - // function for closing the application with closing all used processes - - close_sub_processes(); - - mainLog.warn('quitting app'); - - win.destroy(); - chat.destroy(); - logViewer.destroy(); - - app.quit(); + if (os.platform() == "darwin") { + spawn("pkill", ["-9", "freedata-tnc"]); + spawn("pkill", ["-9", "freedata-daemon"]); + } + } catch (e) { + mainLog.error(e); + } } +function close_all() { + // function for closing the application with closing all used processes + + close_sub_processes(); + + mainLog.warn("quitting app"); + + win.destroy(); + chat.destroy(); + logViewer.destroy(); + + app.quit(); +} // RUN RIGCTLD -ipcMain.on('request-start-rigctld',(event, data)=>{ +ipcMain.on("request-start-rigctld", (event, data) => { + try { + let rigctld_proc = spawn(data.path, data.parameters); - try{ - let rigctld_proc = spawn(data.path, data.parameters); + rigctld_proc.on("exit", function (code) { + console.log("rigctld process exited with code " + code); - rigctld_proc.on('exit', function (code) { - console.log('rigctld process exited with code ' + code); + // if rigctld crashes, error code is -2 + // then we are going to restart rigctld + // this "fixes" a problem with latest rigctld on raspberry pi + //if (code == -2){ + // setTimeout(ipcRenderer.send('request-start-rigctld', data), 500); + //} + //let rigctld_proc = spawn(data.path, data.parameters); + }); + } catch (e) { + console.log(e); + } - // if rigctld crashes, error code is -2 - // then we are going to restart rigctld - // this "fixes" a problem with latest rigctld on raspberry pi - //if (code == -2){ - // setTimeout(ipcRenderer.send('request-start-rigctld', data), 500); - //} - //let rigctld_proc = spawn(data.path, data.parameters); - }); - } catch (e) { - console.log(e); - } - - /* + /* const rigctld = exec(data.path, data.parameters); rigctld.stdout.on("data", data => { console.log(`stdout: ${data}`); }); */ - - }); - // STOP RIGCTLD -ipcMain.on('request-stop-rigctld',(event,data)=>{ - mainLog.warn('closing rigctld'); - try { - - if(os.platform()=='win32' || os.platform()=='win64'){ - spawn('Taskkill', ['/IM', 'rigctld.exe', '/F']) - } - - if(os.platform()=='linux'){ - - spawn('pkill', ['-9', 'rigctld']) - - } - - if(os.platform()=='darwin'){ - - spawn('pkill', ['-9', 'rigctld']) - - } - } catch (e) { - mainLog.error(e) +ipcMain.on("request-stop-rigctld", (event, data) => { + mainLog.warn("closing rigctld"); + try { + if (os.platform() == "win32" || os.platform() == "win64") { + spawn("Taskkill", ["/IM", "rigctld.exe", "/F"]); } + + if (os.platform() == "linux") { + spawn("pkill", ["-9", "rigctld"]); + } + + if (os.platform() == "darwin") { + spawn("pkill", ["-9", "rigctld"]); + } + } catch (e) { + mainLog.error(e); + } }); - - // CHECK RIGCTLD CONNECTION // create new socket so we are not reopening every time a new one var rigctld_connection = new net.Socket(); var rigctld_connection_state = false; var rigctld_events_wired = false; -ipcMain.on('request-check-rigctld',(event, data)=>{ +ipcMain.on("request-check-rigctld", (event, data) => { + try { + let Data = { + state: "unknown", + }; - try{ - - let Data = { - state: "unknown", - }; - - if(!rigctld_connection_state){ - rigctld_connection = new net.Socket(); - rigctld_events_wired = false; - rigctld_connection.connect(data.port, data.ip) - } - - // Check if we have created a new socket object and attach listeners if not already created - if (typeof(rigctld_connection) != 'undefined' && !rigctld_events_wired) { - - rigctld_connection.on('connect', function() { - rigctld_events_wired=true; - mainLog.info("Starting rigctld event listeners"); - rigctld_connection_state = true; - Data["state"] = "connection possible - (" + data.ip + ":" + data.port + ")"; - if (win !== null && win !== '' && typeof(win) != 'undefined'){ - // try catch for being sure we have a clean app close - try{ - win.webContents.send('action-check-rigctld', Data); - } catch(e){ - console.log(e) - } - } - }) - - rigctld_connection.on('error', function() { - rigctld_connection_state = false; - Data["state"] = "unknown/stopped - (" + data.ip + ":" + data.port + ")"; - if (win !== null && win !== '' && typeof(win) != 'undefined'){ - // try catch for being sure we have a clean app close - try{ - win.webContents.send('action-check-rigctld', Data); - } catch(e){ - console.log(e) - } - } - }) - - rigctld_connection.on('end', function() { - rigctld_connection_state = false; - }) - - } - - } catch(e) { - console.log(e) + if (!rigctld_connection_state) { + rigctld_connection = new net.Socket(); + rigctld_events_wired = false; + rigctld_connection.connect(data.port, data.ip); } -}); \ No newline at end of file + // Check if we have created a new socket object and attach listeners if not already created + if (typeof rigctld_connection != "undefined" && !rigctld_events_wired) { + rigctld_connection.on("connect", function () { + rigctld_events_wired = true; + mainLog.info("Starting rigctld event listeners"); + rigctld_connection_state = true; + Data["state"] = + "connection possible - (" + data.ip + ":" + data.port + ")"; + if (win !== null && win !== "" && typeof win != "undefined") { + // try catch for being sure we have a clean app close + try { + win.webContents.send("action-check-rigctld", Data); + } catch (e) { + console.log(e); + } + } + }); + + rigctld_connection.on("error", function () { + rigctld_connection_state = false; + Data["state"] = "unknown/stopped - (" + data.ip + ":" + data.port + ")"; + if (win !== null && win !== "" && typeof win != "undefined") { + // try catch for being sure we have a clean app close + try { + win.webContents.send("action-check-rigctld", Data); + } catch (e) { + console.log(e); + } + } + }); + + rigctld_connection.on("end", function () { + rigctld_connection_state = false; + }); + } + } catch (e) { + console.log(e); + } +}); diff --git a/gui/package.json b/gui/package.json index 5790edc0..cfce9425 100644 --- a/gui/package.json +++ b/gui/package.json @@ -1,6 +1,6 @@ { "name": "FreeDATA", - "version": "0.7.2-alpha.2", + "version": "0.7.3-alpha.2", "description": "FreeDATA ", "main": "main.js", "scripts": { @@ -35,28 +35,28 @@ "bootstrap": "^5.2.3", "bootstrap-icons": "^1.10.3", "bootswatch": "^5.2.3", - "chart.js": "^4.2.0", + "chart.js": "^4.2.1", "chartjs-plugin-annotation": "^2.1.2", "electron-log": "^4.4.8", "electron-updater": "^5.3.0", - "emoji-picker-element": "^1.15.0", + "emoji-picker-element": "^1.15.1", "emoji-picker-element-data": "^1.3.0", "express-pouchdb": "^4.2.0", "mime": "^3.0.0", - "pouchdb": "^8.0.0", - "pouchdb-browser": "^8.0.0", + "pouchdb": "^8.0.1", + "pouchdb-browser": "^8.0.1", "pouchdb-express-router": "^0.0.11", - "pouchdb-find": "^8.0.0", - "pouchdb-replication": "^8.0.0", + "pouchdb-find": "^8.0.1", + "pouchdb-replication": "^8.0.1", "qth-locator": "^2.1.0", "utf8": "^3.0.0", "uuid": "^9.0.0" }, "devDependencies": { - "electron": "^22.0.2", + "electron": "^23.0.0", "electron-builder": "^23.6.0", "@electron/notarize": "^1.2.3", - "electron-builder-notarize": "^1.5.0" + "electron-builder-notarize": "^1.5.1" }, "build": { "productName": "FreeDATA", diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 7a969a99..22cb979e 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -1,64 +1,65 @@ -const path = require('path') -const { - ipcRenderer -} = require('electron') -const { - v4: uuidv4 -} = require('uuid'); +const path = require("path"); +const { ipcRenderer } = require("electron"); +const { v4: uuidv4 } = require("uuid"); // https://stackoverflow.com/a/26227660 -var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config") +var appDataFolder = + process.env.APPDATA || + (process.platform == "darwin" + ? process.env.HOME + "/Library/Application Support" + : process.env.HOME + "/.config"); var configFolder = path.join(appDataFolder, "FreeDATA"); -var configPath = path.join(configFolder, 'config.json') +var configPath = path.join(configFolder, "config.json"); const config = require(configPath); // set date format -const dateFormat = new Intl.DateTimeFormat('en-GB', { - timeStyle: 'long', - dateStyle: 'full' +const dateFormat = new Intl.DateTimeFormat("en-GB", { + timeStyle: "long", + dateStyle: "full", }); // set date format information -const dateFormatShort = new Intl.DateTimeFormat('en-GB', { - year: 'numeric', - month: 'numeric', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - second: 'numeric', - hour12: false, +const dateFormatShort = new Intl.DateTimeFormat("en-GB", { + year: "numeric", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + hour12: false, }); -const dateFormatHours = new Intl.DateTimeFormat('en-GB', { - hour: 'numeric', - minute: 'numeric', - hour12: false, +const dateFormatHours = new Intl.DateTimeFormat("en-GB", { + hour: "numeric", + minute: "numeric", + hour12: false, }); // split character -const split_char = '\0;\1;' +const split_char = "\0;\1;"; // global for our selected file we want to transmit // ----------------- some chat globals -var filetype = ''; -var file = ''; -var filename = ''; +var filetype = ""; +var file = ""; +var filename = ""; var callsign_counter = 0; -var selected_callsign = ''; +var selected_callsign = ""; +var lastIsWritingBroadcast = new Date().getTime(); // ----------------------------------- -var chatDB = path.join(configFolder, 'chatDB') +var chatDB = path.join(configFolder, "chatDB"); // ---- MessageDB -try{ - var PouchDB = require('pouchdb'); -} catch(err){ - console.log(err); +try { + var PouchDB = require("pouchdb"); +} catch (err) { + console.log(err); - /* + /* This is a fix for raspberryPi where we get an error when loading pouchdb because of leveldown package isnt running on ARM devices. pouchdb-browser does not depend on leveldb and seems to be working. */ - console.log("using pouchdb-browser fallback") - var PouchDB = require('pouchdb-browser'); + console.log("using pouchdb-browser fallback"); + var PouchDB = require("pouchdb-browser"); } -PouchDB.plugin(require('pouchdb-find')); +PouchDB.plugin(require("pouchdb-find")); //PouchDB.plugin(require('pouchdb-replication')); var db = new PouchDB(chatDB); @@ -107,449 +108,534 @@ db.sync('http://172.20.10.4:5984/jojo', { var dxcallsigns = new Set(); db.createIndex({ - index: { - fields: ['timestamp', 'uuid', 'dxcallsign', 'dxgrid', 'msg', 'checksum', 'type', 'command', 'status', 'percent', 'bytesperminute', '_attachments'] - } -}).then(function(result) { + index: { + fields: [ + "timestamp", + "uuid", + "dxcallsign", + "dxgrid", + "msg", + "checksum", + "type", + "command", + "status", + "percent", + "bytesperminute", + "_attachments", + ], + }, +}) + .then(function (result) { // handle result - console.log(result) -}).catch(function(err) { + console.log(result); + }) + .catch(function (err) { console.log(err); -}); + }); db.find({ - selector: { - timestamp: { - $exists: true - } + selector: { + timestamp: { + $exists: true, }, - sort: [{ - 'timestamp': 'asc' - }] -}).then(function(result) { + }, + sort: [ + { + timestamp: "asc", + }, + ], +}) + .then(function (result) { // handle result - if (typeof(result) !== 'undefined') { - result.docs.forEach(function(item) { - //console.log(item) - // another query with attachments - db.get(item._id, { - attachments: true - }).then(function(item_with_attachments){ - update_chat(item_with_attachments); - }); - - - + if (typeof result !== "undefined") { + result.docs.forEach(function (item) { + //console.log(item) + // another query with attachments + db.get(item._id, { + attachments: true, + }).then(function (item_with_attachments) { + update_chat(item_with_attachments); }); + }); } -}).catch(function(err) { + }) + .catch(function (err) { console.log(err); -}); + }); // WINDOW LISTENER -window.addEventListener('DOMContentLoaded', () => { +window.addEventListener("DOMContentLoaded", () => { + // theme selector + if (config.theme != "default") { + var theme_path = + "../node_modules/bootswatch/dist/" + config.theme + "/bootstrap.min.css"; + document.getElementById("bootstrap_theme").href = theme_path; + } else { + var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; + document.getElementById("bootstrap_theme").href = theme_path; + } + document + .querySelector("emoji-picker") + .addEventListener("emoji-click", (event) => { + var msg = document.getElementById("chatModuleMessage"); + //Convert to utf-8--so we can just use utf-8 everywhere + msg.setRangeText(event.detail.emoji.unicode.toString("utf-8")); + //console.log(event.detail); + //msg.focus(); + }); + document.getElementById("emojipickerbutton").addEventListener("click", () => { + var element = document.getElementById("emojipickercontainer"); + console.log(element.style.display); + if (element.style.display === "none") { + element.style.display = "block"; + } else { + element.style.display = "none"; + } + }); + document + .getElementById("delete_selected_chat") + .addEventListener("click", () => { + db.find({ + selector: { + dxcallsign: selected_callsign, + }, + }) + .then(function (result) { + // handle result + if (typeof result !== "undefined") { + result.docs.forEach(function (item) { + console.log(item); + db.get(item._id) + .then(function (doc) { + db.remove(doc) + .then(function (doc) { + return location.reload(); + }) + .catch(function (err) { + console.log(err); + }); + }) + .catch(function (err) { + console.log(err); + }); + }); + } + }) + .catch(function (err) { + console.log(err); + }); + }); + document.getElementById("selectFilesButton").addEventListener("click", () => { + //document.getElementById('selectFiles').click(); + ipcRenderer.send("select-file", { + title: "Title", + }); + }); - // theme selector - if(config.theme != 'default'){ - var theme_path = "../node_modules/bootswatch/dist/"+ config.theme +"/bootstrap.min.css"; - document.getElementById("bootstrap_theme").href = theme_path; - } else { - var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; - document.getElementById("bootstrap_theme").href = theme_path; + document.getElementById("ping").addEventListener("click", () => { + ipcRenderer.send("run-tnc-command", { + command: "ping", + dxcallsign: selected_callsign, + }); + }); + + document.addEventListener("keyup", function (event) { + // Number 13 == Enter + if (event.keyCode === 13 && !event.shiftKey) { + // Cancel the default action, if needed + event.preventDefault(); + // Trigger the button element with a click + document.getElementById("sendMessage").click(); + } + }); + + // ADJUST TEXTAREA SIZE + document.getElementById("chatModuleMessage").addEventListener("input", () => { + var textarea = document.getElementById("chatModuleMessage"); + var text = textarea.value; + + if (document.getElementById("expand_textarea").checked) { + var lines = 6; + } else { + var lines = text.split("\n").length; + + if (lines >= 6) { + lines = 6; + } + } + var message_container_height_offset = 130 + 20 * lines; + var message_container_height = `calc(100% - ${message_container_height_offset}px)`; + document.getElementById("message-container").style.height = + message_container_height; + textarea.rows = lines; + + console.log(textarea.value); + if (lastIsWritingBroadcast < new Date().getTime() - 5 * 1000) { + //console.log("Sending FECIsWriting"); + console.log(config.enable_is_writing); + if (config.enable_is_writing == "True") { + ipcRenderer.send("tnc-fec-iswriting"); + } + lastIsWritingBroadcast = new Date().getTime(); + } + }); + + document.getElementById("expand_textarea").addEventListener("click", () => { + var textarea = document.getElementById("chatModuleMessage"); + + if (document.getElementById("expand_textarea").checked) { + var lines = 6; + document.getElementById("expand_textarea_button").className = + "bi bi-chevron-compact-down"; + } else { + var lines = 1; + document.getElementById("expand_textarea_button").className = + "bi bi-chevron-compact-up"; } + var message_container_height_offset = 130 + 20 * lines; + //var message_container_height_offset = 90 + (23*lines); + var message_container_height = `calc(100% - ${message_container_height_offset}px)`; + document.getElementById("message-container").style.height = + message_container_height; + textarea.rows = lines; + console.log(textarea.rows); + }); - document.querySelector('emoji-picker').addEventListener("emoji-click", (event) => { - var msg = document.getElementById('chatModuleMessage'); - //Convert to utf-8--so we can just use utf-8 everywhere - msg.setRangeText(event.detail.emoji.unicode.toString('utf-8')); - //console.log(event.detail); - //msg.focus(); - }) - document.getElementById("emojipickerbutton").addEventListener("click", () => { - var element = document.getElementById("emojipickercontainer") - console.log(element.style.display); - if (element.style.display === "none") { - element.style.display = "block"; - } else { - element.style.display = "none"; - } - }) - document.getElementById("delete_selected_chat").addEventListener("click", () => { - db.find({ - selector: { - dxcallsign: selected_callsign - } - }).then(function(result) { - // handle result - if (typeof(result) !== 'undefined') { - result.docs.forEach(function(item) { - console.log(item) - db.get(item._id).then(function(doc) { - db.remove(doc).then(function(doc) { - return location.reload(); - }).catch(function(err) { - console.log(err); - }); - }).catch(function(err) { - console.log(err); - }); + // NEW CHAT - }); - } - }).catch(function(err) { - console.log(err); + document + .getElementById("createNewChatButton") + .addEventListener("click", () => { + var dxcallsign = document.getElementById("chatModuleNewDxCall").value; + var uuid = uuidv4(); + db.post({ + _id: uuid, + timestamp: Math.floor(Date.now() / 1000), + dxcallsign: dxcallsign.toUpperCase(), + dxgrid: "---", + msg: "null", + checksum: "null", + type: "newchat", + status: "null", + uuid: uuid, + }) + .then(function (response) { + // handle response + console.log("new database entry"); + console.log(response); + }) + .catch(function (err) { + console.log(err); }); - }) - document.getElementById("selectFilesButton").addEventListener("click", () => { - //document.getElementById('selectFiles').click(); - ipcRenderer.send('select-file', { - title: 'Title', - }); - }) - - document.getElementById("ping").addEventListener("click", () => { - ipcRenderer.send('run-tnc-command', { - command: 'ping', dxcallsign: selected_callsign - }); - }) - - - document.addEventListener("keyup", function(event) { - // Number 13 == Enter - if (event.keyCode === 13 && !event.shiftKey) { - // Cancel the default action, if needed - event.preventDefault(); - // Trigger the button element with a click - document.getElementById("sendMessage").click(); - } - }); - - // ADJUST TEXTAREA SIZE - document.getElementById("chatModuleMessage").addEventListener("input", () => { - var textarea = document.getElementById("chatModuleMessage"); - var text = textarea.value; - - if(document.getElementById("expand_textarea").checked){ - var lines = 6 - } else { - var lines = text.split("\n").length - - if (lines >= 6){ - lines = 6; - } - - } - var message_container_height_offset = 130 + (20*lines); - var message_container_height = `calc(100% - ${message_container_height_offset}px)`; - document.getElementById("message-container").style.height = message_container_height; - textarea.rows = lines; - - console.log(textarea.value) - - - }) - - document.getElementById("expand_textarea").addEventListener("click", () => { - var textarea = document.getElementById("chatModuleMessage"); - -if(document.getElementById("expand_textarea").checked){ - var lines=6 - document.getElementById("expand_textarea_button").className = "bi bi-chevron-compact-down"; - -} else { - var lines=1 - document.getElementById("expand_textarea_button").className = "bi bi-chevron-compact-up"; -} - - var message_container_height_offset = 130 + (20*lines); - //var message_container_height_offset = 90 + (23*lines); - var message_container_height = `calc(100% - ${message_container_height_offset}px)`; - document.getElementById("message-container").style.height = message_container_height; - textarea.rows = lines; - console.log(textarea.rows) - - }) - - - // NEW CHAT - - document.getElementById("createNewChatButton").addEventListener("click", () => { - var dxcallsign = document.getElementById('chatModuleNewDxCall').value; - var uuid = uuidv4() -db.post({ - - _id: uuid, - timestamp: Math.floor(Date.now() / 1000), - dxcallsign: dxcallsign.toUpperCase(), - dxgrid: '---', - msg: 'null', - checksum: 'null', - type: 'newchat', - status: 'null', - uuid: uuid - - }).then(function(response) { - // handle response - console.log("new database entry"); - console.log(response); - }).catch(function(err) { - console.log(err); - }); - update_chat_obj_by_uuid(uuid); - + update_chat_obj_by_uuid(uuid); }); - - // SEND MSG - document.getElementById("sendMessage").addEventListener("click", () => { - document.getElementById('emojipickercontainer').style.display = "none"; - - var dxcallsign = selected_callsign.toUpperCase(); - var textarea = document.getElementById('chatModuleMessage') - var chatmessage = textarea.value; - //Remove non-printable chars from begining and end of string--should save us a byte here and there - chatmessage = chatmessage.toString().trim(); - // reset textarea size - var message_container_height_offset = 150; - var message_container_height = `calc(100% - ${message_container_height_offset}px)`; - document.getElementById("message-container").style.height = message_container_height; - textarea.rows = 1 - document.getElementById("expand_textarea_button").className = "bi bi-chevron-compact-up"; - document.getElementById("expand_textarea").checked = false; - console.log(file); - console.log(filename); - console.log(filetype); - if (filetype == ''){ - filetype = 'plain/text' - } - var timestamp = Math.floor(Date.now() / 1000); + // SEND MSG + document.getElementById("sendMessage").addEventListener("click", () => { + document.getElementById("emojipickercontainer").style.display = "none"; - var file_checksum = crc32(file).toString(16).toUpperCase(); - console.log(file_checksum) - var data_with_attachment = timestamp + split_char + chatmessage + split_char + filename + split_char + filetype + split_char + file; + var dxcallsign = selected_callsign.toUpperCase(); + var textarea = document.getElementById("chatModuleMessage"); + var chatmessage = textarea.value; + //Remove non-printable chars from begining and end of string--should save us a byte here and there + chatmessage = chatmessage.toString().trim(); + // reset textarea size + var message_container_height_offset = 150; + var message_container_height = `calc(100% - ${message_container_height_offset}px)`; + document.getElementById("message-container").style.height = + message_container_height; + textarea.rows = 1; + document.getElementById("expand_textarea_button").className = + "bi bi-chevron-compact-up"; + document.getElementById("expand_textarea").checked = false; - document.getElementById('selectFilesButton').innerHTML = ``; - var uuid = uuidv4(); - let uuidlast = uuid.lastIndexOf('-'); - uuidlast +=1; - if (uuidlast > 0) - { - uuid = uuid.substring(uuidlast); - } - console.log(data_with_attachment) - let Data = { - command: "send_message", - dxcallsign: dxcallsign, - mode: 255, - frames: 1, - data: data_with_attachment, - checksum: file_checksum, - uuid: uuid - }; - ipcRenderer.send('run-tnc-command', Data); - db.post({ - _id: uuid, - timestamp: timestamp, - dxcallsign: dxcallsign, - dxgrid: 'null', - msg: chatmessage, - checksum: file_checksum, - type: "transmit", - status: 'transmit', - uuid: uuid, - _attachments: { - [filename]: { - content_type: filetype, - //data: btoa(file) - data: btoa_FD(file) - } - } - }).then(function(response) { - // handle response - console.log("new database entry"); - console.log(response); - }).catch(function(err) { - console.log(err); - }); - update_chat_obj_by_uuid(uuid); + console.log(file); + console.log(filename); + console.log(filetype); + if (filetype == "") { + filetype = "plain/text"; + } + var timestamp = Math.floor(Date.now() / 1000); - // clear input - document.getElementById('chatModuleMessage').value = '' - - // after adding file data to our attachment variable, delete it from global - filetype = ''; - file = ''; - filename = ''; - - + var file_checksum = crc32(file).toString(16).toUpperCase(); + console.log(file_checksum); + var data_with_attachment = + timestamp + + split_char + + chatmessage + + split_char + + filename + + split_char + + filetype + + split_char + + file; + + document.getElementById("selectFilesButton").innerHTML = ``; + var uuid = uuidv4(); + let uuidlast = uuid.lastIndexOf("-"); + uuidlast += 1; + if (uuidlast > 0) { + uuid = uuid.substring(uuidlast); + } + console.log(data_with_attachment); + let Data = { + command: "send_message", + dxcallsign: dxcallsign, + mode: 255, + frames: 1, + data: data_with_attachment, + checksum: file_checksum, + uuid: uuid, + }; + ipcRenderer.send("run-tnc-command", Data); + db.post({ + _id: uuid, + timestamp: timestamp, + dxcallsign: dxcallsign, + dxgrid: "null", + msg: chatmessage, + checksum: file_checksum, + type: "transmit", + status: "transmit", + uuid: uuid, + _attachments: { + [filename]: { + content_type: filetype, + //data: btoa(file) + data: btoa_FD(file), + }, + }, }) - // cleanup after transmission - filetype = ''; - file = ''; - filename = ''; -}); -ipcRenderer.on('return-selected-files', (event, arg) => { - filetype = arg.mime; - console.log(filetype) + .then(function (response) { + // handle response + console.log("new database entry"); + console.log(response); + }) + .catch(function (err) { + console.log(err); + }); + update_chat_obj_by_uuid(uuid); - file = arg.data; - filename = arg.filename; - document.getElementById('selectFilesButton').innerHTML = ` + // clear input + document.getElementById("chatModuleMessage").value = ""; + + // after adding file data to our attachment variable, delete it from global + filetype = ""; + file = ""; + filename = ""; + }); + // cleanup after transmission + filetype = ""; + file = ""; + filename = ""; +}); +ipcRenderer.on("return-selected-files", (event, arg) => { + filetype = arg.mime; + console.log(filetype); + + file = arg.data; + filename = arg.filename; + document.getElementById("selectFilesButton").innerHTML = ` New file selected `; }); -ipcRenderer.on('action-update-transmission-status', (event, arg) => { - var data = arg["data"][0] - console.log(data.status); - db.get(data.uuid, { - attachments: true - }).then(function(doc) { - return db.put({ - _id: data.uuid, - _rev: doc._rev, - timestamp: doc.timestamp, - dxcallsign: doc.dxcallsign, - dxgrid: doc.dxgrid, - msg: doc.msg, - checksum: doc.checksum, - type: "transmit", - status: data.status, - percent: data.percent, - bytesperminute: data.bytesperminute, - uuid: doc.uuid, - _attachments: doc._attachments - }); - }).then(function(response) { - update_chat_obj_by_uuid(data.uuid); - - }).catch(function(err) { - console.log(err); - console.log(data) +ipcRenderer.on("action-update-transmission-status", (event, arg) => { + var data = arg["data"][0]; + console.log(data.status); + db.get(data.uuid, { + attachments: true, + }) + .then(function (doc) { + return db.put({ + _id: data.uuid, + _rev: doc._rev, + timestamp: doc.timestamp, + dxcallsign: doc.dxcallsign, + dxgrid: doc.dxgrid, + msg: doc.msg, + checksum: doc.checksum, + type: "transmit", + status: data.status, + percent: data.percent, + bytesperminute: data.bytesperminute, + uuid: doc.uuid, + _attachments: doc._attachments, + }); + }) + .then(function (response) { + update_chat_obj_by_uuid(data.uuid); + }) + .catch(function (err) { + console.log(err); + console.log(data); }); }); -ipcRenderer.on('action-new-msg-received', (event, arg) => { - console.log(arg.data) - var new_msg = arg.data; - new_msg.forEach(function(item) { - console.log(item.status) - let obj = new Object(); - - //handle ping - if (item.ping == 'received') { - obj.timestamp = parseInt(item.timestamp); - obj.dxcallsign = item.dxcallsign; - obj.dxgrid = item.dxgrid; - obj.uuid = item.uuid; - obj.command = 'ping'; - obj.checksum = 'null'; - obj.msg = 'null'; - obj.status = item.status; - obj.snr = item.snr; - obj.type = 'ping'; - obj.filename = 'null'; - obj.filetype = 'null'; - obj.file = 'null'; - - add_obj_to_database(obj) - update_chat_obj_by_uuid(obj.uuid); - - // handle beacon - } else if (item.beacon == 'received') { - obj.timestamp = parseInt(item.timestamp); - obj.dxcallsign = item.dxcallsign; - obj.dxgrid = item.dxgrid; - obj.uuid = item.uuid; - obj.command = 'beacon'; - obj.checksum = 'null'; - obj.msg = 'null'; - obj.status = item.status; - obj.snr = item.snr; - obj.type = 'beacon'; - obj.filename = 'null'; - obj.filetype = 'null'; - obj.file = 'null'; - - add_obj_to_database(obj); - update_chat_obj_by_uuid(obj.uuid); - - - // handle ARQ transmission - } else if (item.arq == 'transmission' && item.status == 'received') { - //var encoded_data = atob(item.data); - //var encoded_data = Buffer.from(item.data,'base64').toString('utf-8'); - var encoded_data = atob_FD(item.data); - var splitted_data = encoded_data.split(split_char); - - console.log(splitted_data) - - obj.timestamp = parseInt(splitted_data[4]); - obj.dxcallsign = item.dxcallsign; - obj.dxgrid = item.dxgrid; - obj.command = splitted_data[1]; - obj.checksum = splitted_data[2]; - // convert message to unicode from utf8 because of emojis - //No, don't convert; we're already UTF-8!!!!! - obj.uuid = splitted_data[3]; - obj.msg = splitted_data[5]; - obj.status = 'null'; - obj.snr = 'null'; - obj.type = 'received'; - obj.filename = splitted_data[6]; - obj.filetype = splitted_data[7]; - //obj.file = btoa(splitted_data[8]); - obj.file = btoa_FD(splitted_data[8]); - - add_obj_to_database(obj); - update_chat_obj_by_uuid(obj.uuid); - - } - }); - //window.location = window.location; +//Render is typing message in correct chat window +ipcRenderer.on("action-show-feciswriting", (event, arg) => { + //console.log("In action-show-feciswriting"); + //console.log(arg); + let uuid = uuidv4.toString(); + let dxcallsign = arg["data"][0]["dxcallsign"]; + var new_message = ` +
+

${dxcallsign} is typing....

+ +
+ `; + var id = "chat-" + dxcallsign; + let chatwin = document.getElementById(id); + if (chatwin == undefined) { + //console.log("Element not found!!!!! :("); + return; + } + chatwin.insertAdjacentHTML("beforeend", new_message); + scrollMessagesToBottom(); + let animIcon = document.getElementById("msg-" + uuid + "-icon"); + //Remove notification after about 4.5 seconds hopefully enough time before a second notification can come in + setTimeout(function () { + animIcon.classList = "m-1 bi bi-wifi-2"; + }, 1000); + setTimeout(function () { + animIcon.classList = "m-1 bi bi-wifi"; + }, 2000); + setTimeout(function () { + animIcon.classList = "m-1 bi bi-wifi-2"; + }, 3000); + setTimeout(function () { + animIcon.classList = "m-1 bi bi-wifi-1"; + }, 4000); + setTimeout(() => { + let feciw = document.getElementById("msg-" + uuid); + feciw.remove(); + }, 4500); }); +ipcRenderer.on("action-new-msg-received", (event, arg) => { + console.log(arg.data); + var new_msg = arg.data; + new_msg.forEach(function (item) { + console.log(item.status); + let obj = new Object(); + //handle ping + if (item.ping == "received") { + obj.timestamp = parseInt(item.timestamp); + obj.dxcallsign = item.dxcallsign; + obj.dxgrid = item.dxgrid; + obj.uuid = item.uuid; + obj.command = "ping"; + obj.checksum = "null"; + obj.msg = "null"; + obj.status = item.status; + obj.snr = item.snr; + obj.type = "ping"; + obj.filename = "null"; + obj.filetype = "null"; + obj.file = "null"; + + add_obj_to_database(obj); + update_chat_obj_by_uuid(obj.uuid); + + // handle beacon + } else if (item.beacon == "received") { + obj.timestamp = parseInt(item.timestamp); + obj.dxcallsign = item.dxcallsign; + obj.dxgrid = item.dxgrid; + obj.uuid = item.uuid; + obj.command = "beacon"; + obj.checksum = "null"; + obj.msg = "null"; + obj.status = item.status; + obj.snr = item.snr; + obj.type = "beacon"; + obj.filename = "null"; + obj.filetype = "null"; + obj.file = "null"; + + add_obj_to_database(obj); + update_chat_obj_by_uuid(obj.uuid); + + // handle ARQ transmission + } else if (item.arq == "transmission" && item.status == "received") { + //var encoded_data = atob(item.data); + //var encoded_data = Buffer.from(item.data,'base64').toString('utf-8'); + var encoded_data = atob_FD(item.data); + var splitted_data = encoded_data.split(split_char); + + console.log(splitted_data); + + obj.timestamp = parseInt(splitted_data[4]); + obj.dxcallsign = item.dxcallsign; + obj.dxgrid = item.dxgrid; + obj.command = splitted_data[1]; + obj.checksum = splitted_data[2]; + // convert message to unicode from utf8 because of emojis + //No, don't convert; we're already UTF-8!!!!! + obj.uuid = splitted_data[3]; + obj.msg = splitted_data[5]; + obj.status = "null"; + obj.snr = "null"; + obj.type = "received"; + obj.filename = splitted_data[6]; + obj.filetype = splitted_data[7]; + //obj.file = btoa(splitted_data[8]); + obj.file = btoa_FD(splitted_data[8]); + + add_obj_to_database(obj); + update_chat_obj_by_uuid(obj.uuid); + } + }); + //window.location = window.location; +}); // Update chat list -update_chat = function(obj) { - var dxcallsign = obj.dxcallsign; - var timestamp = dateFormat.format(obj.timestamp * 1000); - var timestampShort = dateFormatShort.format(obj.timestamp * 1000); - var timestampHours = dateFormatHours.format(obj.timestamp * 1000); +update_chat = function (obj) { + var dxcallsign = obj.dxcallsign; + var timestamp = dateFormat.format(obj.timestamp * 1000); + var timestampShort = dateFormatShort.format(obj.timestamp * 1000); + var timestampHours = dateFormatHours.format(obj.timestamp * 1000); - var dxgrid = obj.dxgrid; - - // define shortmessage - if (obj.msg == 'null' || obj.msg == 'NULL'){ - var shortmsg = obj.type; - } else { - var shortmsg = obj.msg; - var maxlength = 30; - var shortmsg = shortmsg.length > maxlength ? shortmsg.substring(0, maxlength - 3) + "..." : shortmsg; - - } - try { - //console.log(Object.keys(obj._attachments)[0].length) - if (typeof(obj._attachments) !== 'undefined' && Object.keys(obj._attachments)[0].length > 0) { - //var filename = obj._attachments; - var filename = Object.keys(obj._attachments)[0] - var filetype = filename.split('.')[1] - var filesize = obj._attachments[filename]["length"] + " Bytes"; - if (filesize == 'undefined Bytes'){ - // get filesize of new submitted data - // not that nice.... - // we really should avoid converting back from base64 for performance reasons... - //var filesize = Math.ceil(atob(obj._attachments[filename]["data"]).length) + "Bytes"; - var filesize = Math.ceil(atob_FD(obj._attachments[filename]["data"]).length) + " Bytes"; - } + var dxgrid = obj.dxgrid; - // check if image, then display it - if(filetype == 'image/png' || filetype =="png"){ - var fileheader = ` + // define shortmessage + if (obj.msg == "null" || obj.msg == "NULL") { + var shortmsg = obj.type; + } else { + var shortmsg = obj.msg; + var maxlength = 30; + var shortmsg = + shortmsg.length > maxlength + ? shortmsg.substring(0, maxlength - 3) + "..." + : shortmsg; + } + try { + //console.log(Object.keys(obj._attachments)[0].length) + if ( + typeof obj._attachments !== "undefined" && + Object.keys(obj._attachments)[0].length > 0 + ) { + //var filename = obj._attachments; + var filename = Object.keys(obj._attachments)[0]; + var filetype = filename.split(".")[1]; + var filesize = obj._attachments[filename]["length"] + " Bytes"; + if (filesize == "undefined Bytes") { + // get filesize of new submitted data + // not that nice.... + // we really should avoid converting back from base64 for performance reasons... + //var filesize = Math.ceil(atob(obj._attachments[filename]["data"]).length) + "Bytes"; + var filesize = + Math.ceil(atob_FD(obj._attachments[filename]["data"]).length) + + " Bytes"; + } + + // check if image, then display it + if (filetype == "image/png" || filetype == "png") { + var fileheader = `

@@ -560,10 +646,8 @@ update_chat = function(obj) {


`; - - }else{ - - var fileheader = ` + } else { + var fileheader = `

${filename} @@ -573,11 +657,9 @@ update_chat = function(obj) {


`; - } + } - - - var controlarea_transmit = ` + var controlarea_transmit = `
@@ -585,40 +667,39 @@ update_chat = function(obj) { `; - var controlarea_receive = ` + var controlarea_receive = `
- `; - - } else { - var filename = ''; - var fileheader = ''; - var filetype = 'text/plain'; - var controlarea_transmit = ` + `; + } else { + var filename = ""; + var fileheader = ""; + var filetype = "text/plain"; + var controlarea_transmit = `
`; - var controlarea_receive = ''; - } - } catch (err) { - console.log("error with database parsing...") - console.log(err) + var controlarea_receive = ""; } - // CALLSIGN LIST - if (!(document.getElementById('chat-' + dxcallsign + '-list'))) { - // increment callsign counter - callsign_counter++; - if (callsign_counter == 1) { - var callsign_selected = 'active show' - //document.getElementById('chatModuleDxCall').value = dxcallsign; - selected_callsign = dxcallsign; - } - - var new_callsign = ` + } catch (err) { + console.log("error with database parsing..."); + console.log(err); + } + // CALLSIGN LIST + if (!document.getElementById("chat-" + dxcallsign + "-list")) { + // increment callsign counter + callsign_counter++; + if (callsign_counter == 1) { + var callsign_selected = "active show"; + //document.getElementById('chatModuleDxCall').value = dxcallsign; + selected_callsign = dxcallsign; + } + + var new_callsign = `
@@ -635,72 +716,71 @@ update_chat = function(obj) { `; - document.getElementById('list-tab').insertAdjacentHTML("beforeend", new_callsign); - var message_area = ` + document + .getElementById("list-tab") + .insertAdjacentHTML("beforeend", new_callsign); + var message_area = `
`; - document.getElementById('nav-tabContent').insertAdjacentHTML("beforeend", message_area); - // create eventlistener for listening on clicking on a callsign - document.getElementById('chat-' + dxcallsign + '-list').addEventListener('click', function() { - //document.getElementById('chatModuleDxCall').value = dxcallsign; - selected_callsign = dxcallsign; + document + .getElementById("nav-tabContent") + .insertAdjacentHTML("beforeend", message_area); + // create eventlistener for listening on clicking on a callsign + document + .getElementById("chat-" + dxcallsign + "-list") + .addEventListener("click", function () { + //document.getElementById('chatModuleDxCall').value = dxcallsign; + selected_callsign = dxcallsign; + setTimeout(scrollMessagesToBottom, 200); + }); - setTimeout(scrollMessagesToBottom, 200); - - - - - }); - // if callsign entry already exists - update - } else { - - // gridsquare - update only on receive - if (obj.type !== 'transmit'){ - document.getElementById('chat-' + dxcallsign +'-list-dxgrid').innerHTML = dxgrid; - } - // time - document.getElementById('chat-' + dxcallsign +'-list-time').innerHTML = timestampHours; - // short message - document.getElementById('chat-' + dxcallsign +'-list-shortmsg').innerHTML = shortmsg; - - + } else { + // gridsquare - update only on receive + if (obj.type !== "transmit") { + document.getElementById("chat-" + dxcallsign + "-list-dxgrid").innerHTML = + dxgrid; } - // APPEND MESSAGES TO CALLSIGN - - if (!(document.getElementById('msg-' + obj._id))) { - if (obj.type == 'ping') { - var new_message = ` + // time + document.getElementById("chat-" + dxcallsign + "-list-time").innerHTML = + timestampHours; + // short message + document.getElementById("chat-" + dxcallsign + "-list-shortmsg").innerHTML = + shortmsg; + } + // APPEND MESSAGES TO CALLSIGN + + if (!document.getElementById("msg-" + obj._id)) { + if (obj.type == "ping") { + var new_message = `

snr: ${obj.snr} - ${timestamp}

`; - } - if (obj.type == 'beacon') { - var new_message = ` + } + if (obj.type == "beacon") { + var new_message = `

snr: ${obj.snr} - ${timestamp}

`; - } - - if (obj.type == 'newchat') { - var new_message = ` + } + + if (obj.type == "newchat") { + var new_message = `

new chat opened - ${timestamp}

`; - } - - - // CHECK FOR NEW LINE AND REPLACE WITH
- var message_html = obj.msg.replaceAll(/\n/g, "
"); - - - if (obj.type == 'received') { - var new_message = ` + } + + // CHECK FOR NEW LINE AND REPLACE WITH
+ var message_html = obj.msg.replaceAll(/\n/g, "
"); + + if (obj.type == "received") { + var new_message = `
@@ -725,25 +805,23 @@ update_chat = function(obj) {
`; - } + } - if (obj.type == 'transmit') { - - //console.log('msg-' + obj._id + '-status') + if (obj.type == "transmit") { + //console.log('msg-' + obj._id + '-status') - if (obj.status == 'failed'){ - var progressbar_bg = 'bg-danger'; - } else { - var progressbar_bg = 'bg-primary'; - } - - //Sneak in low graphics mode if so enabled for progress bars - if (config.high_graphics.toString().toUpperCase() !="TRUE") - { - progressbar_bg += " disable-effects"; - //console.log("Low graphics enabled for chat module"); - } - var new_message = ` + if (obj.status == "failed") { + var progressbar_bg = "bg-danger"; + } else { + var progressbar_bg = "bg-primary"; + } + + //Sneak in low graphics mode if so enabled for progress bars + if (config.high_graphics.toString().toUpperCase() != "TRUE") { + progressbar_bg += " disable-effects"; + //console.log("Low graphics enabled for chat module"); + } + var new_message = `
@@ -752,7 +830,9 @@ update_chat = function(obj) {
-
+
${fileheader}
@@ -760,18 +840,30 @@ update_chat = function(obj) {

${timestamp} - - ${get_icon_for_state(obj.status)} + ${get_icon_for_state( + obj.status + )} - +

-
+
-

+

${obj.percent} % - ${obj.bytesperminute} Bpm

@@ -788,108 +880,153 @@ update_chat = function(obj) {
`; - } - // CHECK CHECK CHECK --> This could be done better - var id = "chat-" + obj.dxcallsign - document.getElementById(id).insertAdjacentHTML("beforeend", new_message); + } + // CHECK CHECK CHECK --> This could be done better + var id = "chat-" + obj.dxcallsign; + document.getElementById(id).insertAdjacentHTML("beforeend", new_message); /* UPDATE EXISTING ELEMENTS */ - } else if (document.getElementById('msg-' + obj._id)) { - console.log("element already exists......") - console.log(obj) + } else if (document.getElementById("msg-" + obj._id)) { + console.log("element already exists......"); + console.log(obj); - console.log(document.getElementById('msg-' + obj._id + '-progress').getAttribute("aria-valuenow")) - - document.getElementById('msg-' + obj._id + '-status').innerHTML = get_icon_for_state(obj.status); - - document.getElementById('msg-' + obj._id + '-progress').setAttribute("aria-valuenow", obj.percent); - document.getElementById('msg-' + obj._id + '-progress').setAttribute("style", "width:" + obj.percent + "%;"); - document.getElementById('msg-' + obj._id + '-progress-information').innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm"; + console.log( + document + .getElementById("msg-" + obj._id + "-progress") + .getAttribute("aria-valuenow") + ); - if (obj.percent >= 100){ - //document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-striped"); - document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-animated"); - document.getElementById('msg-' + obj._id + '-progress').classList.remove("bg-danger"); - document.getElementById('msg-' + obj._id + '-progress').classList.add("bg-primary"); + document.getElementById("msg-" + obj._id + "-status").innerHTML = + get_icon_for_state(obj.status); - document.getElementById('msg-' + obj._id + '-progress').innerHTML = ''; - } else { - document.getElementById('msg-' + obj._id + '-progress').classList.add("progress-bar-striped"); - document.getElementById('msg-' + obj._id + '-progress').classList.add("progress-bar-animated"); - } + document + .getElementById("msg-" + obj._id + "-progress") + .setAttribute("aria-valuenow", obj.percent); + document + .getElementById("msg-" + obj._id + "-progress") + .setAttribute("style", "width:" + obj.percent + "%;"); + document.getElementById( + "msg-" + obj._id + "-progress-information" + ).innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm"; - if (obj.status == 'failed'){ - //document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-striped"); - document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-animated"); - document.getElementById('msg-' + obj._id + '-progress').classList.remove("bg-primary"); - document.getElementById('msg-' + obj._id + '-progress').classList.add("bg-danger"); - } - - - - //document.getElementById(id).className = message_class; + if (obj.percent >= 100) { + //document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-striped"); + document + .getElementById("msg-" + obj._id + "-progress") + .classList.remove("progress-bar-animated"); + document + .getElementById("msg-" + obj._id + "-progress") + .classList.remove("bg-danger"); + document + .getElementById("msg-" + obj._id + "-progress") + .classList.add("bg-primary"); + + document.getElementById("msg-" + obj._id + "-progress").innerHTML = ""; + } else { + document + .getElementById("msg-" + obj._id + "-progress") + .classList.add("progress-bar-striped"); + document + .getElementById("msg-" + obj._id + "-progress") + .classList.add("progress-bar-animated"); } - - - - - // CREATE SAVE TO FOLDER EVENT LISTENER - if (document.getElementById('save-file-msg-' + obj._id) && !document.getElementById('save-file-msg-' + obj._id).hasAttribute('listenerOnClick')) { - - // set Attribute to determine if we already created an EventListener for this element - document.getElementById('save-file-msg-' + obj._id).setAttribute('listenerOnClick', 'true'); - - document.getElementById('save-file-msg-' + obj._id).addEventListener("click", () => { - saveFileToFolder(obj._id) - }); - - + + if (obj.status == "failed") { + //document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-striped"); + document + .getElementById("msg-" + obj._id + "-progress") + .classList.remove("progress-bar-animated"); + document + .getElementById("msg-" + obj._id + "-progress") + .classList.remove("bg-primary"); + document + .getElementById("msg-" + obj._id + "-progress") + .classList.add("bg-danger"); } - // CREATE RESEND MSG EVENT LISTENER - - // check if element exists and if we already created NOT created an event listener - if (document.getElementById('retransmit-msg-' + obj._id) && !document.getElementById('retransmit-msg-' + obj._id).hasAttribute('listenerOnClick')) { - // set Attribute to determine if we already created an EventListener for this element - document.getElementById('retransmit-msg-' + obj._id).setAttribute('listenerOnClick', 'true'); - document.getElementById('retransmit-msg-' + obj._id).addEventListener("click", () => { + //document.getElementById(id).className = message_class; + } - db.get(obj._id, { - attachments: true - }).then(function(doc) { - // handle doc - console.log(doc) + // CREATE SAVE TO FOLDER EVENT LISTENER + if ( + document.getElementById("save-file-msg-" + obj._id) && + !document + .getElementById("save-file-msg-" + obj._id) + .hasAttribute("listenerOnClick") + ) { + // set Attribute to determine if we already created an EventListener for this element + document + .getElementById("save-file-msg-" + obj._id) + .setAttribute("listenerOnClick", "true"); - var filename = Object.keys(obj._attachments)[0] - var filetype = filename.content_type + document + .getElementById("save-file-msg-" + obj._id) + .addEventListener("click", () => { + saveFileToFolder(obj._id); + }); + } + // CREATE RESEND MSG EVENT LISTENER - console.log(filename) - console.log(filetype) - var file = obj._attachments[filename].data - console.log(file) - console.log(Object.keys(obj._attachments)[0].data) - - //var file = atob(obj._attachments[filename]["data"]) - db.getAttachment(obj._id, filename).then(function(data) { - console.log(data) - //Rewrote this part to use buffers to ensure encoding is corect -- n1qm - var binaryString = atob_FD(data); - - console.log(binaryString); - var data_with_attachment = doc.timestamp + split_char + doc.msg + split_char + filename + split_char + filetype + split_char + binaryString; - let Data = { - command: "send_message", - dxcallsign: doc.dxcallsign, - mode: 255, - frames: 1, - data: data_with_attachment, - checksum: doc.checksum, - uuid: doc.uuid - }; - console.log(Data) - ipcRenderer.send('run-tnc-command', Data); - }); - /* + // check if element exists and if we already created NOT created an event listener + if ( + document.getElementById("retransmit-msg-" + obj._id) && + !document + .getElementById("retransmit-msg-" + obj._id) + .hasAttribute("listenerOnClick") + ) { + // set Attribute to determine if we already created an EventListener for this element + document + .getElementById("retransmit-msg-" + obj._id) + .setAttribute("listenerOnClick", "true"); + document + .getElementById("retransmit-msg-" + obj._id) + .addEventListener("click", () => { + db.get(obj._id, { + attachments: true, + }) + .then(function (doc) { + // handle doc + console.log(doc); + + var filename = Object.keys(obj._attachments)[0]; + var filetype = filename.content_type; + + console.log(filename); + console.log(filetype); + var file = obj._attachments[filename].data; + console.log(file); + console.log(Object.keys(obj._attachments)[0].data); + + //var file = atob(obj._attachments[filename]["data"]) + db.getAttachment(obj._id, filename).then(function (data) { + console.log(data); + //Rewrote this part to use buffers to ensure encoding is corect -- n1qm + var binaryString = atob_FD(data); + + console.log(binaryString); + var data_with_attachment = + doc.timestamp + + split_char + + doc.msg + + split_char + + filename + + split_char + + filetype + + split_char + + binaryString; + let Data = { + command: "send_message", + dxcallsign: doc.dxcallsign, + mode: 255, + frames: 1, + data: data_with_attachment, + checksum: doc.checksum, + uuid: doc.uuid, + }; + console.log(Data); + ipcRenderer.send("run-tnc-command", Data); + }); + /* // convert blob data to binary string blobUtil.blobToBinaryString(data).then(function (binaryString) { console.log(binaryString) @@ -919,124 +1056,123 @@ update_chat = function(obj) { }); }); */ - }).catch(function(err) { - console.log(err); - }); - }); - - } - //window.location = window.location - - // scroll to bottom on new message - scrollMessagesToBottom(); - -} - + }) + .catch(function (err) { + console.log(err); + }); + }); + } + //window.location = window.location + // scroll to bottom on new message + scrollMessagesToBottom(); +}; function saveFileToFolder(id) { - db.get(id, { - attachments: true - }).then(function(obj) { - console.log(obj) - console.log(Object.keys(obj._attachments)[0].content_type) - var filename = Object.keys(obj._attachments)[0] - var filetype = filename.content_type - var file = filename.data - console.log(file) - console.log(filename.data) - db.getAttachment(id, filename).then(function(data) { - // handle result - console.log(data.length) - //data = new Blob([data.buffer], { type: 'image/png' } /* (1) */) - console.log(data) - // we need to encode data because of error "an object could not be cloned" - let Data = { - file: data, - filename: filename, - filetype: filetype, - } - console.log(Data) - ipcRenderer.send('save-file-to-folder', Data); - }).catch(function(err) { - console.log(err); - return false + db.get(id, { + attachments: true, + }) + .then(function (obj) { + console.log(obj); + console.log(Object.keys(obj._attachments)[0].content_type); + var filename = Object.keys(obj._attachments)[0]; + var filetype = filename.content_type; + var file = filename.data; + console.log(file); + console.log(filename.data); + db.getAttachment(id, filename) + .then(function (data) { + // handle result + console.log(data.length); + //data = new Blob([data.buffer], { type: 'image/png' } /* (1) */) + console.log(data); + // we need to encode data because of error "an object could not be cloned" + let Data = { + file: data, + filename: filename, + filetype: filetype, + }; + console.log(Data); + ipcRenderer.send("save-file-to-folder", Data); + }) + .catch(function (err) { + console.log(err); + return false; }); - }).catch(function(err) { - console.log(err); + }) + .catch(function (err) { + console.log(err); }); } - // function for setting an ICON to the corresponding state function get_icon_for_state(state) { - if (state == 'transmit') { - var status_icon = ''; - } else if (state == 'transmitting') { - //var status_icon = ''; - var status_icon = ` + if (state == "transmit") { + var status_icon = ''; + } else if (state == "transmitting") { + //var status_icon = ''; + var status_icon = ` `; - } else if (state == 'failed') { - var status_icon = ''; - } else if (state == 'transmitted') { - var status_icon = ''; - } else { - var status_icon = ''; - } - return status_icon; + } else if (state == "failed") { + var status_icon = + ''; + } else if (state == "transmitted") { + var status_icon = ''; + } else { + var status_icon = ''; + } + return status_icon; } - - -update_chat_obj_by_uuid = function(uuid) { - db.get(uuid, { - attachments: true - }).then(function(doc) { - update_chat(doc) - //return doc - }).catch(function(err) { - console.log(err); +update_chat_obj_by_uuid = function (uuid) { + db.get(uuid, { + attachments: true, + }) + .then(function (doc) { + update_chat(doc); + //return doc + }) + .catch(function (err) { + console.log(err); }); -} +}; - -add_obj_to_database = function(obj){ - db.put({ - _id: obj.uuid, - timestamp: parseInt(obj.timestamp), - uuid: obj.uuid, - dxcallsign: obj.dxcallsign, - dxgrid: obj.dxgrid, - msg: obj.msg, - checksum: obj.checksum, - type: obj.type, - command: obj.command, - status: obj.status, - snr: obj.snr, - _attachments: { - [obj.filename]: { - content_type: obj.filetype, - data: obj.file - } - } - }).then(function(response) { - console.log("new database entry"); - console.log(response); - }).catch(function(err) { - console.log(err); +add_obj_to_database = function (obj) { + db.put({ + _id: obj.uuid, + timestamp: parseInt(obj.timestamp), + uuid: obj.uuid, + dxcallsign: obj.dxcallsign, + dxgrid: obj.dxgrid, + msg: obj.msg, + checksum: obj.checksum, + type: obj.type, + command: obj.command, + status: obj.status, + snr: obj.snr, + _attachments: { + [obj.filename]: { + content_type: obj.filetype, + data: obj.file, + }, + }, + }) + .then(function (response) { + console.log("new database entry"); + console.log(response); + }) + .catch(function (err) { + console.log(err); }); -} - +}; // Scroll to bottom of message-container function scrollMessagesToBottom() { - var messageBody = document.getElementById('message-container'); - messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight; + var messageBody = document.getElementById("message-container"); + messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight; } - - // CRC CHECKSUMS // https://stackoverflow.com/a/50579690 // crc32 calculation @@ -1044,44 +1180,42 @@ function scrollMessagesToBottom() { //var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0}; //console.log(crc32('abc').toString(16).toUpperCase()); // hex -var makeCRCTable = function(){ - var c; - var crcTable = []; - for(var n =0; n < 256; n++){ - c = n; - for(var k =0; k < 8; k++){ - c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)); - } - crcTable[n] = c; +var makeCRCTable = function () { + var c; + var crcTable = []; + for (var n = 0; n < 256; n++) { + c = n; + for (var k = 0; k < 8; k++) { + c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; } - return crcTable; -} + crcTable[n] = c; + } + return crcTable; +}; -var crc32 = function(str) { - var crcTable = window.crcTable || (window.crcTable = makeCRCTable()); - var crc = 0 ^ (-1); +var crc32 = function (str) { + var crcTable = window.crcTable || (window.crcTable = makeCRCTable()); + var crc = 0 ^ -1; - for (var i = 0; i < str.length; i++ ) { - crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF]; - } + for (var i = 0; i < str.length; i++) { + crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xff]; + } - return (crc ^ (-1)) >>> 0; + return (crc ^ -1) >>> 0; }; /** * Binary to ASCII replacement * @param {string} data in normal/usual utf-8 format * @returns base64 encoded string */ -function btoa_FD(data) -{ - return Buffer.from(data,'utf-8').toString('base64'); +function btoa_FD(data) { + return Buffer.from(data, "utf-8").toString("base64"); } /** * ASCII to Binary replacement * @param {string} data in base64 encoding * @returns utf-8 normal/usual string */ -function atob_FD(data) -{ - return Buffer.from(data,'base64').toString('utf-8'); -} \ No newline at end of file +function atob_FD(data) { + return Buffer.from(data, "base64").toString("utf-8"); +} diff --git a/gui/preload-log.js b/gui/preload-log.js index 27653f0b..c03ed70a 100644 --- a/gui/preload-log.js +++ b/gui/preload-log.js @@ -1,192 +1,186 @@ -const path = require('path'); -const {ipcRenderer} = require('electron'); +const path = require("path"); +const { ipcRenderer } = require("electron"); // https://stackoverflow.com/a/26227660 -var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config") +var appDataFolder = + process.env.APPDATA || + (process.platform == "darwin" + ? process.env.HOME + "/Library/Application Support" + : process.env.HOME + "/.config"); var configFolder = path.join(appDataFolder, "FreeDATA"); -var configPath = path.join(configFolder, 'config.json') +var configPath = path.join(configFolder, "config.json"); const config = require(configPath); - // WINDOW LISTENER -window.addEventListener('DOMContentLoaded', () => { - document.getElementById('enable_filter_info').addEventListener('click', () => { - if (document.getElementById('enable_filter_info').checked){ - display_class("table-info", true) - } else { - display_class("table-info", false) - } - }) +window.addEventListener("DOMContentLoaded", () => { + document + .getElementById("enable_filter_info") + .addEventListener("click", () => { + if (document.getElementById("enable_filter_info").checked) { + display_class("table-info", true); + } else { + display_class("table-info", false); + } + }); - document.getElementById('enable_filter_debug').addEventListener('click', () => { - if (document.getElementById('enable_filter_debug').checked){ - display_class("table-debug", true) - } else { - display_class("table-debug", false) - } - }) + document + .getElementById("enable_filter_debug") + .addEventListener("click", () => { + if (document.getElementById("enable_filter_debug").checked) { + display_class("table-debug", true); + } else { + display_class("table-debug", false); + } + }); - document.getElementById('enable_filter_warning').addEventListener('click', () => { - if (document.getElementById('enable_filter_warning').checked){ - display_class("table-warning", true) - } else { - display_class("table-warning", false) - } - }) + document + .getElementById("enable_filter_warning") + .addEventListener("click", () => { + if (document.getElementById("enable_filter_warning").checked) { + display_class("table-warning", true); + } else { + display_class("table-warning", false); + } + }); - document.getElementById('enable_filter_error').addEventListener('click', () => { - if (document.getElementById('enable_filter_error').checked){ - display_class("table-danger", true) - } else { - display_class("table-danger", false) - } - }) -}) - - -function display_class(class_name, state){ - var collection = document.getElementsByClassName(class_name); - console.log(collection) - for (let i = 0; i < collection.length; i++) { - if (state == true){ - collection[i].style.display = "table-row"; - } else { - collection[i].style.display = "None"; - } + document + .getElementById("enable_filter_error") + .addEventListener("click", () => { + if (document.getElementById("enable_filter_error").checked) { + display_class("table-danger", true); + } else { + display_class("table-danger", false); + } + }); +}); +function display_class(class_name, state) { + var collection = document.getElementsByClassName(class_name); + console.log(collection); + for (let i = 0; i < collection.length; i++) { + if (state == true) { + collection[i].style.display = "table-row"; + } else { + collection[i].style.display = "None"; } + } } -ipcRenderer.on('action-update-log', (event, arg) => { +ipcRenderer.on("action-update-log", (event, arg) => { + var entry = arg.entry; - var entry = arg.entry - - // remove ANSI characters from string, caused by color logging - // https://stackoverflow.com/a/29497680 - entry = entry.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,'') + // remove ANSI characters from string, caused by color logging + // https://stackoverflow.com/a/29497680 + entry = entry.replace( + /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, + "" + ); + var tbl = document.getElementById("log"); + var row = document.createElement("tr"); - var tbl = document.getElementById("log"); - var row = document.createElement("tr"); + var timestamp = document.createElement("td"); + var timestampText = document.createElement("span"); - var timestamp = document.createElement("td"); - var timestampText = document.createElement('span'); + //datetime = new Date(); + //timestampText.innerText = datetime.toISOString(); + timestampText.innerText = entry.slice(0, 19); + timestamp.appendChild(timestampText); - //datetime = new Date(); - //timestampText.innerText = datetime.toISOString(); - timestampText.innerText = entry.slice(0, 19); - timestamp.appendChild(timestampText); + var type = document.createElement("td"); + var typeText = document.createElement("span"); + // typeText.innerText = entry.slice(10, 30).match(/[\[](.*)[^\]]/g); + console.log(entry.match(/\[[^\]]+\]/g)); - var type = document.createElement("td"); - var typeText = document.createElement('span'); - // typeText.innerText = entry.slice(10, 30).match(/[\[](.*)[^\]]/g); - console.log(entry.match(/\[[^\]]+\]/g)) + try { + typeText.innerText = entry.match(/\[[^\]]+\]/g)[0]; + } catch (e) { + typeText.innerText = "-"; + } - try{ - typeText.innerText = entry.match(/\[[^\]]+\]/g)[0]; - } catch(e){ - typeText.innerText = '-' - } + // let res = str.match(/[\[](.*)[^\]]/g); + type.appendChild(typeText); -// let res = str.match(/[\[](.*)[^\]]/g); + var area = document.createElement("td"); + var areaText = document.createElement("span"); + //areaText.innerText = entry.slice(10, 50).match(/[\] \[](.*)[^\]]/g); + //areaText.innerText = entry.match(/\[[^\]]+\]/g)[1]; - type.appendChild(typeText); + try { + areaText.innerText = entry.match(/\[[^\]]+\]/g)[1]; + } catch (e) { + areaText.innerText = "-"; + } + area.appendChild(areaText); - var area = document.createElement("td"); - var areaText = document.createElement('span'); - //areaText.innerText = entry.slice(10, 50).match(/[\] \[](.*)[^\]]/g); - //areaText.innerText = entry.match(/\[[^\]]+\]/g)[1]; + var logEntry = document.createElement("td"); + var logEntryText = document.createElement("span"); + try { + logEntryText.innerText = entry.split("]")[2]; + } catch (e) { + logEntryText.innerText = "-"; + } + logEntry.appendChild(logEntryText); - try{ - areaText.innerText = entry.match(/\[[^\]]+\]/g)[1]; - } catch(e){ - areaText.innerText = '-' - } - area.appendChild(areaText); - - var logEntry = document.createElement("td"); - var logEntryText = document.createElement('span'); - try{logEntryText.innerText = entry.split("]")[2]; - } catch(e){ - logEntryText.innerText = "-"; - } - logEntry.appendChild(logEntryText); + row.appendChild(timestamp); + row.appendChild(type); + row.appendChild(area); + row.appendChild(logEntry); - row.appendChild(timestamp); - row.appendChild(type); - row.appendChild(area); - row.appendChild(logEntry); - - //row.classList.add("table-blablubb"); -/* + //row.classList.add("table-blablubb"); + /* if (logEntryText.innerText.includes('ALSA lib pcm')) { row.classList.add("table-secondary"); } */ - if (typeText.innerText.includes('info')) { - row.classList.add("table-info"); - } - if (typeText.innerText.includes('debug')) { - row.classList.add("table-secondary"); - } + if (typeText.innerText.includes("info")) { + row.classList.add("table-info"); + } + if (typeText.innerText.includes("debug")) { + row.classList.add("table-secondary"); + } - if (typeText.innerText.includes('warning')) { - row.classList.add("table-warning"); - } - - if (typeText.innerText.includes('error')) { - row.classList.add("table-danger"); - } + if (typeText.innerText.includes("warning")) { + row.classList.add("table-warning"); + } + if (typeText.innerText.includes("error")) { + row.classList.add("table-danger"); + } - if (document.getElementById('enable_filter_info').checked) { - row.style.display = "table-row" - display_class("table-info", true) - } else { - row.style.display = "None" - display_class("table-info", false) + if (document.getElementById("enable_filter_info").checked) { + row.style.display = "table-row"; + display_class("table-info", true); + } else { + row.style.display = "None"; + display_class("table-info", false); + } + if (document.getElementById("enable_filter_debug").checked) { + row.style.display = "table-row"; + display_class("table-secondary", true); + } else { + row.style.display = "None"; + display_class("table-secondary", false); + } + if (document.getElementById("enable_filter_warning").checked) { + row.style.display = "table-row"; + display_class("table-warning", true); + } else { + row.style.display = "None"; + display_class("table-warning", false); + } + if (document.getElementById("enable_filter_error").checked) { + row.style.display = "table-row"; + display_class("table-danger", true); + } else { + row.style.display = "None"; + display_class("table-danger", false); + } - } - if (document.getElementById('enable_filter_debug').checked) { - row.style.display = "table-row" - display_class("table-secondary", true) - } else { - row.style.display = "None" - display_class("table-secondary", false) + tbl.appendChild(row); - } - if (document.getElementById('enable_filter_warning').checked) { - row.style.display = "table-row" - display_class("table-warning", true) - } else { - row.style.display = "None" - display_class("table-warning", false) - - } - if (document.getElementById('enable_filter_error').checked) { - row.style.display = "table-row" - display_class("table-danger", true) - } else { - row.style.display = "None" - display_class("table-danger", false) - - } - - - - - - - tbl.appendChild(row); - - - - - - // scroll to bottom of page - // https://stackoverflow.com/a/11715670 - window.scrollTo(0,document.body.scrollHeight); - - -}) + // scroll to bottom of page + // https://stackoverflow.com/a/11715670 + window.scrollTo(0, document.body.scrollHeight); +}); diff --git a/gui/preload-main.js b/gui/preload-main.js index f1b2752d..a3d9e677 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -1,37 +1,70 @@ -const path = require('path'); -const {ipcRenderer, shell} = require('electron'); -const exec = require('child_process').spawn; -const sock = require('./sock.js'); -const daemon = require('./daemon.js'); -const fs = require('fs'); +const path = require("path"); +const { ipcRenderer, shell } = require("electron"); +const exec = require("child_process").spawn; +const sock = require("./sock.js"); +const daemon = require("./daemon.js"); +const fs = require("fs"); const { - locatorToLatLng, - distance, - bearingDistance, - latLngToLocator -} = require('qth-locator'); + locatorToLatLng, + distance, + bearingDistance, + latLngToLocator, +} = require("qth-locator"); -const { - v4: uuidv4 -} = require('uuid'); +const { v4: uuidv4 } = require("uuid"); -const os = require('os'); +const os = require("os"); // split character used for appending additional data to files -const split_char = '\0;'; - +const split_char = "\0;"; // https://stackoverflow.com/a/26227660 -var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config"); +var appDataFolder = + process.env.APPDATA || + (process.platform == "darwin" + ? process.env.HOME + "/Library/Application Support" + : process.env.HOME + "/.config"); var configFolder = path.join(appDataFolder, "FreeDATA"); -var configPath = path.join(configFolder, 'config.json'); +var configPath = path.join(configFolder, "config.json"); const config = require(configPath); -const contrib = ["DK5SM","DL4IAZ","DB1UJ","EI3HIB","VK5DGR","EI7IG","N2KIQ","KT4WO","DF7MH","G0HWW","N1QM"] +const contrib = [ + "DK5SM", + "DL4IAZ", + "DB1UJ", + "EI3HIB", + "VK5DGR", + "EI7IG", + "N2KIQ", + "KT4WO", + "DF7MH", + "G0HWW", + "N1QM", +]; + +//let elements = document.querySelectorAll('[id^="hamlib_"]'); // get all elements starting with... +const hamlib_elements = [ + "hamlib_deviceid", + "hamlib_deviceport", + "hamlib_stop_bits", + "hamlib_data_bits", + "hamlib_handshake", + "hamlib_serialspeed", + "hamlib_dtrstate", + "hamlib_pttprotocol", + "hamlib_ptt_port", + "hamlib_dcd", + "hamlib_rigctld_port", + "hamlib_rigctld_ip", + "hamlib_rigctld_path", + "hamlib_rigctld_server_port", + "hamlib_rigctld_custom_args", +]; // SET dbfs LEVEL GLOBAL // this is an attempt of reducing CPU LOAD // we are going to check if we have unequal values before we start calculating again -var dbfs_level_raw = 0 +var dbfs_level_raw = 0; +var noise_level_raw = 0; //Global version variable var appVer = null; @@ -39,116 +72,115 @@ var appVer = null; // START INTERVALL COMMAND EXECUTION FOR STATES //setInterval(sock.getRxBuffer, 1000); - // WINDOW LISTENER -window.addEventListener('DOMContentLoaded', () => { +window.addEventListener("DOMContentLoaded", () => { + // save frequency event listener + document.getElementById("saveFrequency").addEventListener("click", () => { + var freq = document.getElementById("newFrequency").value; + console.log(freq); + let Data = { + type: "set", + command: "frequency", + frequency: freq, + }; + ipcRenderer.send("run-tnc-command", Data); + }); - // save frequency event listener - document.getElementById("saveFrequency").addEventListener("click", () => { - var freq = document.getElementById("newFrequency").value; - console.log(freq) - let Data = { - type: "set", - command: "frequency", - frequency: freq, - }; - ipcRenderer.send('run-tnc-command', Data); - - }); - - // enter button for input field - document.getElementById("newFrequency").addEventListener("keypress", function(event) { + // enter button for input field + document + .getElementById("newFrequency") + .addEventListener("keypress", function (event) { if (event.key === "Enter") { event.preventDefault(); document.getElementById("saveFrequency").click(); } }); - // save mode event listener - document.getElementById("saveModePKTUSB").addEventListener("click", () => { - let Data = { - type: "set", - command: "mode", - mode: "PKTUSB", - }; - ipcRenderer.send('run-tnc-command', Data); + // save mode event listener + document.getElementById("saveModePKTUSB").addEventListener("click", () => { + let Data = { + type: "set", + command: "mode", + mode: "PKTUSB", + }; + ipcRenderer.send("run-tnc-command", Data); + }); + + // save mode event listener + document.getElementById("saveModeUSB").addEventListener("click", () => { + let Data = { + type: "set", + command: "mode", + mode: "USB", + }; + ipcRenderer.send("run-tnc-command", Data); + }); + + // save mode event listener + document.getElementById("saveModeLSB").addEventListener("click", () => { + let Data = { + type: "set", + command: "mode", + mode: "LSB", + }; + ipcRenderer.send("run-tnc-command", Data); + }); + + // save mode event listener + document.getElementById("saveModeAM").addEventListener("click", () => { + let Data = { + type: "set", + command: "mode", + mode: "AM", + }; + ipcRenderer.send("run-tnc-command", Data); + }); + + // save mode event listener + document.getElementById("saveModeFM").addEventListener("click", () => { + let Data = { + type: "set", + command: "mode", + mode: "FM", + }; + ipcRenderer.send("run-tnc-command", Data); + }); + + // start stop audio recording event listener + document + .getElementById("startStopRecording") + .addEventListener("click", () => { + let Data = { + type: "set", + command: "record_audio", + }; + ipcRenderer.send("run-tnc-command", Data); }); - // save mode event listener - document.getElementById("saveModeUSB").addEventListener("click", () => { - let Data = { - type: "set", - command: "mode", - mode: "USB", - }; - ipcRenderer.send('run-tnc-command', Data); - }); + document + .getElementById("received_files_folder") + .addEventListener("click", () => { + ipcRenderer.send("get-folder-path", { + title: "Title", + }); - // save mode event listener - document.getElementById("saveModeLSB").addEventListener("click", () => { - let Data = { - type: "set", - command: "mode", - mode: "LSB", - }; - ipcRenderer.send('run-tnc-command', Data); - }); - - // save mode event listener - document.getElementById("saveModeAM").addEventListener("click", () => { - let Data = { - type: "set", - command: "mode", - mode: "AM", - }; - ipcRenderer.send('run-tnc-command', Data); - }); - - // save mode event listener - document.getElementById("saveModeFM").addEventListener("click", () => { - let Data = { - type: "set", - command: "mode", - mode: "FM", - }; - ipcRenderer.send('run-tnc-command', Data); - }); - - // start stop audio recording event listener - document.getElementById("startStopRecording").addEventListener("click", () => { - let Data = { - type: "set", - command: "record_audio", - }; - ipcRenderer.send('run-tnc-command', Data); - - }); - - -document.getElementById('received_files_folder').addEventListener('click', () => { - - ipcRenderer.send('get-folder-path',{ - title: 'Title', - }); - - ipcRenderer.on('return-folder-paths',(event,data)=>{ - document.getElementById("received_files_folder").value = data.path.filePaths[0] - config.received_files_folder = data.path.filePaths[0] + ipcRenderer.on("return-folder-paths", (event, data) => { + document.getElementById("received_files_folder").value = + data.path.filePaths[0]; + config.received_files_folder = data.path.filePaths[0]; fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); }); -}) -document.getElementById('openReceivedFilesFolder').addEventListener('click', () => { - - ipcRenderer.send('open-folder',{ + document + .getElementById("openReceivedFilesFolder") + .addEventListener("click", () => { + ipcRenderer.send("open-folder", { path: config.received_files_folder, + }); }); -}) - - - -/* + /* // ENABLE BOOTSTRAP POPOVERS EVERYWHERE // https://getbootstrap.com/docs/5.0/components/popovers/#example-enable-popovers-everywhere var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')) @@ -157,2088 +189,1929 @@ document.getElementById('openReceivedFilesFolder').addEventListener('click', () }) */ - - // ENABLE TOOLTIPS EVERYWHERE - // https://getbootstrap.com/docs/5.1/components/tooltips/ - var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) - var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { - return new bootstrap.Tooltip(tooltipTriggerEl); - }) - - - // LOAD SETTINGS - document.getElementById("tnc_adress").value = config.tnc_host; - document.getElementById("tnc_port").value = config.tnc_port; - - callsign_and_ssid = config.mycall.split("-"); - callsign = callsign_and_ssid[0]; - ssid = callsign_and_ssid[1]; - - document.getElementById("myCall").value = callsign; - //document.title = document.title + ' - Call: ' + config.mycall; - updateTitle(); - - document.getElementById("myCallSSID").value = ssid; - document.getElementById("myGrid").value = config.mygrid; - - // hamlib settings - document.getElementById('hamlib_deviceid').value = config.hamlib_deviceid; - - set_setting_switch("enable_hamlib_deviceport", "hamlib_deviceport", config.enable_hamlib_deviceport) - set_setting_switch("enable_hamlib_ptt_port", "hamlib_ptt_port", config.enable_hamlib_ptt_port) - - document.getElementById('hamlib_serialspeed').value = config.hamlib_serialspeed; - set_setting_switch("enable_hamlib_serialspeed", "hamlib_serialspeed", config.enable_hamlib_serialspeed) - - document.getElementById('hamlib_pttprotocol').value = config.hamlib_pttprotocol; - set_setting_switch("enable_hamlib_pttprotocol", "hamlib_pttprotocol", config.enable_hamlib_pttprotocol) - - document.getElementById('hamlib_databits').value = config.hamlib_data_bits; - set_setting_switch("enable_hamlib_databits", "hamlib_databits", config.enable_hamlib_databits) - - document.getElementById('hamlib_stopbits').value = config.hamlib_stop_bits; - set_setting_switch("enable_hamlib_stopbits", "hamlib_stopbits", config.enable_hamlib_stopbits) - - document.getElementById('hamlib_handshake').value = config.hamlib_handshake; - set_setting_switch("enable_hamlib_handshake", "hamlib_handshake", config.enable_hamlib_handshake) - - document.getElementById('hamlib_dcd').value = config.hamlib_dcd; - set_setting_switch("enable_hamlib_dcd", "hamlib_dcd", config.enable_hamlib_dcd) - - document.getElementById('hamlib_dtrstate').value = config.hamlib_dtrstate; - set_setting_switch("enable_hamlib_dtrstate", "hamlib_dtrstate", config.enable_hamlib_dtrstate) - - - - - - document.getElementById("hamlib_rigctld_ip").value = config.hamlib_rigctld_ip; - document.getElementById("hamlib_rigctld_port").value = config.hamlib_rigctld_port; - document.getElementById("hamlib_rigctld_path").value = config.hamlib_rigctld_path; - document.getElementById("hamlib_rigctld_server_port").value = config.hamlib_rigctld_server_port; - - - - document.getElementById("beaconInterval").value = config.beacon_interval; - - document.getElementById("scatterSwitch").value = config.enable_scatter; - document.getElementById("fftSwitch").value = config.enable_fft; - - - - document.getElementById("received_files_folder").value = config.received_files_folder; - - if(config.enable_scatter == 'True'){ - document.getElementById("scatterSwitch").checked = true; - } else { - document.getElementById("scatterSwitch").checked = false; - } - - if(config.enable_fft == 'True'){ - document.getElementById("fftSwitch").checked = true; - } else { - document.getElementById("fftSwitch").checked = false; - } - - if(config.low_bandwidth_mode == 'True'){ - document.getElementById("500HzModeSwitch").checked = true; - } else { - document.getElementById("500HzModeSwitch").checked = false; - } - - if(config.high_graphics == 'True'){ - document.getElementById("GraphicsSwitch").checked = true; - } else { - document.getElementById("GraphicsSwitch").checked = false; - } - - if(config.enable_fsk == 'True'){ - document.getElementById("fskModeSwitch").checked = true; - } else { - document.getElementById("fskModeSwitch").checked = false; - } - - if(config.respond_to_cq == 'True'){ - document.getElementById("respondCQSwitch").checked = true; - } else { - document.getElementById("respondCQSwitch").checked = false; - } - - if(config.enable_explorer == 'True'){ - document.getElementById("ExplorerSwitch").checked = true; - } else { - document.getElementById("ExplorerSwitch").checked = false; - } - - if (config.explorer_stats.toLowerCase() == 'true') { - document.getElementById("ExplorerStatsSwitch").checked=true; - } else { - document.getElementById("ExplorerStatsSwitch").checked=false; - } - - - if(config.auto_tune == 'True'){ - document.getElementById("autoTuneSwitch").checked = true; - } else { - document.getElementById("autoTuneSwitch").checked = false; - } - // theme selector - - if(config.theme != 'default'){ - var theme_path = "../node_modules/bootswatch/dist/"+ config.theme +"/bootstrap.min.css"; - document.getElementById("theme_selector").value = config.theme; - document.getElementById("bootstrap_theme").href = escape(theme_path); - } else { - var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; - document.getElementById("theme_selector").value = 'default'; - document.getElementById("bootstrap_theme").href = escape(theme_path); - } - - - // Update channel selector - document.getElementById("update_channel_selector").value = config.update_channel; - document.getElementById("updater_channel").innerHTML = escape(config.update_channel); - - // Update tuning range fmin fmax - document.getElementById("tuning_range_fmin").value = config.tuning_range_fmin; - document.getElementById("tuning_range_fmax").value = config.tuning_range_fmax; - - - // Update TX Audio Level - document.getElementById("audioLevelTXvalue").innerHTML = parseInt(config.tx_audio_level); - document.getElementById("audioLevelTX").value = parseInt(config.tx_audio_level); - - // Update RX Buffer Size - document.getElementById("rx_buffer_size").value = config.rx_buffer_size; - - if (config.spectrum == 'waterfall') { - document.getElementById("waterfall-scatter-switch1").checked = true; - document.getElementById("waterfall-scatter-switch2").checked = false; - document.getElementById("waterfall-scatter-switch3").checked = false; - - document.getElementById("waterfall").style.visibility = 'visible'; - document.getElementById("waterfall").style.height = '100%'; - document.getElementById("waterfall").style.display = 'block'; - - document.getElementById("scatter").style.height = '0px'; - document.getElementById("scatter").style.visibility = 'hidden'; - document.getElementById("scatter").style.display = 'none'; - - document.getElementById("chart").style.height = '0px'; - document.getElementById("chart").style.visibility = 'hidden'; - document.getElementById("chart").style.display = 'none'; - - } else if (config.spectrum == 'scatter'){ - - document.getElementById("waterfall-scatter-switch1").checked = false; - document.getElementById("waterfall-scatter-switch2").checked = true; - document.getElementById("waterfall-scatter-switch3").checked = false; - - document.getElementById("waterfall").style.visibility = 'hidden'; - document.getElementById("waterfall").style.height = '0px'; - document.getElementById("waterfall").style.display = 'none'; - - - document.getElementById("scatter").style.height = '100%'; - document.getElementById("scatter").style.visibility = 'visible'; - document.getElementById("scatter").style.display = 'block'; - - document.getElementById("chart").style.visibility = 'hidden'; - document.getElementById("chart").style.height = '0px'; - document.getElementById("chart").style.display = 'none'; - - } else { - - document.getElementById("waterfall-scatter-switch1").checked = false; - document.getElementById("waterfall-scatter-switch2").checked = false; - document.getElementById("waterfall-scatter-switch3").checked = true; - - document.getElementById("waterfall").style.visibility = 'hidden'; - document.getElementById("waterfall").style.height = '0px'; - document.getElementById("waterfall").style.display = 'none'; - - document.getElementById("scatter").style.height = '0px'; - document.getElementById("scatter").style.visibility = 'hidden'; - document.getElementById("scatter").style.display = 'none'; - - document.getElementById("chart").style.visibility = 'visible'; - document.getElementById("chart").style.height = '100%'; - document.getElementById("chart").style.display = 'block'; - - } - - // radio control element - if (config.radiocontrol == 'rigctld') { - - document.getElementById("radio-control-switch-disabled").checked = false; - document.getElementById("radio-control-switch-radio").checked = true; - document.getElementById("radio-control-switch-connect").checked = false; - document.getElementById("radio-control-switch-network").checked = false; - - document.getElementById("radio-control-disabled").style.visibility = 'hidden'; - document.getElementById("radio-control-disabled").style.display = 'none'; - - document.getElementById("radio-control-radio").style.visibility = 'visible'; - document.getElementById("radio-control-radio").style.display = '100%'; - - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; - - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; - - document.getElementById("radio-control-network").style.visibility = 'hidden'; - document.getElementById("radio-control-network").style.display = 'none'; - - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; - } else { - - document.getElementById("radio-control-switch-disabled").checked = true; - document.getElementById("radio-control-switch-radio").checked = false; - document.getElementById("radio-control-switch-connect").checked = false; - document.getElementById("radio-control-switch-network").checked = false; - document.getElementById("radio-control-switch-rigctld").checked = false; - document.getElementById("radio-control-switch-rigctld-info").checked = false; - - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; - - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; - - document.getElementById("radio-control-network").style.display = 'none'; - document.getElementById("radio-control-network").style.visibility = 'hidden'; - - document.getElementById("radio-control-radio").style.display = 'none'; - document.getElementById("radio-control-radio").style.visibility = 'hidden'; - - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; - - } - - // remote tnc - if (config.tnclocation == 'remote') { - document.getElementById("local-remote-switch1").checked = false; - document.getElementById("local-remote-switch2").checked = true; - document.getElementById("remote-tnc-field").style.visibility = 'visible'; - toggleClass("remote-tnc-field",'d-none',false); - } else { - document.getElementById("local-remote-switch1").checked = true; - document.getElementById("local-remote-switch2").checked = false; - document.getElementById("remote-tnc-field").style.visibility = 'hidden'; - toggleClass("remote-tnc-field",'d-none',true); - } - - // Create spectrum object on canvas with ID "waterfall" - global.spectrum = new Spectrum( - "waterfall", { - spectrumPercent: 0, - wf_rows: 192 //Assuming 1 row = 1 pixe1, 192 is the height of the spectrum container - }); - - //Set waterfalltheme - document.getElementById("wftheme_selector").value = config.wftheme; - spectrum.setColorMap(config.wftheme); - - document.getElementById("btnAbout").addEventListener("click", () => { - document.getElementById('aboutVersion').innerText=appVer; - let maxcol=3; - let col =2; - let shuffled = contrib - .map(value => ({ value, sort: Math.random() })) - .sort((a, b) => a.sort - b.sort) - .map(({ value }) => value) - let list ="
  • DJ2LS
  • "; - let list2=""; - let list3=""; - shuffled.forEach(element => { - switch (col) { - case 1: - list +="
  • " +element + "
  • " - break; - case 2: - list2 +="
  • " +element + "
  • " - break; - case 3: - list3 +="
  • " +element + "
  • " - break; - } - col=col + 1; - if (col > maxcol ) { - col=1; - } - }); - //list+=""; - divContrib.innerHTML="
      " + list + "
    "; - divContrib2.innerHTML="
      " + list2 + "
    "; - divContrib3.innerHTML="
      " + list3 + "
    "; - //console.log(shuffled) + // ENABLE TOOLTIPS EVERYWHERE + // https://getbootstrap.com/docs/5.1/components/tooltips/ + var tooltipTriggerList = [].slice.call( + document.querySelectorAll('[data-bs-toggle="tooltip"]') + ); + var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { + return new bootstrap.Tooltip(tooltipTriggerEl); + }); + + // LOAD SETTINGS + + // load settings by function + loadSettings(hamlib_elements); + + document.getElementById("tnc_adress").value = config.tnc_host; + document.getElementById("tnc_port").value = config.tnc_port; + + callsign_and_ssid = config.mycall.split("-"); + callsign = callsign_and_ssid[0]; + ssid = callsign_and_ssid[1]; + + document.getElementById("myCall").value = callsign; + //document.title = document.title + ' - Call: ' + config.mycall; + updateTitle(); + + document.getElementById("myCallSSID").value = ssid; + document.getElementById("myGrid").value = config.mygrid; + + // hamlib settings + document.getElementById("hamlib_deviceid").value = config.hamlib_deviceid; + + document.getElementById("hamlib_rigctld_ip").value = config.hamlib_rigctld_ip; + document.getElementById("hamlib_rigctld_port").value = + config.hamlib_rigctld_port; + document.getElementById("hamlib_rigctld_path").value = + config.hamlib_rigctld_path; + document.getElementById("hamlib_rigctld_server_port").value = + config.hamlib_rigctld_server_port; + + document.getElementById("beaconInterval").value = config.beacon_interval; + + document.getElementById("scatterSwitch").value = config.enable_scatter; + document.getElementById("fftSwitch").value = config.enable_fft; + + document.getElementById("received_files_folder").value = + config.received_files_folder; + + if (config.enable_scatter == "True") { + document.getElementById("scatterSwitch").checked = true; + } else { + document.getElementById("scatterSwitch").checked = false; + } + + if (config.enable_is_writing == "True") { + document.getElementById("enable_is_writing").checked = true; + } else { + document.getElementById("enable_is_writing").checked = false; + } + + if (config.enable_fft == "True") { + document.getElementById("fftSwitch").checked = true; + } else { + document.getElementById("fftSwitch").checked = false; + } + + if (config.low_bandwidth_mode == "True") { + document.getElementById("500HzModeSwitch").checked = true; + } else { + document.getElementById("500HzModeSwitch").checked = false; + } + + if (config.high_graphics == "True") { + document.getElementById("GraphicsSwitch").checked = true; + } else { + document.getElementById("GraphicsSwitch").checked = false; + } + + if (config.enable_fsk == "True") { + document.getElementById("fskModeSwitch").checked = true; + } else { + document.getElementById("fskModeSwitch").checked = false; + } + + if (config.respond_to_cq == "True") { + document.getElementById("respondCQSwitch").checked = true; + } else { + document.getElementById("respondCQSwitch").checked = false; + } + + if (config.enable_explorer == "True") { + document.getElementById("ExplorerSwitch").checked = true; + } else { + document.getElementById("ExplorerSwitch").checked = false; + } + + if (config.explorer_stats.toLowerCase() == "true") { + document.getElementById("ExplorerStatsSwitch").checked = true; + } else { + document.getElementById("ExplorerStatsSwitch").checked = false; + } + + if (config.auto_tune == "True") { + document.getElementById("autoTuneSwitch").checked = true; + } else { + document.getElementById("autoTuneSwitch").checked = false; + } + // theme selector + + if (config.theme != "default") { + var theme_path = + "../node_modules/bootswatch/dist/" + config.theme + "/bootstrap.min.css"; + document.getElementById("theme_selector").value = config.theme; + document.getElementById("bootstrap_theme").href = escape(theme_path); + } else { + var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; + document.getElementById("theme_selector").value = "default"; + document.getElementById("bootstrap_theme").href = escape(theme_path); + } + + // Update channel selector + document.getElementById("update_channel_selector").value = + config.update_channel; + document.getElementById("updater_channel").innerHTML = escape( + config.update_channel + ); + + // Update tuning range fmin fmax + document.getElementById("tuning_range_fmin").value = config.tuning_range_fmin; + document.getElementById("tuning_range_fmax").value = config.tuning_range_fmax; + + // Update TX Audio Level + document.getElementById("audioLevelTXvalue").innerHTML = parseInt( + config.tx_audio_level + ); + document.getElementById("audioLevelTX").value = parseInt( + config.tx_audio_level + ); + + // Update RX Buffer Size + document.getElementById("rx_buffer_size").value = config.rx_buffer_size; + + if (config.spectrum == "waterfall") { + document.getElementById("waterfall-scatter-switch1").checked = true; + document.getElementById("waterfall-scatter-switch2").checked = false; + document.getElementById("waterfall-scatter-switch3").checked = false; + + document.getElementById("waterfall").style.visibility = "visible"; + document.getElementById("waterfall").style.height = "100%"; + document.getElementById("waterfall").style.display = "block"; + + document.getElementById("scatter").style.height = "0px"; + document.getElementById("scatter").style.visibility = "hidden"; + document.getElementById("scatter").style.display = "none"; + + document.getElementById("chart").style.height = "0px"; + document.getElementById("chart").style.visibility = "hidden"; + document.getElementById("chart").style.display = "none"; + } else if (config.spectrum == "scatter") { + document.getElementById("waterfall-scatter-switch1").checked = false; + document.getElementById("waterfall-scatter-switch2").checked = true; + document.getElementById("waterfall-scatter-switch3").checked = false; + + document.getElementById("waterfall").style.visibility = "hidden"; + document.getElementById("waterfall").style.height = "0px"; + document.getElementById("waterfall").style.display = "none"; + + document.getElementById("scatter").style.height = "100%"; + document.getElementById("scatter").style.visibility = "visible"; + document.getElementById("scatter").style.display = "block"; + + document.getElementById("chart").style.visibility = "hidden"; + document.getElementById("chart").style.height = "0px"; + document.getElementById("chart").style.display = "none"; + } else { + document.getElementById("waterfall-scatter-switch1").checked = false; + document.getElementById("waterfall-scatter-switch2").checked = false; + document.getElementById("waterfall-scatter-switch3").checked = true; + + document.getElementById("waterfall").style.visibility = "hidden"; + document.getElementById("waterfall").style.height = "0px"; + document.getElementById("waterfall").style.display = "none"; + + document.getElementById("scatter").style.height = "0px"; + document.getElementById("scatter").style.visibility = "hidden"; + document.getElementById("scatter").style.display = "none"; + + document.getElementById("chart").style.visibility = "visible"; + document.getElementById("chart").style.height = "100%"; + document.getElementById("chart").style.display = "block"; + } + + // radio control element + if (config.radiocontrol == "rigctld") { + document.getElementById("radio-control-switch-disabled").checked = false; + document.getElementById("radio-control-switch-rigctld").checked = true; + document.getElementById("radio-control-switch-help").checked = false; + + document.getElementById("radio-control-disabled").style.visibility = + "hidden"; + document.getElementById("radio-control-disabled").style.display = "none"; + + document.getElementById("radio-control-help").style.visibility = "hidden"; + document.getElementById("radio-control-help").style.display = "none"; + + document.getElementById("radio-control-rigctld").style.visibility = + "visible"; + document.getElementById("radio-control-rigctld").style.display = "block"; + } else { + document.getElementById("radio-control-switch-disabled").checked = true; + document.getElementById("radio-control-switch-help").checked = false; + document.getElementById("radio-control-switch-rigctld").checked = false; + + document.getElementById("radio-control-help").style.display = "none"; + document.getElementById("radio-control-help").style.visibility = "hidden"; + + document.getElementById("radio-control-rigctld").style.visibility = + "hidden"; + document.getElementById("radio-control-rigctld").style.display = "none"; + } + + // remote tnc + if (config.tnclocation == "remote") { + document.getElementById("local-remote-switch1").checked = false; + document.getElementById("local-remote-switch2").checked = true; + document.getElementById("remote-tnc-field").style.visibility = "visible"; + toggleClass("remote-tnc-field", "d-none", false); + } else { + document.getElementById("local-remote-switch1").checked = true; + document.getElementById("local-remote-switch2").checked = false; + document.getElementById("remote-tnc-field").style.visibility = "hidden"; + toggleClass("remote-tnc-field", "d-none", true); + } + + // Create spectrum object on canvas with ID "waterfall" + global.spectrum = new Spectrum("waterfall", { + spectrumPercent: 0, + wf_rows: 192, //Assuming 1 row = 1 pixe1, 192 is the height of the spectrum container + }); + + //Set waterfalltheme + document.getElementById("wftheme_selector").value = config.wftheme; + spectrum.setColorMap(config.wftheme); + + document.getElementById("btnAbout").addEventListener("click", () => { + document.getElementById("aboutVersion").innerText = appVer; + let maxcol = 3; + let col = 2; + let shuffled = contrib + .map((value) => ({ value, sort: Math.random() })) + .sort((a, b) => a.sort - b.sort) + .map(({ value }) => value); + let list = "
  • DJ2LS
  • "; + let list2 = ""; + let list3 = ""; + shuffled.forEach((element) => { + switch (col) { + case 1: + list += "
  • " + element + "
  • "; + break; + case 2: + list2 += "
  • " + element + "
  • "; + break; + case 3: + list3 += "
  • " + element + "
  • "; + break; + } + col = col + 1; + if (col > maxcol) { + col = 1; + } + }); + //list+=""; + divContrib.innerHTML = "
      " + list + "
    "; + divContrib2.innerHTML = "
      " + list2 + "
    "; + divContrib3.innerHTML = "
      " + list3 + "
    "; + //console.log(shuffled) + }); + + // on click radio control toggle view + // disabled + document + .getElementById("radio-control-switch-disabled") + .addEventListener("click", () => { + //document.getElementById("hamlib_info_field").innerHTML = + // "Disables TNC rig control"; + + document.getElementById("radio-control-disabled").style.display = "block"; + document.getElementById("radio-control-disabled").style.visibility = + "visible"; + + document.getElementById("radio-control-help").style.display = "none"; + document.getElementById("radio-control-help").style.visibility = "hidden"; + + document.getElementById("radio-control-rigctld").style.visibility = + "hidden"; + document.getElementById("radio-control-rigctld").style.display = "none"; + + config.radiocontrol = "disabled"; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); }); - // on click radio control toggle view - // disabled - document.getElementById("radio-control-switch-disabled").addEventListener("click", () => { + // // radio settings 'network' event listener + document + .getElementById("radio-control-switch-help") + .addEventListener("click", () => { + //document.getElementById("hamlib_info_field").innerHTML = + // "Set the ip and port of a rigctld session"; - document.getElementById("hamlib_info_field").innerHTML = 'Set hamlib related settings.'; + document.getElementById("radio-control-disabled").style.display = "none"; + document.getElementById("radio-control-disabled").style.visibility = + "hidden"; - document.getElementById("radio-control-disabled").style.display = 'block'; - document.getElementById("radio-control-disabled").style.visibility = 'visible'; + document.getElementById("radio-control-help").style.display = "block"; + document.getElementById("radio-control-help").style.visibility = + "visible"; - document.getElementById("radio-control-radio").style.display = 'none'; - document.getElementById("radio-control-radio").style.visibility = 'hidden'; + document.getElementById("radio-control-rigctld").style.visibility = + "hidden"; + document.getElementById("radio-control-rigctld").style.display = "none"; - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; + config.radiocontrol = "rigctld"; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; + // // radio settings 'rigctld' event listener + document + .getElementById("radio-control-switch-rigctld") + .addEventListener("click", () => { + //document.getElementById("hamlib_info_field").innerHTML = + // "Edit your rigctld settings and start and stop rigctld ."; - document.getElementById("radio-control-network").style.display = 'none'; - document.getElementById("radio-control-network").style.visibility = 'hidden'; + document.getElementById("radio-control-disabled").style.display = "none"; + document.getElementById("radio-control-disabled").style.visibility = + "hidden"; - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; + document.getElementById("radio-control-help").style.display = "none"; + document.getElementById("radio-control-help").style.visibility = "hidden"; - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; + document.getElementById("radio-control-rigctld").style.visibility = + "visible"; + document.getElementById("radio-control-rigctld").style.display = "block"; - config.radiocontrol = 'disabled' + config.radiocontrol = "rigctld"; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + + document + .getElementById("hamlib_rigctld_path") + .addEventListener("click", () => { + ipcRenderer.send("get-file-path", { + title: "Title", + }); + + ipcRenderer.on("return-file-paths", (event, data) => { + rigctldPath = data.path.filePaths[0]; + document.getElementById("hamlib_rigctld_path").value = rigctldPath; + config.hamlib_rigctld_path = rigctldPath; fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); }); - - - // radio settings event listener - document.getElementById("radio-control-switch-radio").addEventListener("click", () => { - document.getElementById("hamlib_info_field").innerHTML = 'Select your radio by searching for the name or ID.'; + // radio settings 'hamlib_rigctld_server_port' event listener + document + .getElementById("hamlib_rigctld_server_port") + .addEventListener("change", () => { + config.hamlib_rigctld_server_port = document.getElementById( + "hamlib_rigctld_server_port" + ).value; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - document.getElementById("radio-control-disabled").style.display = 'none'; - document.getElementById("radio-control-disabled").style.visibility = 'hidden'; - - document.getElementById("radio-control-radio").style.display = 'block'; - document.getElementById("radio-control-radio").style.visibility = 'visible'; - - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; - - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; - - document.getElementById("radio-control-network").style.display = 'none'; - document.getElementById("radio-control-network").style.visibility = 'hidden'; - - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; - - config.radiocontrol = 'rigctld'; + // hamlib bulk event listener for saving settings + hamlib_elements.forEach(function (elem) { + try { + document.getElementById(elem).addEventListener("change", function () { + config[elem] = document.getElementById(elem).value; fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - // radio settings 'connection' event listener - document.getElementById("radio-control-switch-connect").addEventListener("click", () => { - - document.getElementById("hamlib_info_field").innerHTML = 'Setup the connection between rigctld and your radio'; - - document.getElementById("radio-control-disabled").style.display = 'none'; - document.getElementById("radio-control-disabled").style.visibility = 'hidden'; - - document.getElementById("radio-control-radio").style.display = 'none'; - document.getElementById("radio-control-radio").style.visibility = 'hidden'; - - document.getElementById("radio-control-connection").style.visibility = 'visible'; - document.getElementById("radio-control-connection").style.display = 'block'; - - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; - - document.getElementById("radio-control-network").style.display = 'none'; - document.getElementById("radio-control-network").style.visibility = 'hidden'; - - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; - - config.radiocontrol = 'rigctld'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // radio settings 'ptt' event listener - document.getElementById("radio-control-switch-ptt").addEventListener("click", () => { - - document.getElementById("hamlib_info_field").innerHTML = 'Set your PTT related settings.'; - - document.getElementById("radio-control-disabled").style.display = 'none'; - document.getElementById("radio-control-disabled").style.visibility = 'hidden'; - - document.getElementById("radio-control-radio").style.display = 'none'; - document.getElementById("radio-control-radio").style.visibility = 'hidden'; - - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; - - document.getElementById("radio-control-ptt").style.visibility = 'visible'; - document.getElementById("radio-control-ptt").style.display = 'block'; - - document.getElementById("radio-control-network").style.display = 'none'; - document.getElementById("radio-control-network").style.visibility = 'hidden'; - - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; - - config.radiocontrol = 'rigctld'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - // // radio settings 'network' event listener - document.getElementById("radio-control-switch-network").addEventListener("click", () => { - - document.getElementById("hamlib_info_field").innerHTML = 'Set the ip and port of a rigctld session'; - - document.getElementById("radio-control-disabled").style.display = 'none'; - document.getElementById("radio-control-disabled").style.visibility = 'hidden'; - - document.getElementById("radio-control-radio").style.display = 'none'; - document.getElementById("radio-control-radio").style.visibility = 'hidden'; - - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; - - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; - - document.getElementById("radio-control-network").style.display = 'block'; - document.getElementById("radio-control-network").style.visibility = 'visible'; - - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; - - config.radiocontrol = 'rigctld'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // // radio settings 'rigctld' event listener - document.getElementById("radio-control-switch-rigctld").addEventListener("click", () => { - - document.getElementById("hamlib_info_field").innerHTML = 'Define the rigctld path and port'; - - document.getElementById("radio-control-disabled").style.display = 'none'; - document.getElementById("radio-control-disabled").style.visibility = 'hidden'; - - document.getElementById("radio-control-radio").style.display = 'none'; - document.getElementById("radio-control-radio").style.visibility = 'hidden'; - - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; - - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; - - document.getElementById("radio-control-network").style.display = 'none'; - document.getElementById("radio-control-network").style.visibility = 'hidden'; - - document.getElementById("radio-control-rigctld").style.visibility = 'visible'; - document.getElementById("radio-control-rigctld").style.display = 'block'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld-info").style.display = 'none'; - - config.radiocontrol = 'rigctld'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // // radio settings 'rigctld' event listener - document.getElementById("radio-control-switch-rigctld-info").addEventListener("click", () => { - - document.getElementById("hamlib_info_field").innerHTML = 'Start and stop rigctld .'; - - - document.getElementById("radio-control-disabled").style.display = 'none'; - document.getElementById("radio-control-disabled").style.visibility = 'hidden'; - - document.getElementById("radio-control-radio").style.display = 'none'; - document.getElementById("radio-control-radio").style.visibility = 'hidden'; - - document.getElementById("radio-control-connection").style.visibility = 'hidden'; - document.getElementById("radio-control-connection").style.display = 'none'; - - document.getElementById("radio-control-ptt").style.visibility = 'hidden'; - document.getElementById("radio-control-ptt").style.display = 'none'; - - document.getElementById("radio-control-network").style.display = 'none'; - document.getElementById("radio-control-network").style.visibility = 'hidden'; - - document.getElementById("radio-control-rigctld").style.visibility = 'hidden'; - document.getElementById("radio-control-rigctld").style.display = 'none'; - - document.getElementById("radio-control-rigctld-info").style.visibility = 'visible'; - document.getElementById("radio-control-rigctld-info").style.display = 'block'; - - config.radiocontrol = 'rigctld'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - // radio settings 'enable hamlib deviceport' event listener - document.getElementById("enable_hamlib_deviceport").addEventListener("change", () => { - enable_setting("enable_hamlib_deviceport", "hamlib_deviceport") - }); - - // radio settings 'enable hamlib serialspeed' event listener - document.getElementById("enable_hamlib_serialspeed").addEventListener("change", () => { - enable_setting("enable_hamlib_serialspeed", "hamlib_serialspeed") - }); - - // radio settings 'enable hamlib data bits' event listener - document.getElementById("enable_hamlib_databits").addEventListener("change", () => { - enable_setting("enable_hamlib_databits", "hamlib_databits") - }); - - // radio settings 'enable hamlib stop bits' event listener - document.getElementById("enable_hamlib_stopbits").addEventListener("change", () => { - enable_setting("enable_hamlib_stopbits", "hamlib_stopbits") - }); - - // radio settings 'enable hamlib handshake' event listener - document.getElementById("enable_hamlib_handshake").addEventListener("change", () => { - enable_setting("enable_hamlib_handshake", "hamlib_handshake") - }); - - // radio settings 'enable hamlib ptt port' event listener - document.getElementById("enable_hamlib_ptt_port").addEventListener("change", () => { - enable_setting("enable_hamlib_ptt_port", "hamlib_ptt_port") - }); - - // radio settings 'enable hamlib ptt protocol' event listener - document.getElementById("enable_hamlib_pttprotocol").addEventListener("change", () => { - enable_setting("enable_hamlib_pttprotocol", "hamlib_pttprotocol") - }); - // radio settings 'enable hamlib dcd' event listener - document.getElementById("enable_hamlib_dcd").addEventListener("change", () => { - enable_setting("enable_hamlib_dcd", "hamlib_dcd") - }); - - // radio settings 'enable hamlib dtr state' event listener - document.getElementById("enable_hamlib_dtrstate").addEventListener("change", () => { - enable_setting("enable_hamlib_dtrstate", "hamlib_dtrstate") - }); - - -/* -document.getElementById('hamlib_rigctld_path').addEventListener('change', () => { -var fileList = document.getElementById("dataModalFile").files; - console.log(fileList) - -}) -*/ - -document.getElementById('hamlib_rigctld_path').addEventListener('click', () => { - - ipcRenderer.send('get-file-path',{ - title: 'Title', - }); - - ipcRenderer.on('return-file-paths',(event,data)=>{ - rigctldPath = data.path.filePaths[0] - document.getElementById("hamlib_rigctld_path").value = rigctldPath - config.hamlib_rigctld_path = rigctldPath - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - - }); -}) - - // radio settings 'hamlib_rigctld_server_port' event listener - document.getElementById("hamlib_rigctld_server_port").addEventListener("change", () => { - - - config.hamlib_rigctld_server_port = document.getElementById("hamlib_rigctld_server_port").value - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - -document.getElementById('hamlib_rigctld_start').addEventListener('click', () => { - var rigctldPath = document.getElementById("hamlib_rigctld_path").value; - - - var paramList = [] - - var hamlib_deviceid = document.getElementById("hamlib_deviceid").value; - paramList = paramList.concat('-m', hamlib_deviceid) - - // hamlib deviceport setting - if (document.getElementById('enable_hamlib_deviceport').checked){ - var hamlib_deviceport = document.getElementById("hamlib_deviceport").value; - paramList = paramList.concat('-r', hamlib_deviceport) + console.log(config); + }); + } catch (e) { + console.log(e); + console.log(elem); } + }); - // hamlib serialspeed setting - if (document.getElementById('enable_hamlib_serialspeed').checked){ - var hamlib_serialspeed = document.getElementById("hamlib_serialspeed").value; - paramList = paramList.concat('-s', hamlib_serialspeed) - } + document + .getElementById("hamlib_rigctld_start") + .addEventListener("click", () => { + var rigctldPath = document.getElementById("hamlib_rigctld_path").value; - // hamlib databits setting - if (document.getElementById('enable_hamlib_databits').checked){ - var hamlib_databits = document.getElementById("hamlib_databits").value; - paramList = paramList.concat('--set-conf=data_bits=' + hamlib_databits) - } + var paramList = []; - // hamlib stopbits setting - if (document.getElementById('enable_hamlib_stopbits').checked){ - var hamlib_stopbits = document.getElementById("hamlib_stopbits").value; - paramList = paramList.concat('--set-conf=stop_bits=' + hamlib_stopbits) - } + var hamlib_deviceid = document.getElementById("hamlib_deviceid").value; + paramList = paramList.concat("-m", hamlib_deviceid); - // hamlib handshake setting - if (document.getElementById('enable_hamlib_handshake').checked){ - var hamlib_handshake = document.getElementById("hamlib_handshake").value; - paramList = paramList.concat('--set-conf=serial_handshake=' + hamlib_handshake) - } + // hamlib deviceport setting + if (document.getElementById("hamlib_deviceport").value !== "ignore") { + var hamlib_deviceport = + document.getElementById("hamlib_deviceport").value; + paramList = paramList.concat("-r", hamlib_deviceport); + } - // hamlib dcd setting - if (document.getElementById('enable_hamlib_dcd').checked){ + // hamlib serialspeed setting + if (document.getElementById("hamlib_serialspeed").value !== "ignore") { + var hamlib_serialspeed = + document.getElementById("hamlib_serialspeed").value; + paramList = paramList.concat("-s", hamlib_serialspeed); + } + + // hamlib databits setting + if (document.getElementById("hamlib_data_bits").value !== "ignore") { + var hamlib_data_bits = + document.getElementById("hamlib_data_bits").value; + paramList = paramList.concat( + "--set-conf=data_bits=" + hamlib_data_bits + ); + } + + // hamlib stopbits setting + if (document.getElementById("hamlib_stop_bits").value !== "ignore") { + var hamlib_stop_bits = + document.getElementById("hamlib_stop_bits").value; + paramList = paramList.concat( + "--set-conf=stop_bits=" + hamlib_stop_bits + ); + } + + // hamlib handshake setting + if (document.getElementById("hamlib_handshake").value !== "ignore") { + var hamlib_handshake = + document.getElementById("hamlib_handshake").value; + paramList = paramList.concat( + "--set-conf=serial_handshake=" + hamlib_handshake + ); + } + + // hamlib dcd setting + if (document.getElementById("hamlib_dcd").value !== "ignore") { var hamlib_dcd = document.getElementById("hamlib_dcd").value; - paramList = paramList.concat('--dcd-type=' + hamlib_dcd) - } + paramList = paramList.concat("--dcd-type=" + hamlib_dcd); + } - // hamlib ptt port - if (document.getElementById('enable_hamlib_ptt_port').checked){ + // hamlib ptt port + if (document.getElementById("hamlib_ptt_port").value !== "ignore") { var hamlib_ptt_port = document.getElementById("hamlib_ptt_port").value; - paramList = paramList.concat('-p', hamlib_ptt_port) - } + paramList = paramList.concat("-p", hamlib_ptt_port); + } - // hamlib ptt type - if (document.getElementById('enable_hamlib_pttprotocol').checked){ - var hamlib_ptt_type = document.getElementById("hamlib_pttprotocol").value; - paramList = paramList.concat('--ptt-type=' + hamlib_ptt_type) - } + // hamlib ptt type + if (document.getElementById("hamlib_pttprotocol").value !== "ignore") { + var hamlib_ptt_type = + document.getElementById("hamlib_pttprotocol").value; + paramList = paramList.concat("--ptt-type=" + hamlib_ptt_type); + } - // hamlib dtr state - if (document.getElementById('enable_hamlib_dtrstate').checked){ + // hamlib dtr state + if (document.getElementById("hamlib_dtrstate").value !== "ignore") { var hamlib_dtrstate = document.getElementById("hamlib_dtrstate").value; - paramList = paramList.concat('--set-conf=dtr_state=' + hamlib_dtrstate) - } + paramList = paramList.concat("--set-conf=dtr_state=" + hamlib_dtrstate); + } + var hamlib_rigctld_server_port = document.getElementById( + "hamlib_rigctld_server_port" + ).value; + paramList = paramList.concat("-t", hamlib_rigctld_server_port); + //Custom rigctld arguments to pass to rigctld + var hamlib_rigctld_custom_args = document.getElementById( + "hamlib_rigctld_custom_args" + ).value; + paramList = paramList.concat(hamlib_rigctld_custom_args); + document.getElementById("hamlib_rigctld_command").value = + paramList.join(" "); // join removes the commas + console.log(paramList); + console.log(rigctldPath); - var hamlib_rigctld_server_port = document.getElementById("hamlib_rigctld_server_port").value; - paramList = paramList.concat('-t', hamlib_rigctld_server_port) + let Data = { + path: rigctldPath, + parameters: paramList, + }; + ipcRenderer.send("request-start-rigctld", Data); + }); + document + .getElementById("hamlib_rigctld_stop") + .addEventListener("click", () => { + ipcRenderer.send("request-stop-rigctld", { + path: "123", + parameters: "--version", + }); + }); + // on click waterfall scatter toggle view + // waterfall + document + .getElementById("waterfall-scatter-switch1") + .addEventListener("click", () => { + document.getElementById("chart").style.visibility = "hidden"; + document.getElementById("chart").style.display = "none"; + document.getElementById("chart").style.height = "0px"; + document.getElementById("scatter").style.height = "0px"; + document.getElementById("scatter").style.display = "none"; + document.getElementById("scatter").style.visibility = "hidden"; + document.getElementById("waterfall").style.display = "block"; + document.getElementById("waterfall").style.visibility = "visible"; + document.getElementById("waterfall").style.height = "100%"; - document.getElementById('hamlib_rigctld_command').value = paramList.join(" ") // join removes the commas + config.spectrum = "waterfall"; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + // scatter + document + .getElementById("waterfall-scatter-switch2") + .addEventListener("click", () => { + document.getElementById("scatter").style.display = "block"; + document.getElementById("scatter").style.visibility = "visible"; + document.getElementById("scatter").style.height = "100%"; - console.log(paramList) - console.log(rigctldPath) + document.getElementById("waterfall").style.visibility = "hidden"; + document.getElementById("waterfall").style.height = "0px"; + document.getElementById("waterfall").style.display = "none"; + + document.getElementById("chart").style.visibility = "hidden"; + document.getElementById("chart").style.height = "0px"; + document.getElementById("chart").style.display = "none"; + + config.spectrum = "scatter"; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + // chart + document + .getElementById("waterfall-scatter-switch3") + .addEventListener("click", () => { + document.getElementById("waterfall").style.visibility = "hidden"; + document.getElementById("waterfall").style.height = "0px"; + document.getElementById("waterfall").style.display = "none"; + + document.getElementById("scatter").style.height = "0px"; + document.getElementById("scatter").style.visibility = "hidden"; + document.getElementById("scatter").style.display = "none"; + + document.getElementById("chart").style.height = "100%"; + document.getElementById("chart").style.display = "block"; + document.getElementById("chart").style.visibility = "visible"; + + config.spectrum = "chart"; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + + // on click remote tnc toggle view + document + .getElementById("local-remote-switch1") + .addEventListener("click", () => { + document.getElementById("local-remote-switch1").checked = true; + document.getElementById("local-remote-switch2").checked = false; + document.getElementById("remote-tnc-field").style.visibility = "hidden"; + config.tnclocation = "localhost"; + toggleClass("remote-tnc-field", "d-none", true); + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + document + .getElementById("local-remote-switch2") + .addEventListener("click", () => { + document.getElementById("local-remote-switch1").checked = false; + document.getElementById("local-remote-switch2").checked = true; + document.getElementById("remote-tnc-field").style.visibility = "visible"; + config.tnclocation = "remote"; + toggleClass("remote-tnc-field", "d-none", false); + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + + // on change ping callsign + document.getElementById("dxCall").addEventListener("change", () => { + document.getElementById("dataModalDxCall").value = + document.getElementById("dxCall").value; + }); + // on change ping callsign + document.getElementById("dataModalDxCall").addEventListener("change", () => { + document.getElementById("dxCall").value = + document.getElementById("dataModalDxCall").value; + }); + + // on change port and host + document.getElementById("tnc_adress").addEventListener("change", () => { + console.log(document.getElementById("tnc_adress").value); + config.tnc_host = document.getElementById("tnc_adress").value; + config.daemon_host = document.getElementById("tnc_adress").value; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); let Data = { - path: rigctldPath, - parameters: paramList + port: document.getElementById("tnc_port").value, + adress: document.getElementById("tnc_adress").value, }; - ipcRenderer.send('request-start-rigctld', Data); + ipcRenderer.send("request-update-tnc-ip", Data); + Data = { + port: parseInt(document.getElementById("tnc_port").value) + 1, + adress: document.getElementById("tnc_adress").value, + }; + ipcRenderer.send("request-update-daemon-ip", Data); + }); + // on change tnc port + document.getElementById("tnc_port").addEventListener("change", () => { + config.tnc_port = document.getElementById("tnc_port").value; + config.daemon_port = + parseInt(document.getElementById("tnc_port").value) + 1; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); -}) -document.getElementById('hamlib_rigctld_stop').addEventListener('click', () => { - ipcRenderer.send('request-stop-rigctld',{ - path: '123', - parameters: '--version' + let Data = { + port: document.getElementById("tnc_port").value, + adress: document.getElementById("tnc_adress").value, + }; + ipcRenderer.send("request-update-tnc-ip", Data); + + Data = { + port: parseInt(document.getElementById("tnc_port").value) + 1, + adress: document.getElementById("tnc_adress").value, + }; + ipcRenderer.send("request-update-daemon-ip", Data); + }); + + // on change audio TX Level + document.getElementById("audioLevelTX").addEventListener("change", () => { + var tx_audio_level = parseInt( + document.getElementById("audioLevelTX").value + ); + document.getElementById("audioLevelTXvalue").innerHTML = tx_audio_level; + config.tx_audio_level = tx_audio_level; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + + let Data = { + command: "set_tx_audio_level", + tx_audio_level: tx_audio_level, + }; + ipcRenderer.send("run-tnc-command", Data); + }); + document.getElementById("sendTestFrame").addEventListener("click", () => { + let Data = { + type: "set", + command: "send_test_frame", + }; + ipcRenderer.send("run-tnc-command", Data); + }); + // saveMyCall button clicked + document.getElementById("myCall").addEventListener("input", () => { + callsign = document.getElementById("myCall").value; + ssid = document.getElementById("myCallSSID").value; + callsign_ssid = callsign.toUpperCase() + "-" + ssid; + config.mycall = callsign_ssid; + // split document title by looking for Call then split and update it + //var documentTitle = document.title.split('Call:') + //document.title = documentTitle[0] + 'Call: ' + callsign_ssid; + updateTitle(callsign_ssid); + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + daemon.saveMyCall(callsign_ssid); + }); + + // saveMyGrid button clicked + document.getElementById("myGrid").addEventListener("input", () => { + grid = document.getElementById("myGrid").value; + config.mygrid = grid; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + daemon.saveMyGrid(grid); + }); + + // startPing button clicked + document.getElementById("sendPing").addEventListener("click", () => { + var dxcallsign = document.getElementById("dxCall").value.toUpperCase(); + if (dxcallsign == "" || dxcallsign == null || dxcallsign == undefined) + return; + pauseButton(document.getElementById("sendPing"), 2000); + sock.sendPing(dxcallsign); + }); + + // dataModalstartPing button clicked + document.getElementById("dataModalSendPing").addEventListener("click", () => { + var dxcallsign = document.getElementById("dataModalDxCall").value; + dxcallsign = dxcallsign.toUpperCase(); + sock.sendPing(dxcallsign); + }); + + // close app, update and restart + document + .getElementById("update_and_install") + .addEventListener("click", () => { + ipcRenderer.send("request-restart-and-install"); }); + // open arq session + document.getElementById("openARQSession").addEventListener("click", () => { + var dxcallsign = document.getElementById("dataModalDxCall").value; + dxcallsign = dxcallsign.toUpperCase(); + sock.connectARQ(dxcallsign); + }); -}) + // close arq session + document.getElementById("closeARQSession").addEventListener("click", () => { + sock.disconnectARQ(); + }); + // sendCQ button clicked + document.getElementById("sendCQ").addEventListener("click", () => { + pauseButton(document.getElementById("sendCQ"), 2000); + sock.sendCQ(); + }); - // on click waterfall scatter toggle view - // waterfall - document.getElementById("waterfall-scatter-switch1").addEventListener("click", () => { - document.getElementById("chart").style.visibility = 'hidden'; - document.getElementById("chart").style.display = 'none'; - document.getElementById("chart").style.height = '0px'; + // Start beacon button clicked + document.getElementById("startBeacon").addEventListener("click", () => { + let bcn = document.getElementById("startBeacon"); + bcn.disabled = true; + interval = document.getElementById("beaconInterval").value; + //Use class list to determine state of beacon, secondary == off + if (bcn.className.toLowerCase().indexOf("secondary") > 0) { + //Stopped; let us start it + sock.startBeacon(interval); + } else { + sock.stopBeacon(); + } + config.beacon_interval = interval; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + bcn.disabled = false; + }); - document.getElementById("scatter").style.height = '0px'; - document.getElementById("scatter").style.display = 'none'; - document.getElementById("scatter").style.visibility = 'hidden'; + // sendscatter Switch clicked + document.getElementById("scatterSwitch").addEventListener("click", () => { + console.log(document.getElementById("scatterSwitch").checked); + if (document.getElementById("scatterSwitch").checked == true) { + config.enable_scatter = "True"; + } else { + config.enable_scatter = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - document.getElementById("waterfall").style.display = 'block'; - document.getElementById("waterfall").style.visibility = 'visible'; - document.getElementById("waterfall").style.height = '100%'; + // sendfft Switch clicked + document.getElementById("fftSwitch").addEventListener("click", () => { + if (document.getElementById("fftSwitch").checked == true) { + config.enable_fft = "True"; + } else { + config.enable_fft = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - config.spectrum = 'waterfall'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + // enable 500z Switch clicked + document.getElementById("500HzModeSwitch").addEventListener("click", () => { + if (document.getElementById("500HzModeSwitch").checked == true) { + config.low_bandwidth_mode = "True"; + } else { + config.low_bandwidth_mode = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + + // enable response to cq clicked + document.getElementById("respondCQSwitch").addEventListener("click", () => { + if (document.getElementById("respondCQSwitch").checked == true) { + config.respond_to_cq = "True"; + } else { + config.respond_to_cq = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + + // enable explorer Switch clicked + document.getElementById("ExplorerSwitch").addEventListener("click", () => { + if (document.getElementById("ExplorerSwitch").checked == true) { + config.enable_explorer = "True"; + } else { + config.enable_explorer = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + // enable explorer stats Switch clicked + document + .getElementById("ExplorerStatsSwitch") + .addEventListener("click", () => { + if (document.getElementById("ExplorerStatsSwitch").checked == true) { + config.explorer_stats = "True"; + } else { + config.explorer_stats = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); }); - // scatter - document.getElementById("waterfall-scatter-switch2").addEventListener("click", () => { - document.getElementById("scatter").style.display = 'block'; - document.getElementById("scatter").style.visibility = 'visible'; - document.getElementById("scatter").style.height = '100%'; + // enable autotune Switch clicked + document.getElementById("autoTuneSwitch").addEventListener("click", () => { + if (document.getElementById("autoTuneSwitch").checked == true) { + config.auto_tune = "True"; + } else { + config.auto_tune = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + document.getElementById("GraphicsSwitch").addEventListener("click", () => { + if (document.getElementById("GraphicsSwitch").checked == true) { + config.high_graphics = "True"; + } else { + config.high_graphics = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + set_CPU_mode(); + }); - document.getElementById("waterfall").style.visibility = 'hidden'; - document.getElementById("waterfall").style.height = '0px'; - document.getElementById("waterfall").style.display = 'none'; + // enable fsk Switch clicked + document.getElementById("fskModeSwitch").addEventListener("click", () => { + if (document.getElementById("fskModeSwitch").checked == true) { + config.enable_fsk = "True"; + } else { + config.enable_fsk = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - document.getElementById("chart").style.visibility = 'hidden'; - document.getElementById("chart").style.height = '0px'; - document.getElementById("chart").style.display = 'none'; + // enable is writing switch clicked + document.getElementById("enable_is_writing").addEventListener("click", () => { + if (document.getElementById("enable_is_writing").checked == true) { + config.enable_is_writing = "True"; + } else { + config.enable_is_writing = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - config.spectrum = 'scatter'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - // chart - document.getElementById("waterfall-scatter-switch3").addEventListener("click", () => { - document.getElementById("waterfall").style.visibility = 'hidden'; - document.getElementById("waterfall").style.height = '0px'; - document.getElementById("waterfall").style.display = 'none'; + // Tuning range clicked + document.getElementById("tuning_range_fmin").addEventListener("click", () => { + var tuning_range_fmin = document.getElementById("tuning_range_fmin").value; + config.tuning_range_fmin = tuning_range_fmin; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - document.getElementById("scatter").style.height = '0px'; - document.getElementById("scatter").style.visibility = 'hidden'; - document.getElementById("scatter").style.display = 'none'; + document.getElementById("tuning_range_fmax").addEventListener("click", () => { + var tuning_range_fmax = document.getElementById("tuning_range_fmax").value; + config.tuning_range_fmax = tuning_range_fmax; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - document.getElementById("chart").style.height = '100%'; - document.getElementById("chart").style.display = 'block'; - document.getElementById("chart").style.visibility = 'visible'; + // Theme selector clicked + document.getElementById("theme_selector").addEventListener("click", () => { + var theme = document.getElementById("theme_selector").value; + if (theme != "default") { + var theme_path = + "../node_modules/bootswatch/dist/" + theme + "/bootstrap.min.css"; + } else { + var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; + } - config.spectrum = 'chart'; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + //update path to css file + document.getElementById("bootstrap_theme").href = escape(theme_path); + + config.theme = theme; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + + // Waterfall theme selector changed + document.getElementById("wftheme_selector").addEventListener("change", () => { + var wftheme = document.getElementById("wftheme_selector").value; + spectrum.setColorMap(wftheme); + config.wftheme = wftheme; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); + + // Update channel selector changed + document + .getElementById("update_channel_selector") + .addEventListener("change", () => { + config.update_channel = document.getElementById( + "update_channel_selector" + ).value; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + console.log("Autoupdate channel changed to ", config.update_channel); }); + // rx buffer size selector clicked + document.getElementById("rx_buffer_size").addEventListener("click", () => { + var rx_buffer_size = document.getElementById("rx_buffer_size").value; + config.rx_buffer_size = rx_buffer_size; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); - // on click remote tnc toggle view - document.getElementById("local-remote-switch1").addEventListener("click", () => { - document.getElementById("local-remote-switch1").checked = true; - document.getElementById("local-remote-switch2").checked = false; - document.getElementById("remote-tnc-field").style.visibility = 'hidden'; - config.tnclocation = 'localhost'; - toggleClass("remote-tnc-field",'d-none',true); - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - document.getElementById("local-remote-switch2").addEventListener("click", () => { - document.getElementById("local-remote-switch1").checked = false; - document.getElementById("local-remote-switch2").checked = true; - document.getElementById("remote-tnc-field").style.visibility = 'visible'; - config.tnclocation = 'remote'; - toggleClass("remote-tnc-field",'d-none',false); - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - - // on change ping callsign - document.getElementById("dxCall").addEventListener("change", () => { - document.getElementById("dataModalDxCall").value = document.getElementById("dxCall").value; - }); - // on change ping callsign - document.getElementById("dataModalDxCall").addEventListener("change", () => { - document.getElementById("dxCall").value = document.getElementById("dataModalDxCall").value; - - }); - - // on change port and host - document.getElementById("tnc_adress").addEventListener("change", () => { - console.log(document.getElementById("tnc_adress").value); - config.tnc_host = document.getElementById("tnc_adress").value; - config.daemon_host = document.getElementById("tnc_adress").value; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - - let Data = { - port: document.getElementById("tnc_port").value, - adress: document.getElementById("tnc_adress").value, - }; - ipcRenderer.send('request-update-tnc-ip', Data); - - Data = { - port: parseInt(document.getElementById("tnc_port").value) + 1, - adress: document.getElementById("tnc_adress").value, - }; - ipcRenderer.send('request-update-daemon-ip', Data); - }); - - // on change tnc port - document.getElementById("tnc_port").addEventListener("change", () => { - - config.tnc_port = document.getElementById("tnc_port").value; - config.daemon_port = parseInt(document.getElementById("tnc_port").value) + 1; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - - let Data = { - port: document.getElementById("tnc_port").value, - adress: document.getElementById("tnc_adress").value, - }; - ipcRenderer.send('request-update-tnc-ip', Data); - - Data = { - port: parseInt(document.getElementById("tnc_port").value) + 1, - adress: document.getElementById("tnc_adress").value, - }; - ipcRenderer.send('request-update-daemon-ip', Data); - - }); - - // on change audio TX Level - document.getElementById("audioLevelTX").addEventListener("change", () => { - var tx_audio_level = parseInt(document.getElementById("audioLevelTX").value); - document.getElementById("audioLevelTXvalue").innerHTML = tx_audio_level; - config.tx_audio_level = tx_audio_level; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - - let Data = { - command: "set_tx_audio_level", - tx_audio_level: tx_audio_level - }; - ipcRenderer.send('run-tnc-command', Data); - - }); - document.getElementById("sendTestFrame").addEventListener("click", () => { - let Data = { - type: "set", - command: "send_test_frame" - }; - ipcRenderer.send('run-tnc-command', Data); - }); - // saveMyCall button clicked - document.getElementById("myCall").addEventListener("input", () => { - callsign = document.getElementById("myCall").value; - ssid = document.getElementById("myCallSSID").value; - callsign_ssid = callsign.toUpperCase() + '-' + ssid; - config.mycall = callsign_ssid; - // split document title by looking for Call then split and update it - //var documentTitle = document.title.split('Call:') - //document.title = documentTitle[0] + 'Call: ' + callsign_ssid; - updateTitle(callsign_ssid); - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - daemon.saveMyCall(callsign_ssid); - }); - - // saveMyGrid button clicked - document.getElementById("myGrid").addEventListener("input", () => { - grid = document.getElementById("myGrid").value; - config.mygrid = grid; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - daemon.saveMyGrid(grid); - - }); - - - // startPing button clicked - document.getElementById("sendPing").addEventListener("click", () => { - var dxcallsign = document.getElementById("dxCall").value.toUpperCase(); - if (dxcallsign == "" || dxcallsign == null || dxcallsign == undefined) - return; - pauseButton(document.getElementById("sendPing"),2000); - sock.sendPing(dxcallsign); - }); - - // dataModalstartPing button clicked - document.getElementById("dataModalSendPing").addEventListener("click", () => { - var dxcallsign = document.getElementById("dataModalDxCall").value; - dxcallsign = dxcallsign.toUpperCase(); - sock.sendPing(dxcallsign); - }); - - - - - - // close app, update and restart - document.getElementById("update_and_install").addEventListener("click", () => { - ipcRenderer.send('request-restart-and-install'); - }); - - // open arq session - document.getElementById("openARQSession").addEventListener("click", () => { - var dxcallsign = document.getElementById("dataModalDxCall").value; - dxcallsign = dxcallsign.toUpperCase(); - sock.connectARQ(dxcallsign); - }); - - // close arq session - document.getElementById("closeARQSession").addEventListener("click", () => { - sock.disconnectARQ(); - }); - - - // sendCQ button clicked - document.getElementById("sendCQ").addEventListener("click", () => { - pauseButton(document.getElementById("sendCQ"),2000); - sock.sendCQ(); - }); - - - // Start beacon button clicked - document.getElementById("startBeacon").addEventListener("click", () => { - interval = document.getElementById("beaconInterval").value; - config.beacon_interval = interval; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - sock.startBeacon(interval); - }); - - // sendscatter Switch clicked - document.getElementById("scatterSwitch").addEventListener("click", () => { - console.log(document.getElementById("scatterSwitch").checked); - if(document.getElementById("scatterSwitch").checked == true){ - config.enable_scatter = "True"; - } else { - config.enable_scatter = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // sendfft Switch clicked - document.getElementById("fftSwitch").addEventListener("click", () => { - if(document.getElementById("fftSwitch").checked == true){ - config.enable_fft = "True"; - } else { - config.enable_fft = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // enable 500z Switch clicked - document.getElementById("500HzModeSwitch").addEventListener("click", () => { - if(document.getElementById("500HzModeSwitch").checked == true){ - config.low_bandwidth_mode = "True"; - } else { - config.low_bandwidth_mode = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // enable response to cq clicked - document.getElementById("respondCQSwitch").addEventListener("click", () => { - if(document.getElementById("respondCQSwitch").checked == true){ - config.respond_to_cq = "True"; - } else { - config.respond_to_cq = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // enable explorer Switch clicked - document.getElementById("ExplorerSwitch").addEventListener("click", () => { - if(document.getElementById("ExplorerSwitch").checked == true){ - config.enable_explorer = "True"; - } else { - config.enable_explorer = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - // enable explorer stats Switch clicked - document.getElementById("ExplorerStatsSwitch").addEventListener("click", () => { - if(document.getElementById("ExplorerStatsSwitch").checked == true){ - config.explorer_stats = "True"; - } else { - config.explorer_stats = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - // enable autotune Switch clicked - document.getElementById("autoTuneSwitch").addEventListener("click", () => { - if(document.getElementById("autoTuneSwitch").checked == true){ - config.auto_tune = "True"; - } else { - config.auto_tune = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - document.getElementById("GraphicsSwitch").addEventListener("click", () => { - if(document.getElementById("GraphicsSwitch").checked == true){ - config.high_graphics = "True"; - } else { - config.high_graphics = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - set_CPU_mode(); - }); - - // enable fsk Switch clicked - document.getElementById("fskModeSwitch").addEventListener("click", () => { - if(document.getElementById("fskModeSwitch").checked == true){ - config.enable_fsk = "True"; - } else { - config.enable_fsk = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - - // Tuning range clicked - document.getElementById("tuning_range_fmin").addEventListener("click", () => { - var tuning_range_fmin = document.getElementById("tuning_range_fmin").value; - config.tuning_range_fmin = tuning_range_fmin; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - document.getElementById("tuning_range_fmax").addEventListener("click", () => { - var tuning_range_fmax = document.getElementById("tuning_range_fmax").value; - config.tuning_range_fmax = tuning_range_fmax; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - // Theme selector clicked - document.getElementById("theme_selector").addEventListener("click", () => { - - var theme = document.getElementById("theme_selector").value; - if(theme != 'default'){ - var theme_path = "../node_modules/bootswatch/dist/"+ theme +"/bootstrap.min.css"; - } else { - var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; - } - - //update path to css file - document.getElementById("bootstrap_theme").href = escape(theme_path) - - config.theme = theme; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - - }); - - // Waterfall theme selector changed - document.getElementById("wftheme_selector").addEventListener("change", () => { - var wftheme = document.getElementById("wftheme_selector").value; - spectrum.setColorMap(wftheme); - config.wftheme = wftheme; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - // Update channel selector changed - document.getElementById("update_channel_selector").addEventListener("change", () => { - config.update_channel = document.getElementById("update_channel_selector").value; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - console.log("Autoupdate channel changed to ", config.update_channel); - }); - - // rx buffer size selector clicked - document.getElementById("rx_buffer_size").addEventListener("click", () => { - var rx_buffer_size = document.getElementById("rx_buffer_size").value; - config.rx_buffer_size = rx_buffer_size; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); - - - //screen size - window.addEventListener('resize',() => { - + //screen size + window.addEventListener("resize", () => { config.screen_height = window.innerHeight; config.screen_width = window.innerWidth; fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); + }); + // Explorer button clicked + document.getElementById("openExplorer").addEventListener("click", () => { + shell.openExternal( + "https://explorer.freedata.app/?myCall=" + + document.getElementById("myCall").value + ); + }); - // Stop beacon button clicked - document.getElementById("stopBeacon").addEventListener("click", () => { - sock.stopBeacon(); - }); + // Stats button clicked + document.getElementById("btnStats").addEventListener("click", () => { + shell.openExternal("https://statistics.freedata.app"); + }); + // GH Link clicked + document.getElementById("fdWww").addEventListener("click", () => { + shell.openExternal("https://freedata.app"); + }); + // GH Link clicked + document.getElementById("ghUrl").addEventListener("click", () => { + shell.openExternal("https://github.com/DJ2LS/FreeDATA"); + }); + // Wiki Link clicked + document.getElementById("wikiUrl").addEventListener("click", () => { + shell.openExternal("https://wiki.freedata.app"); + }); + // Groups.io Link clicked + document.getElementById("groupsioUrl").addEventListener("click", () => { + shell.openExternal("https://groups.io/g/freedata"); + }); + // Discord Link clicked + document.getElementById("discordUrl").addEventListener("click", () => { + shell.openExternal("https://discord.gg/jnADeDtxUF"); + }); + // startTNC button clicked + document.getElementById("startTNC").addEventListener("click", () => { + var tuning_range_fmin = document.getElementById("tuning_range_fmin").value; + var tuning_range_fmax = document.getElementById("tuning_range_fmax").value; - // Explorer button clicked - document.getElementById("openExplorer").addEventListener("click", () => { - shell.openExternal('https://explorer.freedata.app/?myCall=' + document.getElementById("myCall").value); - }); + var rigctld_ip = document.getElementById("hamlib_rigctld_ip").value; + var rigctld_port = document.getElementById("hamlib_rigctld_port").value; + var hamlib_rigctld_server_port = document.getElementById( + "hamlib_rigctld_server_port" + ).value; - // Stats button clicked - document.getElementById("btnStats").addEventListener("click", () => { - shell.openExternal('https://statistics.freedata.app'); - }); + var deviceid = document.getElementById("hamlib_deviceid").value; + var deviceport = document.getElementById("hamlib_deviceport").value; + var serialspeed = document.getElementById("hamlib_serialspeed").value; + var pttprotocol = document.getElementById("hamlib_pttprotocol").value; + var hamlib_dcd = document.getElementById("hamlib_dcd").value; - // GH Link clicked - document.getElementById("ghUrl").addEventListener("click", () => { - shell.openExternal('https://github.com/DJ2LS/FreeDATA'); - }); - // Wiki Link clicked - document.getElementById("wikiUrl").addEventListener("click", () => { - shell.openExternal('https://wiki.freedata.app'); - }); - // Groups.io Link clicked - document.getElementById("groupsioUrl").addEventListener("click", () => { - shell.openExternal('https://groups.io/g/freedata'); - }); - // Discord Link clicked - document.getElementById("discordUrl").addEventListener("click", () => { - shell.openExternal('https://discord.gg/jnADeDtxUF'); - }); - // startTNC button clicked - document.getElementById("startTNC").addEventListener("click", () => { + var mycall = document.getElementById("myCall").value; + var ssid = document.getElementById("myCallSSID").value; + callsign_ssid = mycall.toUpperCase() + "-" + ssid; - var tuning_range_fmin = document.getElementById("tuning_range_fmin").value; - var tuning_range_fmax = document.getElementById("tuning_range_fmax").value; - - var rigctld_ip = document.getElementById("hamlib_rigctld_ip").value; - var rigctld_port = document.getElementById("hamlib_rigctld_port").value; - var hamlib_rigctld_server_port = document.getElementById("hamlib_rigctld_server_port").value; + var mygrid = document.getElementById("myGrid").value; - var deviceid = document.getElementById("hamlib_deviceid").value; - var deviceport = document.getElementById("hamlib_deviceport").value; - var serialspeed = document.getElementById("hamlib_serialspeed").value; - var pttprotocol = document.getElementById("hamlib_pttprotocol").value; - var hamlib_dcd = document.getElementById("hamlib_dcd").value; + var rx_audio = document.getElementById("audio_input_selectbox").value; + var tx_audio = document.getElementById("audio_output_selectbox").value; - var mycall = document.getElementById("myCall").value; - var ssid = document.getElementById("myCallSSID").value; - callsign_ssid = mycall.toUpperCase() + '-' + ssid; - - var mygrid = document.getElementById("myGrid").value; - - var rx_audio = document.getElementById("audio_input_selectbox").value; - var tx_audio = document.getElementById("audio_output_selectbox").value; - - var pttport = document.getElementById("hamlib_ptt_port").value; - var data_bits = document.getElementById('hamlib_databits').value; - var stop_bits = document.getElementById('hamlib_stopbits').value; - var handshake = document.getElementById('hamlib_handshake').value; - - if (document.getElementById("scatterSwitch").checked == true){ - var enable_scatter = "True"; - } else { - var enable_scatter = "False"; - } - + var pttport = document.getElementById("hamlib_ptt_port").value; + var data_bits = document.getElementById("hamlib_data_bits").value; + var stop_bits = document.getElementById("hamlib_stop_bits").value; + var handshake = document.getElementById("hamlib_handshake").value; - if (document.getElementById("fftSwitch").checked == true){ - var enable_fft = "True"; - } else { - var enable_fft = "False"; - } - - if (document.getElementById("500HzModeSwitch").checked == true){ - var low_bandwidth_mode = "True"; - } else { - var low_bandwidth_mode = "False"; - } - - if (document.getElementById("fskModeSwitch").checked == true){ - var enable_fsk = "True"; - } else { - var enable_fsk = "False"; - } - - if (document.getElementById("respondCQSwitch").checked == true){ - var respond_to_cq = "True"; - } else { - var respond_to_cq = "False"; - } - - if (document.getElementById("ExplorerSwitch").checked == true){ - var enable_explorer = "True"; - } else { - var enable_explorer = "False"; - } - - if (document.getElementById("ExplorerStatsSwitch").checked == true){ - var explorer_stats = "True"; - } else { - var explorer_stats = "False"; - } - - if (document.getElementById("autoTuneSwitch").checked == true){ - var auto_tune = "True"; - } else { - var auto_tune = "False"; - } - // loop through audio device list and select - for(i = 0; i < document.getElementById("audio_input_selectbox").length; i++) { - device = document.getElementById("audio_input_selectbox")[i]; - - if (device.value == rx_audio) { - console.log(device.text); - config.rx_audio = device.text; - } - } - - // loop through audio device list and select - for(i = 0; i < document.getElementById("audio_output_selectbox").length; i++) { - device = document.getElementById("audio_output_selectbox")[i]; - - if (device.value == tx_audio) { - console.log(device.text); - config.tx_audio = device.text; - } - } - - if (!document.getElementById("radio-control-switch-disabled").checked) { - var radiocontrol = 'rigctld'; - } else { - var radiocontrol = 'disabled'; - } - - var tx_audio_level = document.getElementById("audioLevelTX").value; - var rx_buffer_size = document.getElementById("rx_buffer_size").value; - - - - - config.radiocontrol = radiocontrol; - config.mycall = callsign_ssid; - config.mygrid = mygrid; - config.hamlib_deviceid = deviceid; - config.hamlib_deviceport = deviceport; - config.hamlib_serialspeed = serialspeed; - config.hamlib_pttprotocol = pttprotocol; - config.hamlib_pttport = pttport; - config.hamlib_data_bits = data_bits; - config.hamlib_stop_bits = stop_bits; - config.hamlib_handshake = handshake; - config.hamlib_dcd = hamlib_dcd; - //config.deviceid_rigctl = deviceid_rigctl; - //config.serialspeed_rigctl = serialspeed_rigctl; - //config.pttprotocol_rigctl = pttprotocol_rigctl; - config.hamlib_rigctld_port = rigctld_port; - config.hamlib_rigctld_ip = rigctld_ip; - config.hamlib_rigctld_server_port = hamlib_rigctld_server_port; - //config.deviceport_rigctl = deviceport_rigctl; - config.enable_scatter = enable_scatter; - config.enable_fft = enable_fft; - config.enable_fsk = enable_fsk; - config.low_bandwidth_mode = low_bandwidth_mode; - config.tx_audio_level = tx_audio_level; - config.respond_to_cq = respond_to_cq; - config.rx_buffer_size = rx_buffer_size; - config.enable_explorer = enable_explorer; - config.explorer_stats = explorer_stats; - config.auto_tune = auto_tune; - - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - - - // collapse settings screen - // deactivated this part so start / stop is a little bit more smooth. We are getting problems because of network delay - /* - var collapseFirstRow = new bootstrap.Collapse(document.getElementById('collapseFirstRow'), {toggle: false}) - collapseFirstRow.hide() - var collapseSecondRow = new bootstrap.Collapse(document.getElementById('collapseSecondRow'), {toggle: false}) - collapseSecondRow.hide() - var collapseThirdRow = new bootstrap.Collapse(document.getElementById('collapseThirdRow'), {toggle: false}) - collapseThirdRow.show() - var collapseFourthRow = new bootstrap.Collapse(document.getElementById('collapseFourthRow'), {toggle: false}) - collapseFourthRow.show() - */ - - - daemon.startTNC(callsign_ssid, mygrid, rx_audio, tx_audio, radiocontrol, deviceid, deviceport, pttprotocol, pttport, serialspeed, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port, enable_fft, enable_scatter, low_bandwidth_mode, tuning_range_fmin, tuning_range_fmax, enable_fsk, tx_audio_level, respond_to_cq, rx_buffer_size, enable_explorer,explorer_stats,auto_tune); - - - }) - - document.getElementById("tncLog").addEventListener("click", () => { - - ipcRenderer.send('request-open-tnc-log'); - - - -}) - - - // stopTNC button clicked - document.getElementById("stopTNC").addEventListener("click", () => { - if (!confirm("Stop the TNC?")) return; - - daemon.stopTNC(); - - // collapse settings screen - // deactivated this part so start / stop is a little bit more smooth. We are getting problems because of network delay - /* - var collapseFirstRow = new bootstrap.Collapse(document.getElementById('collapseFirstRow'), {toggle: false}) - collapseFirstRow.show() - var collapseSecondRow = new bootstrap.Collapse(document.getElementById('collapseSecondRow'), {toggle: false}) - collapseSecondRow.show() - - var collapseThirdRow = new bootstrap.Collapse(document.getElementById('collapseThirdRow'), {toggle: false}) - collapseThirdRow.hide() - var collapseFourthRow = new bootstrap.Collapse(document.getElementById('collapseFourthRow'), {toggle: false}) - collapseFourthRow.hide() - */ - }) - - - // openDataModule button clicked - // not necessesary at this time beacuse bootstrap handles this - // document.getElementById("openDataModule").addEventListener("click", () => { - // var transmitFileSidebar = document.getElementById('transmitFileSidebar') - // var bstransmitFileSidebar = new bootstrap.Offcanvas(transmitFileSidebar) - // bstransmitFileSidebar.show() - //}) - - // openReceivedFiles button clicked - // not necessesary at this time beacuse bootstrap handles this - //document.getElementById("openReceivedFiles").addEventListener("click", () => { - // var transmitFileSidebar = document.getElementById('transmitFileSidebar') - // var bstransmitFileSidebar = new bootstrap.Offcanvas(transmitFileSidebar) - // bstransmitFileSidebar.show() - //}) - - - // TEST HAMLIB - document.getElementById("testHamlib").addEventListener("click", () => { - - - var data_bits = document.getElementById("hamlib_databits").value; - var stop_bits = document.getElementById("hamlib_stopbits").value; - var handshake = document.getElementById("hamlib_handshake").value; - var pttport = document.getElementById("hamlib_ptt_port").value; - - var rigctld_ip = document.getElementById("hamlib_rigctld_ip").value; - var rigctld_port = document.getElementById("hamlib_rigctld_port").value; - - var deviceid = document.getElementById("hamlib_deviceid").value; - var deviceport = document.getElementById("hamlib_deviceport").value; - var serialspeed = document.getElementById("hamlib_serialspeed").value; - var pttprotocol = document.getElementById("hamlib_pttprotocol").value; - - if (document.getElementById("radio-control-switch-disabled").checked) { - var radiocontrol = 'disabled'; - } else { - var radiocontrol = 'rigctld'; - } - - daemon.testHamlib(radiocontrol, deviceid, deviceport, serialspeed, pttprotocol, pttport, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port) - }) - - - // START TRANSMISSION - document.getElementById("startTransmission").addEventListener("click", () => { - //document.getElementById("transmitFileSidebar").style.width = "0px"; - /* not neccessary at this time because handled by bootstap inside html - var transmitFileSidebar = document.getElementById('transmitFileSidebar') - var bstransmitFileSidebar = new bootstrap.Offcanvas(transmitFileSidebar) - bstransmitFileSidebar.show() - */ - - - - var fileList = document.getElementById("dataModalFile").files; - console.log(fileList) - var reader = new FileReader(); - reader.readAsBinaryString(fileList[0]); - //reader.readAsDataURL(fileList[0]); - - reader.onload = function(e) { - // binary data - - var data = e.target.result; - console.log(data); - - - let Data = { - command: "send_file", - dxcallsign: document.getElementById("dataModalDxCall").value.toUpperCase(), - mode: document.getElementById("datamode").value, - frames: document.getElementById("framesperburst").value, - filetype: fileList[0].type, - filename: fileList[0].name, - data: data, - checksum: '123123123', - }; - // only send command if dxcallsign entered and we have a file selected - if(document.getElementById("dataModalDxCall").value.length > 0){ - ipcRenderer.send('run-tnc-command', Data); - } - }; - reader.onerror = function(e) { - // error occurred - console.log('Error : ' + e.type); - }; - - }) - // STOP TRANSMISSION - document.getElementById("stopTransmission").addEventListener("click", () => { - let Data = { - command: "stop_transmission" - }; - ipcRenderer.send('run-tnc-command', Data); - }) - - // STOP TRANSMISSION AND CONNECRTION - document.getElementById("stop_transmission_connection").addEventListener("click", () => { - let Data = { - command: "stop_transmission" - }; - ipcRenderer.send('run-tnc-command', Data); - sock.disconnectARQ(); - }) - - - // OPEN CHAT MODULE - document.getElementById("openRFChat").addEventListener("click", () => { - let Data = { - command: "openRFChat" - }; - ipcRenderer.send('request-show-chat-window', Data); - }) -}) - -function connectedStation(data) -{ - if ((typeof(data.dxcallsign) == 'undefined')) { - return; - } - if (!(typeof(data.arq) == 'undefined') && data.arq.toLowerCase() == 'session') { - var prefix = "w/ "; + if (document.getElementById("scatterSwitch").checked == true) { + var enable_scatter = "True"; } else { - switch (data.irs){ - case 'True': - //We are receiving station - var prefix = "de "; - break; - case 'False': - //We are sending station - var prefix = "to "; - break; - default: - //Shouldn't happen - console.trace('No data.irs data in tnc-message'); - var prefix = ""; - break; - } - + var enable_scatter = "False"; } - document.getElementById("txtConnectedWith").textContent=prefix + data.dxcallsign; + + if (document.getElementById("fftSwitch").checked == true) { + var enable_fft = "True"; + } else { + var enable_fft = "False"; + } + + if (document.getElementById("500HzModeSwitch").checked == true) { + var low_bandwidth_mode = "True"; + } else { + var low_bandwidth_mode = "False"; + } + + if (document.getElementById("fskModeSwitch").checked == true) { + var enable_fsk = "True"; + } else { + var enable_fsk = "False"; + } + + if (document.getElementById("respondCQSwitch").checked == true) { + var respond_to_cq = "True"; + } else { + var respond_to_cq = "False"; + } + + if (document.getElementById("ExplorerSwitch").checked == true) { + var enable_explorer = "True"; + } else { + var enable_explorer = "False"; + } + + if (document.getElementById("ExplorerStatsSwitch").checked == true) { + var explorer_stats = "True"; + } else { + var explorer_stats = "False"; + } + + if (document.getElementById("autoTuneSwitch").checked == true) { + var auto_tune = "True"; + } else { + var auto_tune = "False"; + } + // loop through audio device list and select + for ( + i = 0; + i < document.getElementById("audio_input_selectbox").length; + i++ + ) { + device = document.getElementById("audio_input_selectbox")[i]; + + if (device.value == rx_audio) { + console.log(device.text); + config.rx_audio = device.text; + } + } + + // loop through audio device list and select + for ( + i = 0; + i < document.getElementById("audio_output_selectbox").length; + i++ + ) { + device = document.getElementById("audio_output_selectbox")[i]; + + if (device.value == tx_audio) { + console.log(device.text); + config.tx_audio = device.text; + } + } + + if (!document.getElementById("radio-control-switch-disabled").checked) { + var radiocontrol = "rigctld"; + } else { + var radiocontrol = "disabled"; + } + + var tx_audio_level = document.getElementById("audioLevelTX").value; + var rx_buffer_size = document.getElementById("rx_buffer_size").value; + + config.radiocontrol = radiocontrol; + config.mycall = callsign_ssid; + config.mygrid = mygrid; + config.hamlib_deviceid = deviceid; + config.hamlib_deviceport = deviceport; + config.hamlib_serialspeed = serialspeed; + config.hamlib_pttprotocol = pttprotocol; + config.hamlib_ptt_port = pttport; + config.hamlib_data_bits = data_bits; + config.hamlib_stop_bits = stop_bits; + config.hamlib_handshake = handshake; + config.hamlib_dcd = hamlib_dcd; + config.hamlib_rigctld_port = rigctld_port; + config.hamlib_rigctld_ip = rigctld_ip; + config.hamlib_rigctld_server_port = hamlib_rigctld_server_port; + config.enable_scatter = enable_scatter; + config.enable_fft = enable_fft; + config.enable_fsk = enable_fsk; + config.low_bandwidth_mode = low_bandwidth_mode; + config.tx_audio_level = tx_audio_level; + config.respond_to_cq = respond_to_cq; + config.rx_buffer_size = rx_buffer_size; + config.enable_explorer = enable_explorer; + config.explorer_stats = explorer_stats; + config.auto_tune = auto_tune; + + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + + daemon.startTNC( + callsign_ssid, + mygrid, + rx_audio, + tx_audio, + radiocontrol, + deviceid, + deviceport, + pttprotocol, + pttport, + serialspeed, + data_bits, + stop_bits, + handshake, + rigctld_ip, + rigctld_port, + enable_fft, + enable_scatter, + low_bandwidth_mode, + tuning_range_fmin, + tuning_range_fmax, + enable_fsk, + tx_audio_level, + respond_to_cq, + rx_buffer_size, + enable_explorer, + explorer_stats, + auto_tune + ); + }); + + document.getElementById("tncLog").addEventListener("click", () => { + ipcRenderer.send("request-open-tnc-log"); + }); + + // stopTNC button clicked + document.getElementById("stopTNC").addEventListener("click", () => { + if (!confirm("Stop the TNC?")) return; + + daemon.stopTNC(); + }); + + // TEST HAMLIB + document.getElementById("testHamlib").addEventListener("click", () => { + var data_bits = document.getElementById("hamlib_data_bits").value; + var stop_bits = document.getElementById("hamlib_stop_bits").value; + var handshake = document.getElementById("hamlib_handshake").value; + var pttport = document.getElementById("hamlib_ptt_port").value; + + var rigctld_ip = document.getElementById("hamlib_rigctld_ip").value; + var rigctld_port = document.getElementById("hamlib_rigctld_port").value; + + var deviceid = document.getElementById("hamlib_deviceid").value; + var deviceport = document.getElementById("hamlib_deviceport").value; + var serialspeed = document.getElementById("hamlib_serialspeed").value; + var pttprotocol = document.getElementById("hamlib_pttprotocol").value; + + if (document.getElementById("radio-control-switch-disabled").checked) { + var radiocontrol = "disabled"; + } else { + var radiocontrol = "rigctld"; + } + + daemon.testHamlib( + radiocontrol, + deviceid, + deviceport, + serialspeed, + pttprotocol, + pttport, + data_bits, + stop_bits, + handshake, + rigctld_ip, + rigctld_port + ); + }); + + // START TRANSMISSION + document.getElementById("startTransmission").addEventListener("click", () => { + var fileList = document.getElementById("dataModalFile").files; + console.log(fileList); + var reader = new FileReader(); + reader.readAsBinaryString(fileList[0]); + //reader.readAsDataURL(fileList[0]); + + reader.onload = function (e) { + // binary data + + var data = e.target.result; + console.log(data); + + let Data = { + command: "send_file", + dxcallsign: document + .getElementById("dataModalDxCall") + .value.toUpperCase(), + mode: document.getElementById("datamode").value, + frames: document.getElementById("framesperburst").value, + filetype: fileList[0].type, + filename: fileList[0].name, + data: data, + checksum: "123123123", + }; + // only send command if dxcallsign entered and we have a file selected + if (document.getElementById("dataModalDxCall").value.length > 0) { + ipcRenderer.send("run-tnc-command", Data); + } + }; + reader.onerror = function (e) { + // error occurred + console.log("Error : " + e.type); + }; + }); + // STOP TRANSMISSION + document.getElementById("stopTransmission").addEventListener("click", () => { + let Data = { + command: "stop_transmission", + }; + ipcRenderer.send("run-tnc-command", Data); + }); + + // STOP TRANSMISSION AND CONNECRTION + document + .getElementById("stop_transmission_connection") + .addEventListener("click", () => { + let Data = { + command: "stop_transmission", + }; + ipcRenderer.send("run-tnc-command", Data); + sock.disconnectARQ(); + }); + + // OPEN CHAT MODULE + document.getElementById("openRFChat").addEventListener("click", () => { + let Data = { + command: "openRFChat", + }; + ipcRenderer.send("request-show-chat-window", Data); + }); +}); + +function connectedStation(data) { + if (typeof data.dxcallsign == "undefined") { + return; + } + if ( + !(typeof data.arq == "undefined") && + data.arq.toLowerCase() == "session" + ) { + var prefix = "w/ "; + } else { + switch (data.irs) { + case "True": + //We are receiving station + var prefix = "de "; + break; + case "False": + //We are sending station + var prefix = "to "; + break; + default: + //Shouldn't happen + console.trace("No data.irs data in tnc-message"); + var prefix = ""; + break; + } + } + document.getElementById("txtConnectedWith").textContent = + prefix + data.dxcallsign; } //Listen for events caused by tnc 'tnc-message' rx -ipcRenderer.on('action-update-reception-status', (event, arg) => { - var data =arg["data"][0]; - var txprog = document.getElementById("transmission_progress") - ipcRenderer.send('request-show-electron-progressbar',data.percent); - txprog.setAttribute("aria-valuenow", data.percent); - txprog.setAttribute("style", "width:" + data.percent + "%;"); - - // SET TIME LEFT UNTIL FINIHED - if (typeof(data.finished) == 'undefined') { - var time_left = "time left: estimating"; - } else { - var arq_seconds_until_finish = data.finished - var hours = Math.floor(arq_seconds_until_finish / 3600); - var minutes = Math.floor((arq_seconds_until_finish % 3600) / 60 ); - var seconds = arq_seconds_until_finish % 60; - if(hours < 0) { - hours = 0; - } - if(minutes < 0) { - minutes = 0; - } - if(seconds < 0) { - seconds = 0; - } - if (hours > 0) - { - time_left = "time left: ~"+ hours.toString().padStart(2,'0') + ":" + minutes.toString().padStart(2,'0') + "." + seconds.toString().padStart(2,'0'); - } else { - time_left = "time left: ~"+ minutes.toString().padStart(2,'0') + "." + seconds.toString().padStart(2,'0'); - } - } - var time_left = "" + time_left +" || Speed/min: "; +ipcRenderer.on("action-update-reception-status", (event, arg) => { + var data = arg["data"][0]; + var txprog = document.getElementById("transmission_progress"); + ipcRenderer.send("request-show-electron-progressbar", data.percent); + txprog.setAttribute("aria-valuenow", data.percent); + txprog.setAttribute("style", "width:" + data.percent + "%;"); - // SET BYTES PER MINUTE - if (typeof(data.bytesperminute) == 'undefined') { - var arq_bytes_per_minute = 0; + // SET TIME LEFT UNTIL FINIHED + if (typeof data.finished == "undefined") { + var time_left = "time left: estimating"; + } else { + var arq_seconds_until_finish = data.finished; + var hours = Math.floor(arq_seconds_until_finish / 3600); + var minutes = Math.floor((arq_seconds_until_finish % 3600) / 60); + var seconds = arq_seconds_until_finish % 60; + if (hours < 0) { + hours = 0; + } + if (minutes < 0) { + minutes = 0; + } + if (seconds < 0) { + seconds = 0; + } + if (hours > 0) { + time_left = + "time left: ~" + + hours.toString().padStart(2, "0") + + ":" + + minutes.toString().padStart(2, "0") + + "." + + seconds.toString().padStart(2, "0"); } else { - var arq_bytes_per_minute = data.bytesperminute; + time_left = + "time left: ~" + + minutes.toString().padStart(2, "0") + + "." + + seconds.toString().padStart(2, "0"); } - - // SET BYTES PER MINUTE COMPRESSED - var compress = data.compression; - if (isNaN(compress)) { - compress = 1; - } - var arq_bytes_per_minute_compressed = Math.round(arq_bytes_per_minute * compress); - - time_left += formatBytes(arq_bytes_per_minute,1) + " (comp: " + formatBytes(arq_bytes_per_minute_compressed,1) + ")"; - + } + var time_left = "" + time_left + " || Speed/min: "; - document.getElementById("transmission_timeleft").innerHTML = time_left; - connectedStation(data); + // SET BYTES PER MINUTE + if (typeof data.bytesperminute == "undefined") { + var arq_bytes_per_minute = 0; + } else { + var arq_bytes_per_minute = data.bytesperminute; + } + + // SET BYTES PER MINUTE COMPRESSED + var compress = data.compression; + if (isNaN(compress)) { + compress = 1; + } + var arq_bytes_per_minute_compressed = Math.round( + arq_bytes_per_minute * compress + ); + + time_left += + formatBytes(arq_bytes_per_minute, 1) + + " (comp: " + + formatBytes(arq_bytes_per_minute_compressed, 1) + + ")"; + + document.getElementById("transmission_timeleft").innerHTML = time_left; + connectedStation(data); }); //Listen for events caused by tnc 'tnc-message's tx -ipcRenderer.on('action-update-transmission-status', (event, arg) => { - var data =arg["data"][0]; - var txprog = document.getElementById("transmission_progress") - ipcRenderer.send('request-show-electron-progressbar',data.percent); - txprog.setAttribute("aria-valuenow", data.percent); - txprog.setAttribute("style", "width:" + data.percent + "%;"); - - // SET TIME LEFT UNTIL FINIHED - if (typeof(data.finished) == 'undefined') { - var time_left = "time left: estimating"; - } else { - var arq_seconds_until_finish = data.finished - var hours = Math.floor(arq_seconds_until_finish / 3600); - var minutes = Math.floor((arq_seconds_until_finish % 3600) / 60 ); - var seconds = arq_seconds_until_finish % 60; - if(hours < 0) { - hours = 0; - } - if(minutes < 0) { - minutes = 0; - } - if(seconds < 0) { - seconds = 0; - } - if (hours > 0) - { - time_left = "time left: ~"+ hours.toString().padStart(2,'0') + ":" + minutes.toString().padStart(2,'0') + "." + seconds.toString().padStart(2,'0'); - } else { - time_left = "time left: ~"+ minutes.toString().padStart(2,'0') + "." + seconds.toString().padStart(2,'0'); - } - } - var time_left = "" + time_left +" || Speed/min: "; +ipcRenderer.on("action-update-transmission-status", (event, arg) => { + var data = arg["data"][0]; + var txprog = document.getElementById("transmission_progress"); + ipcRenderer.send("request-show-electron-progressbar", data.percent); + txprog.setAttribute("aria-valuenow", data.percent); + txprog.setAttribute("style", "width:" + data.percent + "%;"); - // SET BYTES PER MINUTE - if (typeof(data.bytesperminute) == 'undefined') { - var arq_bytes_per_minute = 0; + // SET TIME LEFT UNTIL FINIHED + if (typeof data.finished == "undefined") { + var time_left = "time left: estimating"; + } else { + var arq_seconds_until_finish = data.finished; + var hours = Math.floor(arq_seconds_until_finish / 3600); + var minutes = Math.floor((arq_seconds_until_finish % 3600) / 60); + var seconds = arq_seconds_until_finish % 60; + if (hours < 0) { + hours = 0; + } + if (minutes < 0) { + minutes = 0; + } + if (seconds < 0) { + seconds = 0; + } + if (hours > 0) { + time_left = + "time left: ~" + + hours.toString().padStart(2, "0") + + ":" + + minutes.toString().padStart(2, "0") + + "." + + seconds.toString().padStart(2, "0"); } else { - var arq_bytes_per_minute = data.bytesperminute; + time_left = + "time left: ~" + + minutes.toString().padStart(2, "0") + + "." + + seconds.toString().padStart(2, "0"); } - - // SET BYTES PER MINUTE COMPRESSED - var compress = data.compression; - if (isNaN(compress)) { - compress = 1; - } - var arq_bytes_per_minute_compressed = Math.round(arq_bytes_per_minute * compress); - - time_left += formatBytes(arq_bytes_per_minute,1) + " (comp: " + formatBytes(arq_bytes_per_minute_compressed,1) + ")"; - - connectedStation(data); + } + var time_left = "" + time_left + " || Speed/min: "; + // SET BYTES PER MINUTE + if (typeof data.bytesperminute == "undefined") { + var arq_bytes_per_minute = 0; + } else { + var arq_bytes_per_minute = data.bytesperminute; + } + + // SET BYTES PER MINUTE COMPRESSED + var compress = data.compression; + if (isNaN(compress)) { + compress = 1; + } + var arq_bytes_per_minute_compressed = Math.round( + arq_bytes_per_minute * compress + ); + + time_left += + formatBytes(arq_bytes_per_minute, 1) + + " (comp: " + + formatBytes(arq_bytes_per_minute_compressed, 1) + + ")"; + + connectedStation(data); }); -var lastHeard=""; -ipcRenderer.on('action-update-tnc-state', (event, arg) => { - // update FFT - if (typeof(arg.fft) !== 'undefined') { - var array = JSON.parse("[" + arg.fft + "]"); - spectrum.addData(array[0]); - } +var lastHeard = ""; +ipcRenderer.on("action-update-tnc-state", (event, arg) => { + // update FFT + if (typeof arg.fft !== "undefined") { + var array = JSON.parse("[" + arg.fft + "]"); + spectrum.addData(array[0]); + } - if (typeof(arg.mycallsign) !== 'undefined') { - updateTitle(arg.mycallsign); - } + if (typeof arg.mycallsign !== "undefined") { + updateTitle(arg.mycallsign); + } - // update mygrid information with data from tnc - if (typeof(arg.mygrid) !== 'undefined') { - document.getElementById("myGrid").value = arg.mygrid; - } + // update mygrid information with data from tnc + if (typeof arg.mygrid !== "undefined") { + document.getElementById("myGrid").value = arg.mygrid; + } - // DATA STATE - global.rxBufferLengthTnc = arg.rx_buffer_length + // DATA STATE + global.rxBufferLengthTnc = arg.rx_buffer_length; - // START OF SCATTER CHART - const scatterConfig = { - plugins: { - legend: { - display: false, - }, - tooltip: { - enabled: false - }, - annotation: { - annotations: { - line1: { - type: 'line', - yMin: 0, - yMax: 0, - borderColor: 'rgb(255, 99, 132)', - borderWidth: 2, - }, - line2: { - type: 'line', - xMin: 0, - xMax: 0, - borderColor: 'rgb(255, 99, 132)', - borderWidth: 2, - } - } - }, - }, - animations: false, - scales: { - x: { - type: 'linear', - position: 'bottom', - display: true, - min: -80, - max: 80, - ticks: { - display: false - } - }, - y: { - display: true, - min: -80, - max: 80, - ticks: { - display: false, - } - } - } - } - var scatterData = arg.scatter - var newScatterData = { - datasets: [{ - //label: 'constellation diagram', - data: scatterData, - options: scatterConfig, - backgroundColor: 'rgb(255, 99, 132)' - }], - }; + // START OF SCATTER CHART + const scatterConfig = { + plugins: { + legend: { + display: false, + }, + tooltip: { + enabled: false, + }, + annotation: { + annotations: { + line1: { + type: "line", + yMin: 0, + yMax: 0, + borderColor: "rgb(255, 99, 132)", + borderWidth: 2, + }, + line2: { + type: "line", + xMin: 0, + xMax: 0, + borderColor: "rgb(255, 99, 132)", + borderWidth: 2, + }, + }, + }, + }, + animations: false, + scales: { + x: { + type: "linear", + position: "bottom", + display: true, + min: -80, + max: 80, + ticks: { + display: false, + }, + }, + y: { + display: true, + min: -80, + max: 80, + ticks: { + display: false, + }, + }, + }, + }; + var scatterData = arg.scatter; + var newScatterData = { + datasets: [ + { + //label: 'constellation diagram', + data: scatterData, + options: scatterConfig, + backgroundColor: "rgb(255, 99, 132)", + }, + ], + }; - if (typeof(arg.scatter) == 'undefined') { - var scatterSize = 0; + if (typeof arg.scatter == "undefined") { + var scatterSize = 0; + } else { + var scatterSize = arg.scatter.length; + } + + if (scatterSize > 0 && global.scatterData != newScatterData) { + global.scatterData = newScatterData; + + if (typeof global.scatterChart == "undefined") { + var scatterCtx = document.getElementById("scatter").getContext("2d"); + global.scatterChart = new Chart(scatterCtx, { + type: "scatter", + data: global.scatterData, + options: scatterConfig, + }); } else { - var scatterSize = arg.scatter.length; + global.scatterChart.data = global.scatterData; + global.scatterChart.update(); } + } + // END OF SCATTER CHART - if (scatterSize > 0 && global.scatterData != newScatterData) { - global.scatterData = newScatterData; + // START OF SPEED CHART + var speedDataTime = []; - if (typeof(global.scatterChart) == 'undefined') { - var scatterCtx = document.getElementById('scatter').getContext('2d'); - global.scatterChart = new Chart(scatterCtx, { - type: 'scatter', - data: global.scatterData, - options: scatterConfig - }); - } else { - global.scatterChart.data = global.scatterData; - global.scatterChart.update(); + if (typeof arg.speed_list == "undefined") { + var speed_listSize = 0; + } else { + var speed_listSize = arg.speed_list.length; + } + + for (var i = 0; i < speed_listSize; i++) { + var timestamp = arg.speed_list[i].timestamp * 1000; + var h = new Date(timestamp).getHours(); + var m = new Date(timestamp).getMinutes(); + var s = new Date(timestamp).getSeconds(); + var time = h + ":" + m + ":" + s; + speedDataTime.push(time); + } + + var speedDataBpm = []; + for (var i = 0; i < speed_listSize; i++) { + speedDataBpm.push(arg.speed_list[i].bpm); + } + + var speedDataSnr = []; + for (var i = 0; i < speed_listSize; i++) { + speedDataSnr.push(arg.speed_list[i].snr); + } + + var speedChartConfig = { + type: "line", + }; + + // https://www.chartjs.org/docs/latest/samples/line/segments.html + const skipped = (speedCtx, value) => + speedCtx.p0.skip || speedCtx.p1.skip ? value : undefined; + const down = (speedCtx, value) => + speedCtx.p0.parsed.y > speedCtx.p1.parsed.y ? value : undefined; + + var newSpeedData = { + labels: speedDataTime, + datasets: [ + { + type: "line", + label: "SNR[dB]", + data: speedDataSnr, + borderColor: "rgb(75, 192, 192, 1.0)", + segment: { + borderColor: (ctx) => + skipped(ctx, "rgb(0,0,0,0.2)") || down(ctx, "rgb(192,75,75)"), + borderDash: (ctx) => skipped(ctx, [6, 6]), + }, + spanGaps: true, + backgroundColor: "rgba(75, 192, 192, 0.2)", + order: 1, + yAxisID: "SNR", + }, + { + type: "bar", + label: "Speed[bpm]", + data: speedDataBpm, + borderColor: "rgb(120, 100, 120, 1.0)", + backgroundColor: "rgba(120, 100, 120, 0.2)", + order: 0, + yAxisID: "SPEED", + }, + ], + }; + + var speedChartOptions = { + responsive: true, + animations: true, + cubicInterpolationMode: "monotone", + tension: 0.4, + scales: { + SNR: { + type: "linear", + ticks: { beginAtZero: true, color: "rgb(255, 99, 132)" }, + position: "right", + }, + SPEED: { + type: "linear", + ticks: { beginAtZero: true, color: "rgb(120, 100, 120)" }, + position: "left", + grid: { + drawOnChartArea: false, // only want the grid lines for one axis to show up + }, + }, + x: { ticks: { beginAtZero: true } }, + }, + }; + + if (typeof global.speedChart == "undefined") { + var speedCtx = document.getElementById("chart").getContext("2d"); + global.speedChart = new Chart(speedCtx, { + data: newSpeedData, + options: speedChartOptions, + }); + } else { + if (speedDataSnr.length > 0) { + global.speedChart.data = newSpeedData; + global.speedChart.update(); } -} - // END OF SCATTER CHART + } + // END OF SPEED CHART - // START OF SPEED CHART - var speedDataTime = [] + // PTT STATE + switch (arg.ptt_state) { + case "True": + document.getElementById("ptt_state").className = "btn btn-sm btn-danger"; + break; + case "False": + document.getElementById("ptt_state").className = "btn btn-sm btn-success"; + break; + default: + document.getElementById("ptt_state").className = + "btn btn-sm btn-secondary"; + break; + } - if (typeof(arg.speed_list) == 'undefined') { - var speed_listSize = 0; - } else { - var speed_listSize = arg.speed_list.length; - } + // AUDIO RECORDING + if (arg.audio_recording == "True") { + document.getElementById("startStopRecording").textContent = "Stop Rec"; + } else { + document.getElementById("startStopRecording").textContent = "Start Rec"; + } - for (var i=0; i < speed_listSize; i++) { - var timestamp = arg.speed_list[i].timestamp * 1000 - var h = new Date(timestamp).getHours(); - var m = new Date(timestamp).getMinutes(); - var s = new Date(timestamp).getSeconds(); - var time = h + ':' + m + ':' + s; - speedDataTime.push(time) - } + // CHANNEL BUSY STATE + switch (arg.channel_busy) { + case "True": + document.getElementById("channel_busy").className = + "btn btn-sm btn-danger"; + break; + case "False": + document.getElementById("channel_busy").className = + "btn btn-sm btn-success"; + break; + default: + document.getElementById("channel_busy").className = + "btn btn-sm btn-secondary"; + break; + } - var speedDataBpm = [] - for (var i=0; i < speed_listSize; i++) { - speedDataBpm.push(arg.speed_list[i].bpm) + // BUSY STATE + switch (arg.busy_state) { + case "BUSY": + document.getElementById("busy_state").className = "btn btn-sm btn-danger"; + document.getElementById("startTransmission").disabled = true; + break; + case "IDLE": + document.getElementById("busy_state").className = + "btn btn-sm btn-success"; + break; + default: + document.getElementById("busy_state").className = + "btn btn-sm btn-secondary"; + document.getElementById("startTransmission").disabled = true; + break; + } - } + // ARQ STATE + switch (arg.arq_state) { + case "True": + document.getElementById("arq_state").className = "btn btn-sm btn-warning"; + document.getElementById("startTransmission").disabled = false; + break; + default: + document.getElementById("arq_state").className = + "btn btn-sm btn-secondary"; + document.getElementById("startTransmission").disabled = false; + break; + } - var speedDataSnr = [] - for (var i=0; i < speed_listSize; i++) { - speedDataSnr.push(arg.speed_list[i].snr) - } + // ARQ SESSION + switch (arg.arq_session) { + case "True": + document.getElementById("arq_session").className = + "btn btn-sm btn-warning"; + break; + default: + document.getElementById("arq_session").className = + "btn btn-sm btn-secondary"; + break; + } - var speedChartConfig = { - type: 'line', - }; + if (arg.arq_state == "True" || arg.arq_session == "True") { + toggleClass("spnConnectedWith", "text-success", true); + } else { + toggleClass("spnConnectedWith", "text-success", false); + } - // https://www.chartjs.org/docs/latest/samples/line/segments.html - const skipped = (speedCtx, value) => speedCtx.p0.skip || speedCtx.p1.skip ? value : undefined; - const down = (speedCtx, value) => speedCtx.p0.parsed.y > speedCtx.p1.parsed.y ? value : undefined; + // HAMLIB STATUS + if (arg.hamlib_status == "connected") { + document.getElementById("rigctld_state").className = + "btn btn-success btn-sm"; + } else { + document.getElementById("rigctld_state").className = + "btn btn-secondary btn-sm"; + } - var newSpeedData = { - labels: speedDataTime, - datasets: [ - { - type: 'line', - label: 'SNR[dB]', - data: speedDataSnr, - borderColor: 'rgb(75, 192, 192, 1.0)', - segment: { - borderColor: ctx => skipped(ctx, 'rgb(0,0,0,0.2)') || down(ctx, 'rgb(192,75,75)'), - borderDash: ctx => skipped(ctx, [6, 6]), - }, - spanGaps: true, - backgroundColor: 'rgba(75, 192, 192, 0.2)', - order: 1, - yAxisID: 'SNR', - }, - { - type: 'bar', - label: 'Speed[bpm]', - data: speedDataBpm, - borderColor: 'rgb(120, 100, 120, 1.0)', - backgroundColor: 'rgba(120, 100, 120, 0.2)', - order: 0, - yAxisID: 'SPEED', - } - ], - }; + // BEACON + switch (arg.beacon_state) { + case "True": + toggleClass("startBeacon", "btn-outline-secondary", false); + toggleClass("startBeacon", "btn-success", true); + if (document.getElementById("beaconInterval").disabled == false) { + document.getElementById("beaconInterval").disabled = true; + } + break; + default: + toggleClass("startBeacon", "btn-outline-secondary", true); + toggleClass("startBeacon", "btn-success", false); -var speedChartOptions = { - responsive: true, - animations: true, - cubicInterpolationMode: 'monotone', - tension: 0.4, - scales: { - SNR:{ - type: 'linear', - ticks: { beginAtZero: true, color: 'rgb(255, 99, 132)' }, - position: 'right', - }, - SPEED :{ - type: 'linear', - ticks: { beginAtZero: true, color: 'rgb(120, 100, 120)' }, - position: 'left', - grid: { - drawOnChartArea: false, // only want the grid lines for one axis to show up - }, - }, - x: { ticks: { beginAtZero: true } }, - } - } + if (document.getElementById("beaconInterval").disabled == true) { + document.getElementById("beaconInterval").disabled = false; + } + break; + } + // dbfs + // https://www.moellerstudios.org/converting-amplitude-representations/ + if (dbfs_level_raw != arg.dbfs_level) { + dbfs_level_raw = arg.dbfs_level; + dbfs_level = Math.pow(10, arg.dbfs_level / 20) * 100; - if (typeof(global.speedChart) == 'undefined') { + document.getElementById("dbfs_level_value").textContent = + Math.round(arg.dbfs_level) + " dBFS (Audio Level)"; + var dbfscntrl = document.getElementById("dbfs_level"); + dbfscntrl.setAttribute("aria-valuenow", dbfs_level); + dbfscntrl.setAttribute("style", "width:" + dbfs_level + "%;"); + } - var speedCtx = document.getElementById('chart').getContext('2d'); - global.speedChart = new Chart(speedCtx, { - data: newSpeedData, - options: speedChartOptions - }); - } else { - if(speedDataSnr.length > 0){ - global.speedChart.data = newSpeedData; - global.speedChart.update(); - } - } - // END OF SPEED CHART + // noise / strength + // https://www.moellerstudios.org/converting-amplitude-representations/ - // PTT STATE - switch (arg.ptt_state){ - case 'True': - document.getElementById("ptt_state").className = "btn btn-sm btn-danger"; - break; - case 'False': - document.getElementById("ptt_state").className = "btn btn-sm btn-success"; - break; - default: - document.getElementById("ptt_state").className = "btn btn-sm btn-secondary"; - break; - } + if (arg.strength != "" && noise_level_raw != arg.strength) { + //console.log(arg.strength); + noise_level_raw = arg.strength; + noise_level = Math.pow(10, arg.strength / 20) * 100; - // AUDIO RECORDING - if (arg.audio_recording == 'True') { - document.getElementById("startStopRecording").textContent = "Stop Rec" - } else { - document.getElementById("startStopRecording").textContent = "Start Rec" - } + document.getElementById("noise_level_value").textContent = + Math.round(arg.strength) + " dB (S-Meter)"; + var noisecntrl = document.getElementById("noise_level"); + noisecntrl.setAttribute("aria-valuenow", noise_level); + noisecntrl.setAttribute("style", "width:" + noise_level + "%;"); + } - // CHANNEL BUSY STATE - switch (arg.channel_busy){ - case 'True': - document.getElementById("channel_busy").className = "btn btn-sm btn-danger"; - break; - case 'False': - document.getElementById("channel_busy").className = "btn btn-sm btn-success"; - break; - default: - document.getElementById("channel_busy").className = "btn btn-sm btn-secondary"; - break; - } + // SET FREQUENCY + // https://stackoverflow.com/a/2901298 + var freq = arg.frequency.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); + document.getElementById("frequency").textContent = freq; + //document.getElementById("newFrequency").value = arg.frequency; - // BUSY STATE - switch(arg.busy_state){ - case 'BUSY': - document.getElementById("busy_state").className = "btn btn-sm btn-danger"; - document.getElementById("startTransmission").disabled = true; - break; - case 'IDLE': - document.getElementById("busy_state").className = "btn btn-sm btn-success"; - break; - default: - document.getElementById("busy_state").className = "btn btn-sm btn-secondary"; - document.getElementById("startTransmission").disabled = true; - break; - } + // SET MODE + document.getElementById("mode").textContent = arg.mode; - // ARQ STATE - switch (arg.arq_state){ - case 'True': - document.getElementById("arq_state").className = "btn btn-sm btn-warning"; - document.getElementById("startTransmission").disabled = false; - break; - default: - document.getElementById("arq_state").className = "btn btn-sm btn-secondary"; - document.getElementById("startTransmission").disabled = false; - break; - } + // SET bandwidth + document.getElementById("bandwidth").textContent = arg.bandwidth; - // ARQ SESSION - switch (arg.arq_session){ - case 'True': - document.getElementById("arq_session").className = "btn btn-sm btn-warning"; - break; - default: - document.getElementById("arq_session").className = "btn btn-sm btn-secondary"; - break; - } + // SET SPEED LEVEL + switch (arg.speed_level) { + case "0": + document.getElementById("speed_level").className = "bi bi-reception-1"; + break; + case "1": + document.getElementById("speed_level").className = "bi bi-reception-2"; + break; + case "2": + document.getElementById("speed_level").className = "bi bi-reception-3"; + break; + default: + document.getElementById("speed_level").className = "bi bi-reception-4"; + break; + } - if (arg.arq_state == 'True' || arg.arq_session == 'True') { - toggleClass("spnConnectedWith","text-success",true); - } else { - toggleClass("spnConnectedWith","text-success",false); - } - - // HAMLIB STATUS - if (arg.hamlib_status == 'connected') { - document.getElementById("rigctld_state").className = "btn btn-success btn-sm"; - } else { - document.getElementById("rigctld_state").className = "btn btn-secondary btn-sm"; - } - - // BEACON - let bcn = document.getElementById("startBeacon"); - - switch (arg.beacon_state){ - case 'True': - bcn.disabled = true; - if (config.high_graphics.toUpperCase() == "TRUE") { - bcn.className = "btn btn-sm btn-success spinner-grow force-gpu"; - document.getElementById("txtBeacon").setAttribute("class","input-group-text p-1"); - } else { - bcn.className = "btn btn-sm btn-outline-success"; - document.getElementById("txtBeacon").setAttribute("class","input-group-text p-1 text-success text-uppercase"); - } - document.getElementById("beaconInterval").disabled = true; - document.getElementById("stopBeacon").disabled = false; - break; - default: - document.getElementById("txtBeacon").setAttribute("class","input-group-text p-1"); - bcn.className = "btn btn-sm btn-outline-success"; - document.getElementById("beaconInterval").disabled = false; - document.getElementById("stopBeacon").disabled = true; - bcn.disabled = false; - break; - } - // dbfs - // https://www.moellerstudios.org/converting-amplitude-representations/ - if (dbfs_level_raw != arg.dbfs_level){ - dbfs_level_raw = arg.dbfs_level - dbfs_level = Math.pow(10, arg.dbfs_level / 20) * 100 - - document.getElementById("dbfs_level_value").textContent = Math.round(arg.dbfs_level) + ' dBFS' - var dbfscntrl = document.getElementById("dbfs_level"); - dbfscntrl.setAttribute("aria-valuenow", dbfs_level); - dbfscntrl.setAttribute("style", "width:" + dbfs_level + "%;"); - } - - // SET FREQUENCY - // https://stackoverflow.com/a/2901298 - var freq = arg.frequency.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); - document.getElementById("frequency").textContent = freq; - //document.getElementById("newFrequency").value = arg.frequency; - - // SET MODE - document.getElementById("mode").textContent = arg.mode; - - // SET bandwidth - document.getElementById("bandwidth").textContent = arg.bandwidth; - - // SET SPEED LEVEL - switch (arg.speed_level){ - case '0': - document.getElementById("speed_level").className = "bi bi-reception-1"; - break; - case '1': - document.getElementById("speed_level").className = "bi bi-reception-2"; - break; - case '2': - document.getElementById("speed_level").className = "bi bi-reception-3"; - break; - default: - document.getElementById("speed_level").className = "bi bi-reception-4"; - break; - } - - // SET TOTAL BYTES - if (typeof(arg.total_bytes) == 'undefined') { - var total_bytes = 0; - } else { - var total_bytes = arg.total_bytes; - } - document.getElementById("total_bytes").textContent = total_bytes; - - //Check if heard station list has changed - if (typeof(arg.stations) != 'undefined' && arg.stations.length>0 && JSON.stringify(arg.stations) != lastHeard) { - //console.log("Updating last heard stations"); - lastHeard = JSON.stringify(arg.stations); - updateHeardStations(arg); - } - + // SET TOTAL BYTES + if (typeof arg.total_bytes == "undefined") { + var total_bytes = 0; + } else { + var total_bytes = arg.total_bytes; + } + document.getElementById("total_bytes").textContent = total_bytes; + //Check if heard station list has changed + if ( + typeof arg.stations != "undefined" && + arg.stations.length > 0 && + JSON.stringify(arg.stations) != lastHeard + ) { + //console.log("Updating last heard stations"); + lastHeard = JSON.stringify(arg.stations); + updateHeardStations(arg); + } }); function updateHeardStations(arg) { - // UPDATE HEARD STATIONS - - var tbl = document.getElementById("heardstations"); - tbl.innerHTML=""; + // UPDATE HEARD STATIONS - if (typeof(arg.stations) == 'undefined') { - var heardStationsLength = 0; + var tbl = document.getElementById("heardstations"); + tbl.innerHTML = ""; + + if (typeof arg.stations == "undefined") { + var heardStationsLength = 0; + } else { + var heardStationsLength = arg.stations.length; + } + + for (i = 0; i < heardStationsLength; i++) { + // first we update the PING window + if ( + arg.stations[i]["dxcallsign"] == + document.getElementById("dxCall").value.toUpperCase() + ) { + var dxGrid = arg.stations[i]["dxgrid"]; + var myGrid = document.getElementById("myGrid").value; + try { + var dist = parseInt(distance(myGrid, dxGrid)) + " km"; + document.getElementById("dataModalPingDistance").textContent = dist; + } catch { + document.getElementById("dataModalPingDistance").textContent = "---"; + } + document.getElementById("dataModalPingDB").textContent = + arg.stations[i]["snr"]; + } + + // now we update the heard stations list + var row = document.createElement("tr"); + //https://stackoverflow.com/q/51421470 + + //https://stackoverflow.com/a/847196 + timestampRaw = arg.stations[i]["timestamp"]; + var date = new Date(timestampRaw * 1000); + var hours = date.getHours(); + var minutes = "0" + date.getMinutes(); + var seconds = "0" + date.getSeconds(); + var datetime = hours + ":" + minutes.substr(-2) + ":" + seconds.substr(-2); + + var timestamp = document.createElement("td"); + var timestampText = document.createElement("span"); + timestampText.innerText = datetime; + timestamp.appendChild(timestampText); + + var frequency = document.createElement("td"); + var frequencyText = document.createElement("span"); + frequencyText.innerText = arg.stations[i]["frequency"]; + frequency.appendChild(frequencyText); + + var dxCall = document.createElement("td"); + var dxCallText = document.createElement("span"); + dxCallText.innerText = arg.stations[i]["dxcallsign"]; + let dxCallTextCall = dxCallText.innerText; + let dxCallTextShort = dxCallTextCall.split("-", 1)[0]; + row.addEventListener("click", function () { + document.getElementById("dxCall").value = dxCallTextCall; + }); + dxCall.appendChild(dxCallText); + + var dxGrid = document.createElement("td"); + var dxGridText = document.createElement("span"); + dxGridText.innerText = arg.stations[i]["dxgrid"]; + dxGrid.appendChild(dxGridText); + + var gridDistance = document.createElement("td"); + var gridDistanceText = document.createElement("span"); + + try { + if (arg.stations[i]["dxgrid"].toString() != "------") { + gridDistanceText.innerText = + parseInt( + distance( + document.getElementById("myGrid").value, + arg.stations[i]["dxgrid"] + ) + ) + " km"; + } else { + gridDistanceText.innerText = "---"; + } + } catch { + gridDistanceText.innerText = "---"; + } + gridDistance.appendChild(gridDistanceText); + + var dataType = document.createElement("td"); + var dataTypeText = document.createElement("span"); + dataTypeText.innerText = arg.stations[i]["datatype"]; + dataType.appendChild(dataTypeText); + + switch (dataTypeText.innerText) { + case "CQ CQ CQ": + dataTypeText.textContent = "CQ CQ"; + row.classList.add("table-success"); + break; + case "DATA-CHANNEL": + dataTypeText.innerHTML = + ''; + row.classList.add("table-warning"); + break; + case "BEACON": + dataTypeText.textContent = "BCN"; + row.classList.add("table-light"); + break; + case "PING": + row.classList.add("table-info"); + break; + case "PING-ACK": + row.classList.add("table-primary"); + break; + case "SESSION-HB": + dataTypeText.innerHTML = + ''; + //dataType.appendChild(dataTypeText); + break; + } + var snr = document.createElement("td"); + var snrText = document.createElement("span"); + snrText.innerText = arg.stations[i]["snr"]; + snr.appendChild(snrText); + + var offset = document.createElement("td"); + var offsetText = " "; + if (contrib.indexOf(dxCallTextShort) >= 0) { + var offsetText = + ''; } else { - var heardStationsLength = arg.stations.length; + if (dxCallTextShort == "DJ2LS") { + var offsetText = + ''; + } } + offset.innerHTML = offsetText; - for (i = 0; i < heardStationsLength; i++) { + row.appendChild(timestamp); + row.appendChild(frequency); + row.appendChild(offset); + row.appendChild(dxCall); + row.appendChild(dxGrid); + row.appendChild(gridDistance); + row.appendChild(dataType); + row.appendChild(snr); - // first we update the PING window - if (arg.stations[i]['dxcallsign'] == document.getElementById("dxCall").value.toUpperCase()) { - var dxGrid = arg.stations[i]['dxgrid']; - var myGrid = document.getElementById("myGrid").value; - try { - var dist = parseInt(distance(myGrid, dxGrid)) + ' km'; - document.getElementById("dataModalPingDistance").textContent = dist; - } catch { - document.getElementById("dataModalPingDistance").textContent = '---'; - } - document.getElementById("dataModalPingDB").textContent = arg.stations[i]['snr']; - } - - // now we update the heard stations list - var row = document.createElement("tr"); - //https://stackoverflow.com/q/51421470 - - //https://stackoverflow.com/a/847196 - timestampRaw = arg.stations[i]['timestamp']; - var date = new Date(timestampRaw * 1000); - var hours = date.getHours(); - var minutes = "0" + date.getMinutes(); - var seconds = "0" + date.getSeconds(); - var datetime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); - - var timestamp = document.createElement("td"); - var timestampText = document.createElement('span'); - timestampText.innerText = datetime; - timestamp.appendChild(timestampText); - - var frequency = document.createElement("td"); - var frequencyText = document.createElement('span'); - frequencyText.innerText = arg.stations[i]['frequency']; - frequency.appendChild(frequencyText); - - var dxCall = document.createElement("td"); - var dxCallText = document.createElement('span'); - dxCallText.innerText = arg.stations[i]['dxcallsign']; - let dxCallTextCall = dxCallText.innerText; - let dxCallTextShort = dxCallTextCall.split("-",1)[0]; - row.addEventListener("click", function() { - document.getElementById("dxCall").value = dxCallTextCall; - }); - dxCall.appendChild(dxCallText); - - var dxGrid = document.createElement("td"); - var dxGridText = document.createElement('span'); - dxGridText.innerText = arg.stations[i]['dxgrid']; - dxGrid.appendChild(dxGridText); - - var gridDistance = document.createElement("td"); - var gridDistanceText = document.createElement('span'); - - try { - if (arg.stations[i]['dxgrid'].toString() != "------") { - gridDistanceText.innerText = parseInt(distance(document.getElementById("myGrid").value, arg.stations[i]['dxgrid'])) + ' km'; - } else { - gridDistanceText.innerText = '---'; - } - } catch { - gridDistanceText.innerText = '---'; - } - gridDistance.appendChild(gridDistanceText); - - var dataType = document.createElement("td"); - var dataTypeText = document.createElement('span'); - dataTypeText.innerText = arg.stations[i]['datatype']; - dataType.appendChild(dataTypeText); - - switch (dataTypeText.innerText){ - case 'CQ CQ CQ': - dataTypeText.textContent="CQ CQ"; - row.classList.add("table-success"); - break; - case 'DATA-CHANNEL': - dataTypeText.innerHTML = ''; - row.classList.add("table-warning"); - break; - case 'BEACON': - dataTypeText.textContent="BCN"; - row.classList.add("table-light"); - break; - case 'PING': - row.classList.add("table-info"); - break; - case 'PING-ACK': - row.classList.add("table-primary"); - break; - case 'SESSION-HB': - dataTypeText.innerHTML = ''; - //dataType.appendChild(dataTypeText); - break; - } - var snr = document.createElement("td"); - var snrText = document.createElement('span'); - snrText.innerText = arg.stations[i]['snr']; - snr.appendChild(snrText); - - var offset = document.createElement("td"); - var offsetText = " "; - if (contrib.indexOf(dxCallTextShort) >=0) { - var offsetText =''; - } - else { - if (dxCallTextShort == "DJ2LS") { - var offsetText =''; - } - } - offset.innerHTML=offsetText; - - row.appendChild(timestamp); - row.appendChild(frequency); - row.appendChild(offset); - row.appendChild(dxCall); - row.appendChild(dxGrid); - row.appendChild(gridDistance); - row.appendChild(dataType); - row.appendChild(snr); - - tbl.appendChild(row); - } + tbl.appendChild(row); + } } -ipcRenderer.on('action-update-daemon-state', (event, arg) => { - /* +ipcRenderer.on("action-update-daemon-state", (event, arg) => { + /* // deactivetd RAM und CPU view so we dont get errors. We need to find a new place for this feature // RAM document.getElementById("progressbar_ram").setAttribute("aria-valuenow", arg.ram_usage) @@ -2250,153 +2123,161 @@ ipcRenderer.on('action-update-daemon-state', (event, arg) => { document.getElementById("progressbar_cpu").setAttribute("style", "width:" + arg.cpu_usage + "%;") document.getElementById("progressbar_cpu_value").innerHTML = arg.cpu_usage + "%" */ - /* + /* document.getElementById("ram_load").innerHTML = arg.ram_usage + "%" document.getElementById("cpu_load").innerHTML = arg.cpu_usage + "%" */ - // OPERATING SYSTEM - //document.getElementById("operating_system").innerHTML = "OS " + os.type() + // OPERATING SYSTEM + //document.getElementById("operating_system").innerHTML = "OS " + os.type() - /* + /* // PYTHON VERSION document.getElementById("python_version").innerHTML = "Python " + arg.python_version document.getElementById("python_version").className = "btn btn-sm btn-success"; */ - /* + /* // HAMLIB VERSION document.getElementById("hamlib_version").innerHTML = "Hamlib " + arg.hamlib_version document.getElementById("hamlib_version").className = "btn btn-sm btn-success"; */ - /* + /* // NODE VERSION document.getElementById("node_version").innerHTML = "Node " + process.version document.getElementById("node_version").className = "btn btn-sm btn-success"; */ - - // UPDATE AUDIO INPUT - if (arg.tnc_running_state == "stopped") { - if (document.getElementById("audio_input_selectbox").length != arg.input_devices.length) { - document.getElementById("audio_input_selectbox").innerHTML = ""; - for (i = 0; i < arg.input_devices.length; i++) { - var option = document.createElement("option"); - option.text = arg.input_devices[i]['name']; - option.value = arg.input_devices[i]['id']; - // set device from config if available - - if(config.rx_audio == option.text){ - option.setAttribute('selected', true); - } - document.getElementById("audio_input_selectbox").add(option); - } - } - } - // UPDATE AUDIO OUTPUT - if (arg.tnc_running_state == "stopped") { - if (document.getElementById("audio_output_selectbox").length != arg.output_devices.length) { - document.getElementById("audio_output_selectbox").innerHTML = ""; - for (i = 0; i < arg.output_devices.length; i++) { - var option = document.createElement("option"); - option.text = arg.output_devices[i]['name']; - option.value = arg.output_devices[i]['id']; - // set device from config if available - if(config.tx_audio == option.text){ - option.setAttribute('selected', true); - } - document.getElementById("audio_output_selectbox").add(option); - } - } - } - // UPDATE SERIAL DEVICES - if (arg.tnc_running_state == "stopped") { - if (document.getElementById("hamlib_deviceport").length != arg.serial_devices.length) { - document.getElementById("hamlib_deviceport").innerHTML = ""; - for (i = 0; i < arg.serial_devices.length; i++) { - var option = document.createElement("option"); - option.text = arg.serial_devices[i]['port'] + ' -- ' + arg.serial_devices[i]['description']; - option.value = arg.serial_devices[i]['port']; - // set device from config if available - if(config.hamlib_deviceport == option.value){ - option.setAttribute('selected', true); - } - document.getElementById("hamlib_deviceport").add(option); - - } + // UPDATE AUDIO INPUT + if (arg.tnc_running_state == "stopped") { + if ( + document.getElementById("audio_input_selectbox").length != + arg.input_devices.length + ) { + document.getElementById("audio_input_selectbox").innerHTML = ""; + for (i = 0; i < arg.input_devices.length; i++) { + var option = document.createElement("option"); + option.text = arg.input_devices[i]["name"]; + option.value = arg.input_devices[i]["id"]; + // set device from config if available + + if (config.rx_audio == option.text) { + option.setAttribute("selected", true); } - - - + document.getElementById("audio_input_selectbox").add(option); + } } - - if (arg.tnc_running_state == "stopped") { - if (document.getElementById("hamlib_ptt_port").length != arg.serial_devices.length) { - document.getElementById("hamlib_ptt_port").innerHTML = ""; - for (i = 0; i < arg.serial_devices.length; i++) { - var option = document.createElement("option"); - option.text = arg.serial_devices[i]['description']; - option.value = arg.serial_devices[i]['port']; - // set device from config if available - if(config.hamlib_pttport == option.value){ - option.setAttribute('selected', true); - } - document.getElementById("hamlib_ptt_port").add(option); - } - } + } + // UPDATE AUDIO OUTPUT + if (arg.tnc_running_state == "stopped") { + if ( + document.getElementById("audio_output_selectbox").length != + arg.output_devices.length + ) { + document.getElementById("audio_output_selectbox").innerHTML = ""; + for (i = 0; i < arg.output_devices.length; i++) { + var option = document.createElement("option"); + option.text = arg.output_devices[i]["name"]; + option.value = arg.output_devices[i]["id"]; + // set device from config if available + if (config.tx_audio == option.text) { + option.setAttribute("selected", true); + } + document.getElementById("audio_output_selectbox").add(option); + } } - - + } + + // UPDATE SERIAL DEVICES + if (arg.tnc_running_state == "stopped") { + if ( + document.getElementById("hamlib_deviceport").length != + arg.serial_devices.length + ) { + document.getElementById("hamlib_deviceport").innerHTML = ""; + var ignore = document.createElement("option"); + ignore.text = "-- ignore --"; + ignore.value = "ignore"; + document.getElementById("hamlib_deviceport").add(ignore); + for (i = 0; i < arg.serial_devices.length; i++) { + var option = document.createElement("option"); + option.text = + arg.serial_devices[i]["port"] + + " -- " + + arg.serial_devices[i]["description"]; + option.value = arg.serial_devices[i]["port"]; + document.getElementById("hamlib_deviceport").add(option); + } + // set device from config if available + document.getElementById("hamlib_deviceport").value = + config.hamlib_deviceport; + } + } + + if (arg.tnc_running_state == "stopped") { + if ( + document.getElementById("hamlib_ptt_port").length != + arg.serial_devices.length + ) { + document.getElementById("hamlib_ptt_port").innerHTML = ""; + var ignore = document.createElement("option"); + ignore.text = "-- ignore --"; + ignore.value = "ignore"; + document.getElementById("hamlib_ptt_port").add(ignore); + for (i = 0; i < arg.serial_devices.length; i++) { + var option = document.createElement("option"); + option.text = + arg.serial_devices[i]["port"] + + " -- " + + arg.serial_devices[i]["description"]; + option.value = arg.serial_devices[i]["port"]; + document.getElementById("hamlib_ptt_port").add(option); + } + // set device from config if available + document.getElementById("hamlib_ptt_port").value = config.hamlib_ptt_port; + } + } }); - // ACTION UPDATE HAMLIB TEST -ipcRenderer.on('action-update-hamlib-test', (event, arg) => { - console.log(arg.hamlib_result); - if (arg.hamlib_result == 'SUCCESS') { - document.getElementById("testHamlib").className = "btn btn-sm btn-success"; - // BUTTON HAS BEEN REMOVED - //document.getElementById("testHamlibAdvanced").className = "btn btn-sm btn-success"; - - - } - if (arg.hamlib_result == 'NOSUCCESS') { - document.getElementById("testHamlib").className = "btn btn-sm btn-warning"; - // BUTTON HAS BEEN REMOVED - //document.getElementById("testHamlibAdvanced").className = "btn btn-sm btn-warning"; - - } - if (arg.hamlib_result == 'FAILED') { - document.getElementById("testHamlib").className = "btn btn-sm btn-danger"; - // BUTTON HAS BEEN REMOVED - //document.getElementById("testHamlibAdvanced").className = "btn btn-sm btn-danger"; - } - +ipcRenderer.on("action-update-hamlib-test", (event, arg) => { + console.log(arg.hamlib_result); + if (arg.hamlib_result == "SUCCESS") { + document.getElementById("testHamlib").className = "btn btn-sm btn-success"; + // BUTTON HAS BEEN REMOVED + //document.getElementById("testHamlibAdvanced").className = "btn btn-sm btn-success"; + } + if (arg.hamlib_result == "NOSUCCESS") { + document.getElementById("testHamlib").className = "btn btn-sm btn-warning"; + // BUTTON HAS BEEN REMOVED + //document.getElementById("testHamlibAdvanced").className = "btn btn-sm btn-warning"; + } + if (arg.hamlib_result == "FAILED") { + document.getElementById("testHamlib").className = "btn btn-sm btn-danger"; + // BUTTON HAS BEEN REMOVED + //document.getElementById("testHamlibAdvanced").className = "btn btn-sm btn-danger"; + } }); - - -ipcRenderer.on('action-update-daemon-connection', (event, arg) => { - - if (arg.daemon_connection == 'open') { - document.getElementById("daemon_connection_state").className = "btn btn-success"; - //document.getElementById("blurdiv").style.webkitFilter = "blur(0px)"; - - } - if (arg.daemon_connection == 'opening') { - document.getElementById("daemon_connection_state").className = "btn btn-warning"; - //document.getElementById("blurdiv").style.webkitFilter = "blur(10px)"; - - } - if (arg.daemon_connection == 'closed') { - document.getElementById("daemon_connection_state").className = "btn btn-danger"; - //document.getElementById("blurdiv").style.webkitFilter = "blur(10px)"; - } - +ipcRenderer.on("action-update-daemon-connection", (event, arg) => { + if (arg.daemon_connection == "open") { + document.getElementById("daemon_connection_state").className = + "btn btn-success"; + //document.getElementById("blurdiv").style.webkitFilter = "blur(0px)"; + } + if (arg.daemon_connection == "opening") { + document.getElementById("daemon_connection_state").className = + "btn btn-warning"; + //document.getElementById("blurdiv").style.webkitFilter = "blur(10px)"; + } + if (arg.daemon_connection == "closed") { + document.getElementById("daemon_connection_state").className = + "btn btn-danger"; + //document.getElementById("blurdiv").style.webkitFilter = "blur(10px)"; + } }); -ipcRenderer.on('action-update-tnc-connection', (event, arg) => { - - if (arg.tnc_connection == "open") { - /* +ipcRenderer.on("action-update-tnc-connection", (event, arg) => { + if (arg.tnc_connection == "open") { + /* document.getElementById('hamlib_deviceid').disabled = true; document.getElementById('hamlib_deviceport').disabled = true; document.getElementById('testHamlib').disabled = true; @@ -2410,21 +2291,32 @@ ipcRenderer.on('action-update-tnc-connection', (event, arg) => { document.getElementById("openDataModule").disabled = false; */ - // collapse settings screen - var collapseFirstRow = new bootstrap.Collapse(document.getElementById('collapseFirstRow'), {toggle: false}) - collapseFirstRow.hide(); - var collapseSecondRow = new bootstrap.Collapse(document.getElementById('collapseSecondRow'), {toggle: false}) - collapseSecondRow.hide(); - var collapseThirdRow = new bootstrap.Collapse(document.getElementById('collapseThirdRow'), {toggle: false}) - collapseThirdRow.show(); - var collapseFourthRow = new bootstrap.Collapse(document.getElementById('collapseFourthRow'), {toggle: false}) - collapseFourthRow.show(); + // collapse settings screen + var collapseFirstRow = new bootstrap.Collapse( + document.getElementById("collapseFirstRow"), + { toggle: false } + ); + collapseFirstRow.hide(); + var collapseSecondRow = new bootstrap.Collapse( + document.getElementById("collapseSecondRow"), + { toggle: false } + ); + collapseSecondRow.hide(); + var collapseThirdRow = new bootstrap.Collapse( + document.getElementById("collapseThirdRow"), + { toggle: false } + ); + collapseThirdRow.show(); + var collapseFourthRow = new bootstrap.Collapse( + document.getElementById("collapseFourthRow"), + { toggle: false } + ); + collapseFourthRow.show(); - //Set tuning for fancy graphics mode (high/low CPU) - set_CPU_mode(); - - } else { - /* + //Set tuning for fancy graphics mode (high/low CPU) + set_CPU_mode(); + } else { + /* document.getElementById('hamlib_deviceid').disabled = false; document.getElementById('hamlib_deviceport').disabled = false; document.getElementById('testHamlib').disabled = false; @@ -2437,552 +2329,767 @@ ipcRenderer.on('action-update-tnc-connection', (event, arg) => { document.getElementById("hamlib_serialspeed").disabled = false; document.getElementById("openDataModule").disabled = true; */ - // collapse settings screen - var collapseFirstRow = new bootstrap.Collapse(document.getElementById('collapseFirstRow'), {toggle: false}) - collapseFirstRow.show(); - var collapseSecondRow = new bootstrap.Collapse(document.getElementById('collapseSecondRow'), {toggle: false}) - collapseSecondRow.show(); - var collapseThirdRow = new bootstrap.Collapse(document.getElementById('collapseThirdRow'), {toggle: false}) - collapseThirdRow.hide(); - var collapseFourthRow = new bootstrap.Collapse(document.getElementById('collapseFourthRow'), {toggle: false}) - collapseFourthRow.hide(); - } - - - - - - + // collapse settings screen + var collapseFirstRow = new bootstrap.Collapse( + document.getElementById("collapseFirstRow"), + { toggle: false } + ); + collapseFirstRow.show(); + var collapseSecondRow = new bootstrap.Collapse( + document.getElementById("collapseSecondRow"), + { toggle: false } + ); + collapseSecondRow.show(); + var collapseThirdRow = new bootstrap.Collapse( + document.getElementById("collapseThirdRow"), + { toggle: false } + ); + collapseThirdRow.hide(); + var collapseFourthRow = new bootstrap.Collapse( + document.getElementById("collapseFourthRow"), + { toggle: false } + ); + collapseFourthRow.hide(); + } }); +ipcRenderer.on("action-update-rx-buffer", (event, arg) => { + var data = arg.data["data"]; -ipcRenderer.on('action-update-rx-buffer', (event, arg) => { - - var data = arg.data["data"]; + var tbl = document.getElementById("rx-data"); + document.getElementById("rx-data").innerHTML = ""; - var tbl = document.getElementById("rx-data"); - document.getElementById("rx-data").innerHTML = ''; - - - for (i = 0; i < arg.data.length; i++) { - - // first we update the PING window - if (arg.data[i]['dxcallsign'] == document.getElementById("dxCall").value.toUpperCase()) { - /* - // if we are sending data without doing a ping before, we don't have a grid locator available. This could be a future feature for the TNC! - if(arg.data[i]['DXGRID'] != ''){ - document.getElementById("pingDistance").innerHTML = arg.stations[i]['DXGRID'] - } - */ - //document.getElementById("pingDB").innerHTML = arg.stations[i]['snr']; - document.getElementById("dataModalPingDB").innerHTML = arg.stations[i]['snr']; + for (i = 0; i < arg.data.length; i++) { + // first we update the PING window + if ( + arg.data[i]["dxcallsign"] == + document.getElementById("dxCall").value.toUpperCase() + ) { + /* + // if we are sending data without doing a ping before, we don't have a grid locator available. This could be a future feature for the TNC! + if(arg.data[i]['DXGRID'] != ''){ + document.getElementById("pingDistance").innerHTML = arg.stations[i]['DXGRID'] } - - - - // now we update the received files list - - var row = document.createElement("tr"); - //https://stackoverflow.com/q/51421470 - - //https://stackoverflow.com/a/847196 - timestampRaw = arg.data[i]['timestamp'] - var date = new Date(timestampRaw * 1000); - var hours = date.getHours(); - var minutes = "0" + date.getMinutes(); - var seconds = "0" + date.getSeconds(); - var datetime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); - - var timestamp = document.createElement("td"); - var timestampText = document.createElement('span'); - timestampText.innerText = datetime; - timestamp.appendChild(timestampText); - - var dxCall = document.createElement("td"); - var dxCallText = document.createElement('span'); - dxCallText.innerText = arg.data[i]['dxcallsign']; - dxCall.appendChild(dxCallText); - - /* - var dxGrid = document.createElement("td"); - var dxGridText = document.createElement('span'); - dxGridText.innerText = arg.data[i]['DXGRID'] - dxGrid.appendChild(dxGridText); */ - - console.log(arg.data); - - var encoded_data = atob(arg.data[i]['data']); - var splitted_data = encoded_data.split(split_char); - console.log(splitted_data); - - var fileName = document.createElement("td"); - var fileNameText = document.createElement('span'); - //var fileNameString = arg.data[i]['data'][0]['fn']; - var fileNameString = splitted_data[1]; - - - fileNameText.innerText = fileNameString; - fileName.appendChild(fileNameText); - - row.appendChild(timestamp); - row.appendChild(dxCall); - // row.appendChild(dxGrid); - row.appendChild(fileName); - tbl.appendChild(row); - - // https://stackoverflow.com/a/26227660 - //var appDataFolder = process.env.HOME; - //console.log("appDataFolder:" + appDataFolder); - //var applicationFolder = path.join(appDataFolder, "FreeDATA"); - //console.log(applicationFolder); - //var receivedFilesFolder = path.join(applicationFolder, "receivedFiles"); - var receivedFilesFolder = path.join(config.received_files_folder); - - console.log("receivedFilesFolder: " + receivedFilesFolder); - // Creates receivedFiles folder if not exists - // https://stackoverflow.com/a/13544465 - fs.mkdir(receivedFilesFolder, { - recursive: true - }, function(err) { - console.log(err); - }); - - - // write file to data folder - ////var base64String = arg.data[i]['data'][0]['d'] - // remove header from base64 String - // https://www.codeblocq.com/2016/04/Convert-a-base64-string-to-a-file-in-Node/ - ////var base64Data = base64String.split(';base64,').pop() - //write data to file - var base64Data = splitted_data[4]; - var receivedFile = path.join(receivedFilesFolder, fileNameString); - console.log(receivedFile); - - require("fs").writeFile(receivedFile, base64Data, 'binary', function(err) { - //require("fs").writeFile(receivedFile, base64Data, 'base64', function(err) { - console.log(err); - }); + //document.getElementById("pingDB").innerHTML = arg.stations[i]['snr']; + document.getElementById("dataModalPingDB").innerHTML = + arg.stations[i]["snr"]; } + + // now we update the received files list + + var row = document.createElement("tr"); + //https://stackoverflow.com/q/51421470 + + //https://stackoverflow.com/a/847196 + timestampRaw = arg.data[i]["timestamp"]; + var date = new Date(timestampRaw * 1000); + var hours = date.getHours(); + var minutes = "0" + date.getMinutes(); + var seconds = "0" + date.getSeconds(); + var datetime = hours + ":" + minutes.substr(-2) + ":" + seconds.substr(-2); + + var timestamp = document.createElement("td"); + var timestampText = document.createElement("span"); + timestampText.innerText = datetime; + timestamp.appendChild(timestampText); + + var dxCall = document.createElement("td"); + var dxCallText = document.createElement("span"); + dxCallText.innerText = arg.data[i]["dxcallsign"]; + dxCall.appendChild(dxCallText); + + /* + var dxGrid = document.createElement("td"); + var dxGridText = document.createElement('span'); + dxGridText.innerText = arg.data[i]['DXGRID'] + dxGrid.appendChild(dxGridText); + */ + + console.log(arg.data); + + var encoded_data = atob(arg.data[i]["data"]); + var splitted_data = encoded_data.split(split_char); + console.log(splitted_data); + + var fileName = document.createElement("td"); + var fileNameText = document.createElement("span"); + //var fileNameString = arg.data[i]['data'][0]['fn']; + var fileNameString = splitted_data[1]; + + fileNameText.innerText = fileNameString; + fileName.appendChild(fileNameText); + + row.appendChild(timestamp); + row.appendChild(dxCall); + // row.appendChild(dxGrid); + row.appendChild(fileName); + tbl.appendChild(row); + + // https://stackoverflow.com/a/26227660 + //var appDataFolder = process.env.HOME; + //console.log("appDataFolder:" + appDataFolder); + //var applicationFolder = path.join(appDataFolder, "FreeDATA"); + //console.log(applicationFolder); + //var receivedFilesFolder = path.join(applicationFolder, "receivedFiles"); + var receivedFilesFolder = path.join(config.received_files_folder); + + console.log("receivedFilesFolder: " + receivedFilesFolder); + // Creates receivedFiles folder if not exists + // https://stackoverflow.com/a/13544465 + fs.mkdir( + receivedFilesFolder, + { + recursive: true, + }, + function (err) { + console.log(err); + } + ); + + // write file to data folder + ////var base64String = arg.data[i]['data'][0]['d'] + // remove header from base64 String + // https://www.codeblocq.com/2016/04/Convert-a-base64-string-to-a-file-in-Node/ + ////var base64Data = base64String.split(';base64,').pop() + //write data to file + var base64Data = splitted_data[4]; + var receivedFile = path.join(receivedFilesFolder, fileNameString); + console.log(receivedFile); + + require("fs").writeFile(receivedFile, base64Data, "binary", function (err) { + //require("fs").writeFile(receivedFile, base64Data, 'base64', function(err) { + console.log(err); + }); + } +}); +ipcRenderer.on("run-tnc-command-fec-iswriting", (event) => { + //console.log("Sending sendFecIsWriting"); + sock.sendFecIsWriting(config.mycall); }); -ipcRenderer.on('run-tnc-command', (event, arg) => { +ipcRenderer.on("run-tnc-command", (event, arg) => { + if (arg.command == "save_my_call") { + sock.saveMyCall(arg.callsign); + } + if (arg.command == "save_my_grid") { + sock.saveMyGrid(arg.grid); + } + if (arg.command == "ping") { + sock.sendPing(arg.dxcallsign); + } - if (arg.command == 'save_my_call') { - sock.saveMyCall(arg.callsign); - } - if (arg.command == 'save_my_grid') { - sock.saveMyGrid(arg.grid); - } - if (arg.command == 'ping') { - sock.sendPing(arg.dxcallsign); - } + if (arg.command == "send_file") { + sock.sendFile( + arg.dxcallsign, + arg.mode, + arg.frames, + arg.filename, + arg.filetype, + arg.data, + arg.checksum + ); + } + if (arg.command == "send_message") { + sock.sendMessage( + arg.dxcallsign, + arg.mode, + arg.frames, + arg.data, + arg.checksum, + arg.uuid, + arg.command + ); + } + if (arg.command == "stop_transmission") { + sock.stopTransmission(); + } + if (arg.command == "set_tx_audio_level") { + sock.setTxAudioLevel(arg.tx_audio_level); + } + if (arg.command == "record_audio") { + sock.record_audio(); + } + if (arg.command == "send_test_frame") { + sock.sendTestFrame(); + } - if (arg.command == 'send_file') { - sock.sendFile(arg.dxcallsign, arg.mode, arg.frames, arg.filename, arg.filetype, arg.data, arg.checksum); - } - if (arg.command == 'send_message') { - sock.sendMessage(arg.dxcallsign, arg.mode, arg.frames, arg.data, arg.checksum, arg.uuid, arg.command); - } - if (arg.command == 'stop_transmission') { - sock.stopTransmission(); - } - if (arg.command == 'set_tx_audio_level') { - sock.setTxAudioLevel(arg.tx_audio_level); - } - if (arg.command == 'record_audio') { - sock.record_audio(); - } - if (arg.command == 'send_test_frame') { - sock.sendTestFrame(); - } - - if (arg.command == 'frequency') { - sock.set_frequency(arg.frequency); - } - - if (arg.command == 'mode') { - sock.set_mode(arg.mode); - } - + if (arg.command == "frequency") { + sock.set_frequency(arg.frequency); + } + if (arg.command == "mode") { + sock.set_mode(arg.mode); + } }); // IPC ACTION FOR AUTO UPDATER -ipcRenderer.on('action-updater', (event, arg) => { +ipcRenderer.on("action-updater", (event, arg) => { + if (arg.status == "download-progress") { + var progressinfo = + "(" + + Math.round(arg.progress.transferred / 1024) + + "kB /" + + Math.round(arg.progress.total / 1024) + + "kB)" + + " @ " + + Math.round(arg.progress.bytesPerSecond / 1024) + + "kByte/s"; + document.getElementById("UpdateProgressInfo").innerHTML = progressinfo; - if (arg.status == "download-progress"){ - - var progressinfo = '(' - + Math.round(arg.progress.transferred/1024) - + 'kB /' - + Math.round(arg.progress.total/1024) - + 'kB)' - + ' @ ' - + Math.round(arg.progress.bytesPerSecond/1024) - + "kByte/s";; - document.getElementById("UpdateProgressInfo").innerHTML = progressinfo; - - document.getElementById("UpdateProgressBar").setAttribute("aria-valuenow", arg.progress.percent) - document.getElementById("UpdateProgressBar").setAttribute("style", "width:" + arg.progress.percent + "%;") - - - } + document + .getElementById("UpdateProgressBar") + .setAttribute("aria-valuenow", arg.progress.percent); + document + .getElementById("UpdateProgressBar") + .setAttribute("style", "width:" + arg.progress.percent + "%;"); + } - if (arg.status == "checking-for-update"){ - - //document.title = document.title + ' - v' + arg.version; - updateTitle(config.myCall,config.tnc_host,config.tnc_port, " -v " + arg.version); - document.getElementById("updater_status").innerHTML = '' - - document.getElementById("updater_status").className = "btn btn-secondary btn-sm"; - document.getElementById("update_and_install").style.display = 'none'; - } - if (arg.status == "update-downloaded"){ + if (arg.status == "checking-for-update") { + //document.title = document.title + ' - v' + arg.version; + updateTitle( + config.myCall, + config.tnc_host, + config.tnc_port, + " -v " + arg.version + ); + document.getElementById("updater_status").innerHTML = + ''; - - document.getElementById("update_and_install").removeAttribute("style"); - document.getElementById("updater_status").innerHTML = ''; - document.getElementById("updater_status").className = "btn btn-success btn-sm"; - - // HERE WE NEED TO RUN THIS SOMEHOW... - //mainLog.info('quit application and install update'); - //autoUpdater.quitAndInstall(); - - } - if (arg.status == "update-not-available"){ + document.getElementById("updater_status").className = + "btn btn-secondary btn-sm"; + document.getElementById("update_and_install").style.display = "none"; + } + if (arg.status == "update-downloaded") { + document.getElementById("update_and_install").removeAttribute("style"); + document.getElementById("updater_status").innerHTML = + ''; + document.getElementById("updater_status").className = + "btn btn-success btn-sm"; - document.getElementById("updater_status").innerHTML = ''; - document.getElementById("updater_status").className = "btn btn-success btn-sm"; - document.getElementById("update_and_install").style.display = 'none'; - } - if (arg.status == "update-available"){ - - document.getElementById("updater_status").innerHTML = ''; - document.getElementById("updater_status").className = "btn btn-warning btn-sm"; - document.getElementById("update_and_install").style.display = 'none'; - - } - - if (arg.status == "error"){ - - document.getElementById("updater_status").innerHTML = ''; - document.getElementById("updater_status").className = "btn btn-danger btn-sm"; - document.getElementById("update_and_install").style.display = 'none'; - } - - + // HERE WE NEED TO RUN THIS SOMEHOW... + //mainLog.info('quit application and install update'); + //autoUpdater.quitAndInstall(); + } + if (arg.status == "update-not-available") { + document.getElementById("updater_status").innerHTML = + ''; + document.getElementById("updater_status").className = + "btn btn-success btn-sm"; + document.getElementById("update_and_install").style.display = "none"; + } + if (arg.status == "update-available") { + document.getElementById("updater_status").innerHTML = + ''; + document.getElementById("updater_status").className = + "btn btn-warning btn-sm"; + document.getElementById("update_and_install").style.display = "none"; + } + if (arg.status == "error") { + document.getElementById("updater_status").innerHTML = + ''; + document.getElementById("updater_status").className = + "btn btn-danger btn-sm"; + document.getElementById("update_and_install").style.display = "none"; + } }); - - // ----------- INFO MODAL ACTIONS ------------------------------- // CQ TRANSMITTING -ipcRenderer.on('action-show-cq-toast-transmitting', (event, data) => { - displayToast(type='success', icon='bi-broadcast', content='transmitting cq', duration=5000); +ipcRenderer.on("action-show-cq-toast-transmitting", (event, data) => { + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = "transmitting cq"), + (duration = 5000) + ); +}); +// fec iswriting received +ipcRenderer.on("action-show-fec-toast-iswriting", (event, data) => { + let dxcallsign = data["data"][0]["dxcallsign"]; + let content = `${dxcallsign} is typing`; + displayToast( + (type = "success"), + (icon = "bi-pencil-fill"), + (content = content), + (duration = 5000) + ); }); - // CQ RECEIVED -ipcRenderer.on('action-show-cq-toast-received', (event, data) => { - let dxcallsign = data["data"][0]["dxcallsign"] - let dxgrid = data["data"][0]["dxgrid"] - let content = `cq from ${dxcallsign} (${dxgrid})` +ipcRenderer.on("action-show-cq-toast-received", (event, data) => { + let dxcallsign = data["data"][0]["dxcallsign"]; + let dxgrid = data["data"][0]["dxgrid"]; + let content = `cq from ${dxcallsign} (${dxgrid})`; - displayToast(type='success', icon='bi-broadcast', content=content, duration=5000); + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = content), + (duration = 5000) + ); }); // QRV TRANSMITTING -ipcRenderer.on('action-show-qrv-toast-transmitting', (event, data) => { - displayToast(type='success', icon='bi-broadcast', content='transmitting qrv', duration=5000); +ipcRenderer.on("action-show-qrv-toast-transmitting", (event, data) => { + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = "transmitting qrv"), + (duration = 5000) + ); }); // QRV RECEIVED -ipcRenderer.on('action-show-qrv-toast-received', (event, data) => { +ipcRenderer.on("action-show-qrv-toast-received", (event, data) => { + console.log(data["data"][0]); + let dxcallsign = data["data"][0]["dxcallsign"]; + let dxgrid = data["data"][0]["dxgrid"]; + let content = `received qrv from ${dxcallsign} (${dxgrid})`; - console.log(data["data"][0]) - let dxcallsign = data["data"][0]["dxcallsign"] - let dxgrid = data["data"][0]["dxgrid"] - let content = `received qrv from ${dxcallsign} (${dxgrid})` - - displayToast(type='success', icon='bi-broadcast', content=content, duration=5000); + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = content), + (duration = 5000) + ); }); // BEACON TRANSMITTING -ipcRenderer.on('action-show-beacon-toast-transmitting', (event, data) => { - displayToast(type='info', icon='bi-broadcast', content='transmitting beacon', duration=5000); +ipcRenderer.on("action-show-beacon-toast-transmitting", (event, data) => { + displayToast( + (type = "info"), + (icon = "bi-broadcast"), + (content = "transmitting beacon"), + (duration = 5000) + ); }); // BEACON RECEIVED -ipcRenderer.on('action-show-beacon-toast-received', (event, data) => { - console.log(data["data"][0]) - let dxcallsign = data["data"][0]["dxcallsign"] - let dxgrid = data["data"][0]["dxgrid"] - let content = `beacon from ${dxcallsign} (${dxgrid})` - displayToast(type='info', icon='bi-broadcast', content=content, duration=5000); +ipcRenderer.on("action-show-beacon-toast-received", (event, data) => { + console.log(data["data"][0]); + let dxcallsign = data["data"][0]["dxcallsign"]; + let dxgrid = data["data"][0]["dxgrid"]; + let content = `beacon from ${dxcallsign} (${dxgrid})`; + displayToast( + (type = "info"), + (icon = "bi-broadcast"), + (content = content), + (duration = 5000) + ); }); // PING TRANSMITTING -ipcRenderer.on('action-show-ping-toast-transmitting', (event, data) => { - displayToast(type='success', icon='bi-broadcast', content='transmitting ping', duration=5000); +ipcRenderer.on("action-show-ping-toast-transmitting", (event, data) => { + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = "transmitting ping"), + (duration = 5000) + ); }); // PING RECEIVED -ipcRenderer.on('action-show-ping-toast-received', (event, data) => { - console.log(data["data"][0]) - let dxcallsign = data["data"][0]["dxcallsign"] - let content = `ping from ${dxcallsign}` - displayToast(type='success', icon='bi-broadcast', content=content, duration=5000); +ipcRenderer.on("action-show-ping-toast-received", (event, data) => { + console.log(data["data"][0]); + let dxcallsign = data["data"][0]["dxcallsign"]; + let content = `ping from ${dxcallsign}`; + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = content), + (duration = 5000) + ); }); // PING RECEIVED ACK -ipcRenderer.on('action-show-ping-toast-received-ack', (event, data) => { - console.log(data["data"][0]) - let dxcallsign = data["data"][0]["dxcallsign"] - let dxgrid = data["data"][0]["dxgrid"] - let content = `ping ACK from ${dxcallsign} (${dxgrid})` - displayToast(type='success', icon='bi-check', content=content, duration=5000); +ipcRenderer.on("action-show-ping-toast-received-ack", (event, data) => { + console.log(data["data"][0]); + let dxcallsign = data["data"][0]["dxcallsign"]; + let dxgrid = data["data"][0]["dxgrid"]; + let content = `ping ACK from ${dxcallsign} (${dxgrid})`; + displayToast( + (type = "success"), + (icon = "bi-check"), + (content = content), + (duration = 5000) + ); }); // DATA CHANNEL OPENING TOAST -ipcRenderer.on('action-show-arq-toast-datachannel-opening', (event, data) => { - console.log(data["data"][0]) - let dxcallsign = data["data"][0]["dxcallsign"] - let content = `opening datachannel with ${dxcallsign}` - displayToast(type='secondary', icon='bi-arrow-left-right', content=content, duration=5000); +ipcRenderer.on("action-show-arq-toast-datachannel-opening", (event, data) => { + console.log(data["data"][0]); + let dxcallsign = data["data"][0]["dxcallsign"]; + let content = `opening datachannel with ${dxcallsign}`; + displayToast( + (type = "secondary"), + (icon = "bi-arrow-left-right"), + (content = content), + (duration = 5000) + ); }); // DATA CHANNEL WAITING TOAST -ipcRenderer.on('action-show-arq-toast-datachannel-waiting', (event, data) => { - displayToast(type='warning', icon='bi-smartwatch', content='channel busy - waiting...', duration=5000); +ipcRenderer.on("action-show-arq-toast-datachannel-waiting", (event, data) => { + displayToast( + (type = "warning"), + (icon = "bi-smartwatch"), + (content = "channel busy - waiting..."), + (duration = 5000) + ); }); - // DATA CHANNEL OPEN TOAST -ipcRenderer.on('action-show-arq-toast-datachannel-open', (event, data) => { - displayToast(type='success', icon='bi-arrow-left-right', content='datachannel open', duration=5000); +ipcRenderer.on("action-show-arq-toast-datachannel-open", (event, data) => { + displayToast( + (type = "success"), + (icon = "bi-arrow-left-right"), + (content = "datachannel open"), + (duration = 5000) + ); }); // DATA CHANNEL RECEIVED OPENER TOAST -ipcRenderer.on('action-show-arq-toast-datachannel-received-opener', (event, data) => { - console.log(data["data"][0]) - let dxcallsign = data["data"][0]["dxcallsign"] - let content = `datachannel requested by ${dxcallsign}` - displayToast(type='success', icon='bi-arrow-left-right', content=content, duration=5000); -}); +ipcRenderer.on( + "action-show-arq-toast-datachannel-received-opener", + (event, data) => { + console.log(data["data"][0]); + let dxcallsign = data["data"][0]["dxcallsign"]; + let content = `datachannel requested by ${dxcallsign}`; + displayToast( + (type = "success"), + (icon = "bi-arrow-left-right"), + (content = content), + (duration = 5000) + ); + } +); // ARQ TRANSMISSION FAILED // TODO: use for both - transmitting and receiving --> we need to change the IDs -ipcRenderer.on('action-show-arq-toast-transmission-failed', (event, data) => { - displayToast(type='danger', icon='bi-arrow-left-right', content='transmission failed', duration=5000); +ipcRenderer.on("action-show-arq-toast-transmission-failed", (event, data) => { + displayToast( + (type = "danger"), + (icon = "bi-arrow-left-right"), + (content = "transmission failed"), + (duration = 5000) + ); }); // ARQ TRANSMISSION FAILED (Version mismatch) -ipcRenderer.on('action-show-arq-toast-transmission-failed-ver', (event, data) => { - displayToast(type='danger', icon='bi-broadcast', content='protocoll version missmatch', duration=5000); -}); +ipcRenderer.on( + "action-show-arq-toast-transmission-failed-ver", + (event, data) => { + displayToast( + (type = "danger"), + (icon = "bi-broadcast"), + (content = "protocol version missmatch"), + (duration = 5000) + ); + } +); // ARQ TRANSMISSION STOPPED // TODO: RENAME ID -- WRONG -ipcRenderer.on('action-show-arq-toast-transmission-stopped', (event, data) => { - displayToast(type='success', icon='bi-arrow-left-right', content='transmission stopped', duration=5000); +ipcRenderer.on("action-show-arq-toast-transmission-stopped", (event, data) => { + displayToast( + (type = "success"), + (icon = "bi-arrow-left-right"), + (content = "transmission stopped"), + (duration = 5000) + ); }); // ARQ TRANSMISSION FAILED // TODO: USE FOR TX AND RX -ipcRenderer.on('action-show-arq-toast-transmission-failed', (event, data) => { - displayToast(type='danger', icon='bi-broadcast', content='arq transmission failed', duration=5000); +ipcRenderer.on("action-show-arq-toast-transmission-failed", (event, data) => { + displayToast( + (type = "danger"), + (icon = "bi-broadcast"), + (content = "arq transmission failed"), + (duration = 5000) + ); }); // ARQ TRANSMISSION TRANSMITTED -ipcRenderer.on('action-show-arq-toast-transmission-transmitted', (event, data) => { - console.log(data["data"][0]) - let content = `received cq from ${dxcallsign} (${dxgrid})` - displayToast(type='success', icon='bi-broadcast', content='data transmitted', duration=5000); -}); +ipcRenderer.on( + "action-show-arq-toast-transmission-transmitted", + (event, data) => { + console.log(data["data"][0]); + //let content = `received cq from ${dxcallsign} (${dxgrid})`; + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = "data transmitted"), + (duration = 5000) + ); + } +); // ARQ TRANSMISSION TRANSMITTING -ipcRenderer.on('action-show-arq-toast-transmission-transmitting', (event, data) => { - +ipcRenderer.on( + "action-show-arq-toast-transmission-transmitting", + (event, data) => { var irs_snr = data["data"][0].irs_snr; - if(irs_snr <= 0){ - displayToast(type='warning', icon='bi-broadcast', content='low link margin: ' + irs_snr + ' dB', duration=5000); - } else if(irs_snr > 0 && irs_snr <= 5){ - displayToast(type='warning', icon='bi-broadcast', content='medium link margin: ' + irs_snr + ' dB', duration=5000); - } else if(irs_snr > 5 && irs_snr < 12.7){ - displayToast(type='success', icon='bi-broadcast', content='high link margin: ' + irs_snr + ' dB', duration=5000); - } else if(irs_snr >= 12.7){ - displayToast(type='success', icon='bi-broadcast', content='very high link margin: ' + irs_snr + ' dB', duration=5000); + if (irs_snr <= 0) { + displayToast( + (type = "warning"), + (icon = "bi-broadcast"), + (content = "low link margin: " + irs_snr + " dB"), + (duration = 5000) + ); + } else if (irs_snr > 0 && irs_snr <= 5) { + displayToast( + (type = "warning"), + (icon = "bi-broadcast"), + (content = "medium link margin: " + irs_snr + " dB"), + (duration = 5000) + ); + } else if (irs_snr > 5 && irs_snr < 12.7) { + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = "high link margin: " + irs_snr + " dB"), + (duration = 5000) + ); + } else if (irs_snr >= 12.7) { + displayToast( + (type = "success"), + (icon = "bi-broadcast"), + (content = + "very high link margin: " + irs_snr + " dB"), + (duration = 5000) + ); } else { - //displayToast(type='info', icon='bi-broadcast', content='no snr information', duration=5000); + //displayToast(type='info', icon='bi-broadcast', content='no snr information', duration=5000); } - -}); + } +); // ARQ TRANSMISSION RECEIVED -ipcRenderer.on('action-show-arq-toast-transmission-received', (event, data) => { - console.log(data["data"][0]) - displayToast(type='success', icon='bi-check-circle', content='all data received', duration=5000); +ipcRenderer.on("action-show-arq-toast-transmission-received", (event, data) => { + console.log(data["data"][0]); + displayToast( + (type = "success"), + (icon = "bi-check-circle"), + (content = "all data received"), + (duration = 5000) + ); }); // ARQ TRANSMISSION RECEIVING -ipcRenderer.on('action-show-arq-toast-transmission-receiving', (event, data) => { - displayToast(type='primary', icon='bi-arrow-left-right', content='session receiving', duration=5000); -}); +ipcRenderer.on( + "action-show-arq-toast-transmission-receiving", + (event, data) => { + displayToast( + (type = "primary"), + (icon = "bi-arrow-left-right"), + (content = "session receiving"), + (duration = 5000) + ); + } +); // ARQ SESSION CONNECTING -ipcRenderer.on('action-show-arq-toast-session-connecting', (event, data) => { - displayToast(type='primary', icon='bi-arrow-left-right', content='connecting...', duration=5000); +ipcRenderer.on("action-show-arq-toast-session-connecting", (event, data) => { + displayToast( + (type = "primary"), + (icon = "bi-arrow-left-right"), + (content = "connecting..."), + (duration = 5000) + ); }); // ARQ SESSION CONNECTED -ipcRenderer.on('action-show-arq-toast-session-connected', (event, data) => { - displayToast(type='success', icon='bi-arrow-left-right', content='session connected', duration=5000); +ipcRenderer.on("action-show-arq-toast-session-connected", (event, data) => { + displayToast( + (type = "success"), + (icon = "bi-arrow-left-right"), + (content = "session connected"), + (duration = 5000) + ); }); // ARQ SESSION CONNECTED -ipcRenderer.on('action-show-arq-toast-session-waiting', (event, data) => { - displayToast(type='warning', icon='bi-smartwatch', content='session waiting...', duration=5000); +ipcRenderer.on("action-show-arq-toast-session-waiting", (event, data) => { + displayToast( + (type = "warning"), + (icon = "bi-smartwatch"), + (content = "session waiting..."), + (duration = 5000) + ); }); - // ARQ SESSION CLOSE -ipcRenderer.on('action-show-arq-toast-session-close', (event, data) => { - displayToast(type='warning', icon='bi-arrow-left-right', content='session close', duration=5000); +ipcRenderer.on("action-show-arq-toast-session-close", (event, data) => { + displayToast( + (type = "warning"), + (icon = "bi-arrow-left-right"), + (content = "session close"), + (duration = 5000) + ); }); // ARQ SESSION FAILED -ipcRenderer.on('action-show-arq-toast-session-failed', (event, data) => { - displayToast(type='danger', icon='bi-arrow-left-right', content='session failed', duration=5000); +ipcRenderer.on("action-show-arq-toast-session-failed", (event, data) => { + displayToast( + (type = "danger"), + (icon = "bi-arrow-left-right"), + (content = "session failed"), + (duration = 5000) + ); }); - // enable or disable a setting by given switch and element -function enable_setting(enable_switch, enable_object){ - if(document.getElementById(enable_switch).checked){ - config[enable_switch] = true - document.getElementById(enable_object).removeAttribute("disabled","disabled"); - } else { - config[enable_switch] = false - document.getElementById(enable_object).setAttribute("disabled","disabled"); - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); +// not used at this time +function enable_setting(enable_switch, enable_object) { + if (document.getElementById(enable_switch).checked) { + config[enable_switch] = true; + document + .getElementById(enable_object) + .removeAttribute("disabled", "disabled"); + } else { + config[enable_switch] = false; + document.getElementById(enable_object).setAttribute("disabled", "disabled"); + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); } // enable or disable a setting switch -function set_setting_switch(setting_switch, enable_object, state){ - document.getElementById(setting_switch).checked = state - enable_setting(setting_switch, enable_object) - } - -setInterval(checkRigctld, 500) -function checkRigctld(){ - - var rigctld_ip = document.getElementById("hamlib_rigctld_ip").value; - var rigctld_port = document.getElementById("hamlib_rigctld_port").value; - - let Data = { - ip: rigctld_ip, - port: rigctld_port - }; - - //Prevents an error on startup if hamlib settings aren't populated yet - if (rigctld_port.length > 0 && rigctld_ip.length > 0) { - ipcRenderer.send('request-check-rigctld', Data); - } +// not used at this time +function set_setting_switch(setting_switch, enable_object, state) { + document.getElementById(setting_switch).checked = state; + enable_setting(setting_switch, enable_object); } -ipcRenderer.on('action-check-rigctld', (event, data) => { - document.getElementById("hamlib_rigctld_status").value = data["state"]; +setInterval(checkRigctld, 500); +function checkRigctld() { + var rigctld_ip = document.getElementById("hamlib_rigctld_ip").value; + var rigctld_port = document.getElementById("hamlib_rigctld_port").value; + + let Data = { + ip: rigctld_ip, + port: rigctld_port, + }; + + //Prevents an error on startup if hamlib settings aren't populated yet + if (rigctld_port.length > 0 && rigctld_ip.length > 0) { + ipcRenderer.send("request-check-rigctld", Data); + } +} + +ipcRenderer.on("action-check-rigctld", (event, data) => { + document.getElementById("hamlib_rigctld_status").value = data["state"]; }); -ipcRenderer.on('action-set-app-version', (event, data) => { - appVer = data; +ipcRenderer.on("action-set-app-version", (event, data) => { + appVer = data; }); -function updateTitle(mycall = config.mycall , tnc = config.tnc_host, tncport = config.tnc_port, appender = ""){ - //Multiple consecutive spaces get converted to a single space - var title ="FreeDATA " + appVer + " - Call: " + mycall + " - TNC: " + tnc + ":" + tncport + appender; - if (title != document.title) { - document.title=title; - } +function updateTitle( + mycall = config.mycall, + tnc = config.tnc_host, + tncport = config.tnc_port, + appender = "" +) { + //Multiple consecutive spaces get converted to a single space + var title = + "FreeDATA " + + appVer + + " - Call: " + + mycall + + " - TNC: " + + tnc + + ":" + + tncport + + appender; + if (title != document.title) { + document.title = title; + } } //Set force to true to ensure a class is present on a control, other set to false to ensure it isn't present -function toggleClass(control,classToToggle,force) { - var cntrl = document.getElementById(control); - if (cntrl == undefined) { - //console.log("toggle class: unknown control", control); - return; - } - var activeClasses = cntrl.getAttribute('class'); - //var oldactive = activeClasses; - if (force == true && activeClasses.indexOf(classToToggle) >= 0) { - return; - } - if (force == false && activeClasses.indexOf(classToToggle) == -1) { - return; - } - if (force == true) { - activeClasses += " " + classToToggle; - } else { - activeClasses = activeClasses.replace(classToToggle,""); - } - activeClasses = activeClasses.replace(" "," ").trim(); - cntrl.setAttribute("class",activeClasses); - //console.log(control," toggleClass; force: ", force, "class: " ,classToToggle, " in: '" ,oldactive, "' out: '",activeClasses,"'"); +function toggleClass(control, classToToggle, force) { + var cntrl = document.getElementById(control); + if (cntrl == undefined) { + //console.log("toggle class: unknown control", control); + return; + } + var activeClasses = cntrl.getAttribute("class"); + //var oldactive = activeClasses; + if (force == true && activeClasses.indexOf(classToToggle) >= 0) { + return; + } + if (force == false && activeClasses.indexOf(classToToggle) == -1) { + return; + } + if (force == true) { + activeClasses += " " + classToToggle; + } else { + activeClasses = activeClasses.replace(classToToggle, ""); + } + activeClasses = activeClasses.replace(" ", " ").trim(); + cntrl.setAttribute("class", activeClasses); + //console.log(control," toggleClass; force: ", force, "class: " ,classToToggle, " in: '" ,oldactive, "' out: '",activeClasses,"'"); } function set_CPU_mode() { - if (config.high_graphics.toUpperCase()=="FALSE") - { - toggleClass("dbfs_level","disable-effects",true); - toggleClass("dbfs_level","progress-bar-striped",false); - toggleClass("waterfall","disable-effects",true); - toggleClass("transmission_progress","disable-effects",true); - toggleClass("transmission_progress","progress-bar-striped",false); - } - else - { - toggleClass("dbfs_level","disable-effects",false); - toggleClass("dbfs_level","progress-bar-striped",true); - toggleClass("waterfall","disable-effects",false); - toggleClass("transmission_progress","disable-effects",false); - toggleClass("transmission_progress","progress-bar-striped",true); - } + if (config.high_graphics.toUpperCase() == "FALSE") { + toggleClass("dbfs_level", "disable-effects", true); + toggleClass("dbfs_level", "progress-bar-striped", false); + toggleClass("noise_level", "disable-effects", true); + toggleClass("noise_level", "progress-bar-striped", false); + toggleClass("waterfall", "disable-effects", true); + toggleClass("transmission_progress", "disable-effects", true); + toggleClass("transmission_progress", "progress-bar-striped", false); + } else { + toggleClass("dbfs_level", "disable-effects", false); + toggleClass("dbfs_level", "progress-bar-striped", true); + toggleClass("noise_level", "disable-effects", false); + toggleClass("noise_level", "progress-bar-striped", true); + toggleClass("waterfall", "disable-effects", false); + toggleClass("transmission_progress", "disable-effects", false); + toggleClass("transmission_progress", "progress-bar-striped", true); + } } //Temporarily disable a button with timeout function pauseButton(btn, timems) { - btn.disabled = true; - var curText = btn.innerHTML; - if (config.high_graphics.toUpperCase() == "TRUE") { - btn.innerHTML = ""; - } - setTimeout(()=>{ - btn.innerHTML=curText; - btn.disabled = false;}, timems) + btn.disabled = true; + var curText = btn.innerHTML; + if (config.high_graphics.toUpperCase() == "TRUE") { + btn.innerHTML = + '