@@ -92,7 +92,7 @@ function createAdvancedWindow (mainWindow) {
9292}
9393
9494ipcMain . on ( "set_config" , async ( event , arg ) => {
95- defaultcfg = arg ;
95+ defaultcfg = arg ;
9696 storage . set ( 'basic' , defaultcfg , function ( e ) {
9797 if ( e ) throw e ;
9898 } ) ;
@@ -107,13 +107,24 @@ ipcMain.on("resize", async (event,arg) => {
107107} ) ;
108108
109109ipcMain . on ( "get_config" , async ( event , arg ) => {
110- const storedcfg = storage . getSync ( 'basic' ) ;
111- for ( const key in storedcfg ) {
112- if ( storedcfg [ key ] !== "" && storedcfg [ key ] !== undefined ) {
113- defaultcfg [ key ] = storedcfg [ key ] ;
114- }
115- }
116- event . returnValue = defaultcfg ;
110+ var storedcfg = storage . getSync ( 'basic' ) ;
111+ var realcfg = { } ;
112+ if ( ! ( storedcfg . wavelog_url ) && ! ( storedcfg . profiles ) ) { storedcfg = defaultcfg ; } // Old config not present, add default-cfg
113+ if ( ! ( storedcfg . profiles ) ) { // Old Config without array? Convert it
114+ ( realcfg . profiles = realcfg . profiles || [ ] ) . push ( storedcfg ) ;
115+ realcfg . profiles . push ( defaultcfg ) ;
116+ realcfg . profile = ( storedcfg . profile ?? 0 ) ;
117+ } else {
118+ realcfg = storedcfg ;
119+ }
120+ if ( ( arg ?? '' ) !== '' ) {
121+ realcfg . profile = arg ;
122+ }
123+ defaultcfg = realcfg ;
124+ storage . set ( 'basic' , realcfg , function ( e ) { // Store one time
125+ if ( e ) throw e ;
126+ } ) ;
127+ event . returnValue = realcfg ;
117128} ) ;
118129
119130ipcMain . on ( "setCAT" , async ( event , arg ) => {
@@ -174,7 +185,6 @@ function parseADIF(adifdata) {
174185function writeADIF ( adifObject ) {
175186 const { ADIF } = require ( "tcadif" ) ;
176187 var adiWriter = new ADIF ( adifObject ) ;
177- // console.log(adiWriter);
178188 return adiWriter ;
179189}
180190
@@ -184,7 +194,6 @@ function send2wavelog(o_cfg,adif, dryrun = false) {
184194 clpayload . station_profile_id = o_cfg . wavelog_id . trim ( ) ;
185195 clpayload . type = 'adif' ;
186196 clpayload . string = adif ;
187- // console.log(clpayload);
188197 postData = JSON . stringify ( clpayload ) ;
189198 let httpmod = 'http' ;
190199 if ( o_cfg . wavelog_url . toLowerCase ( ) . startsWith ( 'https' ) ) {
@@ -307,7 +316,7 @@ ports.forEach(port => {
307316 let x = { } ;
308317 try {
309318 outadif = writeADIF ( adobject ) ;
310- plainret = await send2wavelog ( defaultcfg , outadif . stringify ( ) ) ;
319+ plainret = await send2wavelog ( defaultcfg . profiles [ defaultcfg . profile ?? 0 ] , outadif . stringify ( ) ) ;
311320 x . state = plainret . statusCode ;
312321 x . payload = JSON . parse ( plainret . resString ) ;
313322 } catch ( e ) {
@@ -370,7 +379,7 @@ async function settrx(qrg) {
370379 } else {
371380 to . mode = 'USB' ;
372381 }
373- if ( defaultcfg . flrig_ena ) {
382+ if ( defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . flrig_ena ) {
374383 postData = '<?xml version="1.0"?>' ;
375384 postData += '<methodCall><methodName>main.set_frequency</methodName><params><param><value><double>' + to . qrg + '</double></value></param></params></methodCall>' ;
376385 var options = {
@@ -380,10 +389,10 @@ async function settrx(qrg) {
380389 'Content-Length' : postData . length
381390 }
382391 } ;
383- let url = "http://" + defaultcfg . flrig_host + ':' + defaultcfg . flrig_port + '/' ;
392+ let url = "http://" + defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . flrig_host + ':' + defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . flrig_port + '/' ;
384393 x = await httpPost ( url , options , postData ) ;
385394
386- if ( defaultcfg . wavelog_pmode ) {
395+ if ( defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . wavelog_pmode ) {
387396 postData = '<?xml version="1.0"?>' ;
388397 postData += '<methodCall><methodName>rig.set_modeA</methodName><params><param><value>' + to . mode + '</value></param></params></methodCall>' ;
389398 var options = {
@@ -396,10 +405,10 @@ async function settrx(qrg) {
396405 x = await httpPost ( url , options , postData ) ;
397406 }
398407 }
399- if ( defaultcfg . hamlib_ena ) {
400- const client = net . createConnection ( { host : defaultcfg . flrig_host , port : defaultcfg . flrig_port } , ( ) => {
408+ if ( defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . hamlib_ena ) {
409+ const client = net . createConnection ( { host : defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . flrig_host , port : defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . flrig_port } , ( ) => {
401410 client . write ( "F " + to . qrg + "\n" ) ;
402- if ( defaultcfg . wavelog_pmode ) {
411+ if ( defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . wavelog_pmode ) {
403412 client . write ( "M " + to . mode + "\n-1" ) ;
404413 }
405414 client . end ( ) ;
0 commit comments