@@ -14,14 +14,16 @@ const {ipcRenderer} = require('electron')
14
14
const bt_save = select ( "#save" ) ;
15
15
const bt_quit = select ( "#quit" ) ;
16
16
const bt_test = select ( "#test" ) ;
17
+ const input_key = select ( "#wavelog_key" ) ;
18
+ const input_url = select ( "#wavelog_url" ) ;
17
19
var oldCat = { vfo : 0 , mode : "SSB" } ;
18
20
19
21
$ ( document ) . ready ( function ( ) {
20
22
21
23
cfg = ipcRenderer . sendSync ( "get_config" , '' ) ;
22
24
$ ( "#wavelog_url" ) . val ( cfg . wavelog_url ) ;
23
25
$ ( "#wavelog_key" ) . val ( cfg . wavelog_key ) ;
24
- $ ( "#wavelog_id" ) . val ( cfg . wavelog_id ) ;
26
+ // $("#wavelog_id").val(cfg.wavelog_id);
25
27
$ ( "#wavelog_radioname" ) . val ( cfg . wavelog_radioname ) ;
26
28
$ ( "#flrig_host" ) . val ( cfg . flrig_host ) ;
27
29
$ ( "#flrig_port" ) . val ( cfg . flrig_port ) ;
@@ -67,6 +69,19 @@ $(document).ready(function() {
67
69
console . log ( x ) ;
68
70
} ) ;
69
71
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
+
70
85
getsettrx ( ) ;
71
86
72
87
$ ( "#flrig_ena" ) . on ( "click" , function ( ) {
@@ -78,15 +93,15 @@ $(document).ready(function() {
78
93
79
94
$ ( "#config-tab" ) . on ( "click" , function ( ) {
80
95
obj = { } ;
81
- obj . width = 420 ;
96
+ obj . width = 430 ;
82
97
obj . height = 550 ;
83
98
obj . ani = false ;
84
99
resizeme ( obj ) ;
85
100
} ) ;
86
101
87
102
$ ( "#status-tab" ) . on ( "click" , function ( ) {
88
103
obj = { } ;
89
- obj . width = 420 ;
104
+ obj . width = 430 ;
90
105
obj . height = 250 ;
91
106
obj . ani = false ;
92
107
resizeme ( obj ) ;
@@ -208,3 +223,48 @@ function updateUtcTime() {
208
223
209
224
document . getElementById ( 'utc' ) . innerHTML = formattedTime ;
210
225
}
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