@@ -3,6 +3,7 @@ const path = require('node:path');
3
3
const { ipcMain} = require ( 'electron' )
4
4
const http = require ( 'http' ) ;
5
5
const xml = require ( "xml2js" ) ;
6
+ const net = require ( 'net' ) ;
6
7
7
8
let s_mainWindow ;
8
9
let msgbacklog = [ ] ;
@@ -24,22 +25,16 @@ var defaultcfg = {
24
25
flrig_host : '127.0.0.1' ,
25
26
flrig_port : '12345' ,
26
27
flrig_ena : false ,
28
+ hamlib_host : '127.0.0.1' ,
29
+ hamlib_port : '4532' ,
30
+ hamlib_ena : false ,
31
+ ignore_pwr : false ,
27
32
}
28
33
29
34
const storage = require ( 'electron-json-storage' ) ;
30
35
31
36
app . disableHardwareAcceleration ( ) ;
32
37
33
- storage . has ( 'basic' , function ( error , hasKey ) {
34
- if ( ! ( hasKey ) ) {
35
- storage . set ( 'basic' , defaultcfg , function ( e ) {
36
- if ( e ) throw e ;
37
- } ) ;
38
- } else {
39
- Object . assign ( defaultcfg , storage . getSync ( 'basic' ) ) ;
40
- }
41
- } ) ;
42
-
43
38
function createWindow ( ) {
44
39
const mainWindow = new BrowserWindow ( {
45
40
width : 430 ,
@@ -65,8 +60,38 @@ function createWindow () {
65
60
return mainWindow ;
66
61
}
67
62
63
+ function createAdvancedWindow ( mainWindow ) {
64
+ let advancedWindow ;
65
+ globalShortcut . register ( 'Control+Shift+D' , ( ) => {
66
+ if ( ! advancedWindow || advancedWindow . isDestroyed ( ) ) {
67
+ const bounds = mainWindow . getBounds ( ) ;
68
+ advancedWindow = new BrowserWindow ( {
69
+ width : 430 ,
70
+ height : 250 ,
71
+ resizable : false ,
72
+ autoHideMenuBar : app . isPackaged ,
73
+ webPreferences : {
74
+ contextIsolation : false ,
75
+ nodeIntegration : true ,
76
+ devTools : ! app . isPackaged ,
77
+ enableRemoteModule : true ,
78
+ } ,
79
+ x : bounds . x + bounds . width + 10 ,
80
+ y : bounds . y ,
81
+ } ) ;
82
+ if ( app . isPackaged ) {
83
+ advancedWindow . setMenu ( null ) ;
84
+ }
85
+ advancedWindow . loadFile ( 'advanced.html' ) ;
86
+ advancedWindow . setTitle ( require ( './package.json' ) . name + " V" + require ( './package.json' ) . version ) ;
87
+ } else {
88
+ advancedWindow . focus ( ) ;
89
+ }
90
+
91
+ } ) ;
92
+ }
93
+
68
94
ipcMain . on ( "set_config" , async ( event , arg ) => {
69
- // event.returnValue="aha";
70
95
defaultcfg = arg ;
71
96
storage . set ( 'basic' , defaultcfg , function ( e ) {
72
97
if ( e ) throw e ;
@@ -75,17 +100,20 @@ ipcMain.on("set_config", async (event,arg) => {
75
100
} ) ;
76
101
77
102
ipcMain . on ( "resize" , async ( event , arg ) => {
78
- // event.returnValue="aha";
79
103
newsize = arg ;
80
104
s_mainWindow . setContentSize ( newsize . width , newsize . height , newsize . ani ) ;
81
105
s_mainWindow . setSize ( newsize . width , newsize . height , newsize . ani ) ;
82
106
event . returnValue = true ;
83
107
} ) ;
84
108
85
- ipcMain . on ( "get_config" , async ( event , arg ) => {
86
- Object . assign ( defaultcfg , storage . getSync ( 'basic' ) ) ;
87
- defaultcfg = storage . getSync ( 'basic' )
88
- event . returnValue = defaultcfg ;
109
+ ipcMain . 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 ;
89
117
} ) ;
90
118
91
119
ipcMain . on ( "setCAT" , async ( event , arg ) => {
@@ -119,6 +147,7 @@ ipcMain.on("test", async (event,arg) => {
119
147
120
148
app . whenReady ( ) . then ( ( ) => {
121
149
s_mainWindow = createWindow ( ) ;
150
+ createAdvancedWindow ( s_mainWindow ) ;
122
151
globalShortcut . register ( 'Control+Shift+I' , ( ) => { return false ; } ) ;
123
152
app . on ( 'activate' , function ( ) {
124
153
if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( )
@@ -332,29 +361,43 @@ async function settrx(qrg) {
332
361
} else {
333
362
to . mode = 'USB' ;
334
363
}
335
- postData = '<?xml version="1.0"?>' ;
336
- postData += '<methodCall><methodName>main.set_frequency</methodName><params><param><value><double>' + to . qrg + '</double></value></param></params></methodCall>' ;
337
- var options = {
338
- method : 'POST' ,
339
- headers : {
340
- 'User-Agent' : 'SW2WL_v' + app . getVersion ( ) ,
341
- 'Content-Length' : postData . length
342
- }
343
- } ;
344
- let url = "http://" + defaultcfg . flrig_host + ':' + defaultcfg . flrig_port + '/' ;
345
- x = await httpPost ( url , options , postData ) ;
346
-
347
- if ( defaultcfg . wavelog_pmode ) {
364
+ if ( defaultcfg . flrig_ena ) {
348
365
postData = '<?xml version="1.0"?>' ;
349
- postData += '<methodCall><methodName>rig.set_modeA </methodName><params><param><value>' + to . mode + '</value></param></params></methodCall>' ;
366
+ postData += '<methodCall><methodName>main.set_frequency </methodName><params><param><value><double> ' + to . qrg + '</double> </value></param></params></methodCall>' ;
350
367
var options = {
351
368
method : 'POST' ,
352
369
headers : {
353
370
'User-Agent' : 'SW2WL_v' + app . getVersion ( ) ,
354
371
'Content-Length' : postData . length
355
372
}
356
373
} ;
374
+ let url = "http://" + defaultcfg . flrig_host + ':' + defaultcfg . flrig_port + '/' ;
357
375
x = await httpPost ( url , options , postData ) ;
376
+
377
+ if ( defaultcfg . wavelog_pmode ) {
378
+ postData = '<?xml version="1.0"?>' ;
379
+ postData += '<methodCall><methodName>rig.set_modeA</methodName><params><param><value>' + to . mode + '</value></param></params></methodCall>' ;
380
+ var options = {
381
+ method : 'POST' ,
382
+ headers : {
383
+ 'User-Agent' : 'SW2WL_v' + app . getVersion ( ) ,
384
+ 'Content-Length' : postData . length
385
+ }
386
+ } ;
387
+ x = await httpPost ( url , options , postData ) ;
388
+ }
389
+ }
390
+ if ( defaultcfg . hamlib_ena ) {
391
+ const client = net . createConnection ( { host : defaultcfg . flrig_host , port : defaultcfg . flrig_port } , ( ) => {
392
+ client . write ( "F " + to . qrg + "\n" ) ;
393
+ if ( defaultcfg . wavelog_pmode ) {
394
+ client . write ( "M " + to . mode + "\n-1" ) ;
395
+ }
396
+ client . end ( ) ;
397
+ } ) ;
398
+
399
+ client . on ( "error" , ( err ) => { } ) ;
400
+ client . on ( "close" , ( ) => { } ) ;
358
401
}
359
402
360
403
return true ;
0 commit comments