@@ -3,6 +3,7 @@ const path = require('node:path');
33const { ipcMain} = require ( 'electron' )
44const http = require ( 'http' ) ;
55const xml = require ( "xml2js" ) ;
6+ const net = require ( 'net' ) ;
67
78let s_mainWindow ;
89let msgbacklog = [ ] ;
@@ -24,22 +25,16 @@ var defaultcfg = {
2425 flrig_host : '127.0.0.1' ,
2526 flrig_port : '12345' ,
2627 flrig_ena : false ,
28+ hamlib_host : '127.0.0.1' ,
29+ hamlib_port : '4532' ,
30+ hamlib_ena : false ,
31+ ignore_pwr : false ,
2732}
2833
2934const storage = require ( 'electron-json-storage' ) ;
3035
3136app . disableHardwareAcceleration ( ) ;
3237
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-
4338function createWindow ( ) {
4439 const mainWindow = new BrowserWindow ( {
4540 width : 430 ,
@@ -65,8 +60,38 @@ function createWindow () {
6560 return mainWindow ;
6661}
6762
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+
6894ipcMain . on ( "set_config" , async ( event , arg ) => {
69- // event.returnValue="aha";
7095 defaultcfg = arg ;
7196 storage . set ( 'basic' , defaultcfg , function ( e ) {
7297 if ( e ) throw e ;
@@ -75,17 +100,20 @@ ipcMain.on("set_config", async (event,arg) => {
75100} ) ;
76101
77102ipcMain . on ( "resize" , async ( event , arg ) => {
78- // event.returnValue="aha";
79103 newsize = arg ;
80104 s_mainWindow . setContentSize ( newsize . width , newsize . height , newsize . ani ) ;
81105 s_mainWindow . setSize ( newsize . width , newsize . height , newsize . ani ) ;
82106 event . returnValue = true ;
83107} ) ;
84108
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 ;
89117} ) ;
90118
91119ipcMain . on ( "setCAT" , async ( event , arg ) => {
@@ -119,6 +147,7 @@ ipcMain.on("test", async (event,arg) => {
119147
120148app . whenReady ( ) . then ( ( ) => {
121149 s_mainWindow = createWindow ( ) ;
150+ createAdvancedWindow ( s_mainWindow ) ;
122151 globalShortcut . register ( 'Control+Shift+I' , ( ) => { return false ; } ) ;
123152 app . on ( 'activate' , function ( ) {
124153 if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( )
@@ -332,29 +361,43 @@ async function settrx(qrg) {
332361 } else {
333362 to . mode = 'USB' ;
334363 }
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 ) {
348365 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>' ;
350367 var options = {
351368 method : 'POST' ,
352369 headers : {
353370 'User-Agent' : 'SW2WL_v' + app . getVersion ( ) ,
354371 'Content-Length' : postData . length
355372 }
356373 } ;
374+ let url = "http://" + defaultcfg . flrig_host + ':' + defaultcfg . flrig_port + '/' ;
357375 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" , ( ) => { } ) ;
358401 }
359402
360403 return true ;
0 commit comments