Skip to content

Commit 7358fd0

Browse files
authored
Merge pull request #75 from wavelog/dev
Preparing 1.1.9 Release
2 parents 327c90f + 98c4c95 commit 7358fd0

File tree

5 files changed

+2021
-625
lines changed

5 files changed

+2021
-625
lines changed

advanced.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {ipcRenderer} = require('electron');
22

3-
var cfg = {};
3+
let cfg = {};
44

55
const bt_save=document.querySelector("#save");
66

@@ -21,7 +21,7 @@ $(document).ready(function() {
2121

2222
if ($("#hamlib_ena").is(':checked') && cfg.profiles[cfg.profile].flrig_ena){cfg.profiles[cfg.profile].flrig_ena = false;}
2323

24-
x=ipcRenderer.sendSync("set_config", cfg);
24+
const x=ipcRenderer.sendSync("set_config", cfg);
2525
// console.log(x);
2626

2727
});

main.js

Lines changed: 92 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {app, BrowserWindow, Tray, Notification, Menu, globalShortcut, powerSaveBlocker } = require('electron/main');
1+
const {app, BrowserWindow, globalShortcut, Notification, powerSaveBlocker } = require('electron/main');
22
const path = require('node:path');
33
const {ipcMain} = require('electron')
44
const http = require('http');
@@ -8,7 +8,6 @@ const net = require('net');
88
const gotTheLock = app.requestSingleInstanceLock();
99

1010
let powerSaveBlockerId;
11-
let tray;
1211
let s_mainWindow;
1312
let msgbacklog=[];
1413
let httpServer;
@@ -18,10 +17,10 @@ const DemoAdif='<call:5>DJ7NT <gridsquare:4>JO30 <mode:3>FT8 <rst_sent:3>-15 <rs
1817

1918
if (require('electron-squirrel-startup')) app.quit();
2019

21-
var udp = require('dgram');
20+
const udp = require('dgram');
2221

23-
var q={};
24-
var defaultcfg = {
22+
let q={};
23+
let defaultcfg = {
2524
wavelog_url: "https://log.jo30.de/index.php",
2625
wavelog_key: "mykey",
2726
wavelog_id: "0",
@@ -106,15 +105,15 @@ ipcMain.on("set_config", async (event,arg) => {
106105
});
107106

108107
ipcMain.on("resize", async (event,arg) => {
109-
newsize=arg;
108+
const newsize=arg;
110109
s_mainWindow.setContentSize(newsize.width,newsize.height,newsize.ani);
111110
s_mainWindow.setSize(newsize.width,newsize.height,newsize.ani);
112111
event.returnValue=true;
113112
});
114113

115114
ipcMain.on("get_config", async (event, arg) => {
116-
var storedcfg = storage.getSync('basic');
117-
var realcfg={};
115+
let storedcfg = storage.getSync('basic');
116+
let realcfg={};
118117
if (!(storedcfg.wavelog_url) && !(storedcfg.profiles)) { storedcfg=defaultcfg; } // Old config not present, add default-cfg
119118
if (!(storedcfg.profiles)) { // Old Config without array? Convert it
120119
(realcfg.profiles = realcfg.profiles || []).push(storedcfg);
@@ -145,14 +144,18 @@ ipcMain.on("quit", async (event,arg) => {
145144
});
146145

147146
function show_noti(arg) {
148-
try {
149-
const notification = new Notification({
150-
title: 'Wavelog',
151-
body: arg
152-
});
153-
notification.show();
154-
} catch(e) {
155-
console.log("No notification possible on this system / ignoring");
147+
if (Notification.isSupported()) {
148+
try {
149+
const notification = new Notification({
150+
title: 'Wavelog',
151+
body: arg
152+
});
153+
notification.show();
154+
} catch(e) {
155+
console.log("No notification possible on this system / ignoring");
156+
}
157+
} else {
158+
console.log("Notifications are not supported on this platform");
156159
}
157160
}
158161

@@ -185,9 +188,6 @@ app.on('before-quit', () => {
185188
if (httpServer) {
186189
httpServer.close();
187190
}
188-
if (tray) {
189-
tray.destroy();
190-
}
191191
});
192192

193193
process.on('SIGINT', () => {
@@ -217,45 +217,12 @@ if (!gotTheLock) {
217217
app.on('activate', function () {
218218
if (BrowserWindow.getAllWindows().length === 0) createWindow()
219219
});
220-
s_mainWindow.webContents.once('dom-ready', function() {
221-
if (msgbacklog.length>0) {
222-
s_mainWindow.webContents.send('updateMsg',msgbacklog.pop());
223-
}
224-
});
225-
226-
// Create the tray icon
227-
const path = require('path');
228-
const iconPath = path.join(__dirname, 'icon1616.png');
229-
tray = new Tray(iconPath);
230-
231-
const contextMenu = Menu.buildFromTemplate([
232-
{ label: 'Show App', click: () => s_mainWindow.show() },
233-
{ label: 'Quit', click: () => {
234-
console.log("Exiting");
235-
app.isQuitting = true;
236-
app.quit();
237-
}
238-
},
239-
]);
240-
241-
tray.setContextMenu(contextMenu);
242-
tray.setToolTip(require('./package.json').name + " V" + require('./package.json').version);
243-
244-
s_mainWindow.on('minimize', (event) => {
245-
event.preventDefault();
246-
s_mainWindow.hide(); // Hides the window instead of minimizing it to the taskbar
247-
});
248-
249-
s_mainWindow.on('close', (event) => {
250-
if (!app.isQuitting) {
251-
event.preventDefault();
252-
s_mainWindow.hide();
253-
}
220+
s_mainWindow.webContents.once('dom-ready', function() {
221+
if (msgbacklog.length>0) {
222+
s_mainWindow.webContents.send('updateMsg',msgbacklog.pop());
223+
}
224+
});
254225
});
255-
if (process.platform === 'darwin') {
256-
app.dock.hide();
257-
}
258-
})
259226
}
260227

261228
app.on('window-all-closed', function () {
@@ -328,13 +295,13 @@ function send2wavelog(o_cfg,adif, dryrun = false) {
328295
clpayload.station_profile_id=o_cfg.wavelog_id.trim();
329296
clpayload.type='adif';
330297
clpayload.string=adif;
331-
postData=JSON.stringify(clpayload);
298+
const postData=JSON.stringify(clpayload);
332299
let httpmod='http';
333300
if (o_cfg.wavelog_url.toLowerCase().startsWith('https')) {
334301
httpmod='https';
335302
}
336303
const https = require(httpmod);
337-
var options = {
304+
const options = {
338305
method: 'POST',
339306
timeout: 5000,
340307
rejectUnauthorized: false,
@@ -346,7 +313,7 @@ function send2wavelog(o_cfg,adif, dryrun = false) {
346313
};
347314

348315
return new Promise((resolve, reject) => {
349-
rej=false;
316+
let rej=false;
350317
let result={};
351318
let url=o_cfg.wavelog_url + '/api/qso';
352319
if (dryrun) { url+='/true'; }
@@ -360,7 +327,7 @@ function send2wavelog(o_cfg,adif, dryrun = false) {
360327
const body = [];
361328
res.on('data', (chunk) => body.push(chunk));
362329
res.on('end', () => {
363-
var resString = Buffer.concat(body).toString();
330+
let resString = Buffer.concat(body).toString();
364331
if (rej) {
365332
if (resString.indexOf('html>')>0) {
366333
resString='{"status":"failed","reason":"wrong URL"}';
@@ -403,15 +370,15 @@ ports.forEach(port => {
403370
});
404371

405372
WServer.on('message',async function(msg,info){
406-
parsedXML={};
407-
adobject={};
373+
let parsedXML={};
374+
let adobject={};
408375
if (msg.toString().includes("xml")) { // detect if incoming String is XML
409376
try {
410377
xml.parseString(msg.toString(), function (err,dat) {
411378
parsedXML=dat;
412379
});
413380
let qsodatum = new Date(Date.parse(parsedXML.contactinfo.timestamp[0]+"Z")); // Added Z to make it UTC
414-
qsodat=fmt(qsodatum);
381+
const qsodat=fmt(qsodatum);
415382
if (parsedXML.contactinfo.mode[0] == 'USB' || parsedXML.contactinfo.mode[0] == 'LSB') { // TCADIF lib is not capable of using USB/LSB
416383
parsedXML.contactinfo.mode[0]='SSB';
417384
}
@@ -447,11 +414,11 @@ ports.forEach(port => {
447414
return;
448415
}
449416
}
450-
var plainret='';
417+
let plainret='';
451418
if (adobject.qsos.length>0) {
452419
let x={};
453420
try {
454-
outadif=writeADIF(adobject);
421+
const outadif=writeADIF(adobject);
455422
plainret=await send2wavelog(defaultcfg.profiles[defaultcfg.profile ?? 0],outadif.stringify());
456423
x.state=plainret.statusCode;
457424
x.payload = JSON.parse(plainret.resString);
@@ -503,9 +470,9 @@ function startserver() {
503470
res.setHeader('Access-Control-Allow-Origin', '*');
504471
res.writeHead(200, {'Content-Type': 'text/plain'});
505472
res.end('');
506-
let parts = req.url.substr(1).split('/');
507-
let qrg = parts[0];
508-
let mode = parts[1] || '';
473+
const parts = req.url.substr(1).split('/');
474+
const qrg = parts[0];
475+
const mode = parts[1] || '';
509476
if (Number.isInteger(Number.parseInt(qrg))) {
510477
settrx(qrg,mode);
511478
}
@@ -515,11 +482,52 @@ function startserver() {
515482
}
516483
}
517484

485+
486+
async function get_modes() {
487+
return new Promise((resolve) => {
488+
ipcMain.once('get_info_result', (event, modes) => {
489+
resolve(modes);
490+
});
491+
s_mainWindow.webContents.send('get_info', 'rig.get_modes');
492+
});
493+
}
494+
495+
function getClosestMode(requestedMode, availableModes) {
496+
if (availableModes.includes(requestedMode)) { // Check perfect matches
497+
return requestedMode;
498+
}
499+
500+
const modeFallbacks = {
501+
'CW': ['CW-L', 'CW-R', 'CW', 'LSB', 'USB'],
502+
'RTTY': ['RTTY', 'RTTY-R'],
503+
};
504+
505+
if (modeFallbacks[requestedMode]) {
506+
for (let variant of modeFallbacks[requestedMode]) {
507+
if (availableModes.includes(variant)) {
508+
return variant;
509+
}
510+
}
511+
}
512+
513+
const found = availableModes.find(mode =>
514+
mode.toUpperCase().startsWith(requestedMode.toUpperCase())
515+
);
516+
if (found) return found;
517+
return null;
518+
}
519+
518520
async function settrx(qrg, mode = '') {
521+
let avail_modes={};
522+
try {
523+
avail_modes=await get_modes();
524+
} catch(e) {
525+
avail_modes=[];
526+
}
519527
let to={};
520528
to.qrg=qrg;
521529
if (mode == 'cw') {
522-
to.mode='CW';
530+
to.mode=getClosestMode(mode,avail_modes);
523531
} else {
524532
if ((to.qrg) < 7999000) {
525533
to.mode='LSB';
@@ -528,22 +536,22 @@ async function settrx(qrg, mode = '') {
528536
}
529537
}
530538
if (defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_ena) {
531-
postData= '<?xml version="1.0"?>';
539+
let postData= '<?xml version="1.0"?>';
532540
postData+='<methodCall><methodName>main.set_frequency</methodName><params><param><value><double>' + to.qrg + '</double></value></param></params></methodCall>';
533-
var options = {
541+
let options = {
534542
method: 'POST',
535543
headers: {
536544
'User-Agent': 'SW2WL_v' + app.getVersion(),
537545
'Content-Length': postData.length
538546
}
539547
};
540548
let url="http://"+defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_host+':'+defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_port+'/';
541-
x=await httpPost(url,options,postData);
549+
let x=await httpPost(url,options,postData);
542550

543551
if (defaultcfg.profiles[defaultcfg.profile ?? 0].wavelog_pmode) {
544552
postData= '<?xml version="1.0"?>';
545553
postData+='<methodCall><methodName>rig.set_modeA</methodName><params><param><value>' + to.mode + '</value></param></params></methodCall>';
546-
var options = {
554+
options = {
547555
method: 'POST',
548556
headers: {
549557
'User-Agent': 'SW2WL_v' + app.getVersion(),
@@ -554,7 +562,7 @@ async function settrx(qrg, mode = '') {
554562
}
555563
}
556564
if (defaultcfg.profiles[defaultcfg.profile ?? 0].hamlib_ena) {
557-
const client = net.createConnection({ host: defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_host, port: defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_port }, () => {
565+
const client = net.createConnection({ host: defaultcfg.profiles[defaultcfg.profile ?? 0].hamlib_host, port: defaultcfg.profiles[defaultcfg.profile ?? 0].hamlib_port }, () => {
558566
client.write("F " + to.qrg + "\n");
559567
if (defaultcfg.profiles[defaultcfg.profile ?? 0].wavelog_pmode) {
560568
client.write("M " + to.mode + "\n-1");
@@ -571,13 +579,13 @@ async function settrx(qrg, mode = '') {
571579

572580
function httpPost(url,options,postData) {
573581
return new Promise((resolve, reject) => {
574-
rej=false;
582+
let rej=false;
575583
let result={};
576584
const req = http.request(url,options, (res) => {
577585
let body=[];
578586
res.on('data', (chunk) => body.push(chunk));
579587
res.on('end', () => {
580-
var resString = Buffer.concat(body).toString();
588+
const resString = Buffer.concat(body).toString();
581589
if (rej) {
582590
reject(resString);
583591
} else {
@@ -604,13 +612,13 @@ function httpPost(url,options,postData) {
604612
}
605613

606614
function fmt(spotDate) {
607-
retstr={};
608-
d=spotDate.getUTCDate().toString();
609-
y=spotDate.getUTCFullYear().toString();
610-
m=(1+spotDate.getUTCMonth()).toString();
611-
h=spotDate.getUTCHours().toString();
612-
i=spotDate.getUTCMinutes().toString();
613-
s=spotDate.getUTCSeconds().toString();
615+
const retstr={};
616+
const d=spotDate.getUTCDate().toString();
617+
const y=spotDate.getUTCFullYear().toString();
618+
const m=(1+spotDate.getUTCMonth()).toString();
619+
const h=spotDate.getUTCHours().toString();
620+
const i=spotDate.getUTCMinutes().toString();
621+
const s=spotDate.getUTCSeconds().toString();
614622
retstr.d=y.padStart(4,'0')+m.padStart(2,'0')+d.padStart(2,'0');
615623
retstr.t=h.padStart(2,'0')+i.padStart(2,'0')+s.padStart(2,'0');
616624
return retstr;

0 commit comments

Comments
 (0)