@@ -14,14 +14,16 @@ const {ipcRenderer} = require('electron')
1414const bt_save = select ( "#save" ) ;
1515const bt_quit = select ( "#quit" ) ;
1616const bt_test = select ( "#test" ) ;
17+ const input_key = select ( "#wavelog_key" ) ;
18+ const input_url = select ( "#wavelog_url" ) ;
1719var oldCat = { vfo : 0 , mode : "SSB" } ;
1820
1921$ ( document ) . ready ( function ( ) {
2022
2123 cfg = ipcRenderer . sendSync ( "get_config" , '' ) ;
2224 $ ( "#wavelog_url" ) . val ( cfg . wavelog_url ) ;
2325 $ ( "#wavelog_key" ) . val ( cfg . wavelog_key ) ;
24- $ ( "#wavelog_id" ) . val ( cfg . wavelog_id ) ;
26+ // $("#wavelog_id").val(cfg.wavelog_id);
2527 $ ( "#wavelog_radioname" ) . val ( cfg . wavelog_radioname ) ;
2628 $ ( "#flrig_host" ) . val ( cfg . flrig_host ) ;
2729 $ ( "#flrig_port" ) . val ( cfg . flrig_port ) ;
@@ -67,6 +69,19 @@ $(document).ready(function() {
6769 console . log ( x ) ;
6870 } ) ;
6971
72+ input_key . addEventListener ( 'change' , ( ) => {
73+ getStations ( ) ;
74+ } ) ;
75+ input_url . addEventListener ( 'change' , ( ) => {
76+ getStations ( ) ;
77+ } ) ;
78+ $ ( '#reload_icon' ) . on ( 'click' , ( ) => {
79+ getStations ( ) ;
80+ } ) ;
81+ if ( cfg . wavelog_key != "" && cfg . wavelog_url != "" ) {
82+ getStations ( ) ;
83+ }
84+
7085 getsettrx ( ) ;
7186
7287 $ ( "#flrig_ena" ) . on ( "click" , function ( ) {
@@ -78,15 +93,15 @@ $(document).ready(function() {
7893
7994 $ ( "#config-tab" ) . on ( "click" , function ( ) {
8095 obj = { } ;
81- obj . width = 420 ;
96+ obj . width = 430 ;
8297 obj . height = 550 ;
8398 obj . ani = false ;
8499 resizeme ( obj ) ;
85100 } ) ;
86101
87102 $ ( "#status-tab" ) . on ( "click" , function ( ) {
88103 obj = { } ;
89- obj . width = 420 ;
104+ obj . width = 430 ;
90105 obj . height = 250 ;
91106 obj . ani = false ;
92107 resizeme ( obj ) ;
@@ -208,3 +223,48 @@ function updateUtcTime() {
208223
209224 document . getElementById ( 'utc' ) . innerHTML = formattedTime ;
210225}
226+
227+ async function getStations ( ) {
228+ let select = $ ( '#wavelog_id' ) ;
229+ select . empty ( ) ;
230+ select . prop ( 'disabled' , true ) ;
231+ try {
232+ let x = await fetch ( $ ( '#wavelog_url' ) . val ( ) . trim ( ) + '/api/station_info/' + $ ( '#wavelog_key' ) . val ( ) . trim ( ) , {
233+ method : 'GET' ,
234+ rejectUnauthorized : false ,
235+ headers : {
236+ Accept : 'application/json' ,
237+ 'Content-Type' : 'application/json' ,
238+ } ,
239+ } ) ;
240+
241+ if ( ! x . ok ) {
242+ throw new Error ( `HTTP error! Status: ${ x . status } ` ) ;
243+ }
244+
245+ let data = await x . json ( ) ;
246+ fillDropdown ( data ) ;
247+
248+ } catch ( error ) {
249+ select . append ( new Option ( 'Failed to load stations' , '0' ) ) ;
250+ console . error ( 'Could not load station locations:' , error . message ) ;
251+ }
252+ }
253+
254+ function fillDropdown ( data ) {
255+ let select = $ ( '#wavelog_id' ) ;
256+ select . empty ( ) ;
257+ select . prop ( 'disabled' , false ) ;
258+
259+ data . forEach ( function ( station ) {
260+ let optionText = station . station_profile_name + " (" + station . station_callsign + ", ID: " + station . station_id + ")" ;
261+ let optionValue = station . station_id ;
262+ select . append ( new Option ( optionText , optionValue ) ) ;
263+ } ) ;
264+
265+ if ( cfg . wavelog_id && data . some ( station => station . station_id == cfg . wavelog_id ) ) {
266+ select . val ( cfg . wavelog_id ) ;
267+ } else {
268+ select . val ( data . length > 0 ? data [ 0 ] . station_id : null ) ;
269+ }
270+ }
0 commit comments