-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrenderer.js
More file actions
722 lines (615 loc) · 20.7 KB
/
renderer.js
File metadata and controls
722 lines (615 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
// Shorthand for document.querySelector.
let cfg={};
let active_cfg=0;
let trxpoll=undefined;
let utcTimeInterval=undefined;
let activeConnections = new Set(); // Track active TCP connections in renderer
let activeAbortControllers = new Set(); // Track active HTTP requests for cancellation
const {ipcRenderer} = require('electron')
const net = require('net');
const bt_toggle=select("#toggle");
const bt_save=select("#save");
const bt_quit=select("#quit");
const bt_test=select("#test");
const input_key=select("#wavelog_key");
const input_url=select("#wavelog_url");
let oldCat={ vfo: 0, mode: "SSB" };
let lastCat=0;
$(document).ready(function() {
load_config();
bt_toggle.addEventListener('click', async () => {
openProfileManager();
});
bt_save.addEventListener('click', async () => {
// cfg=ipcRenderer.sendSync("get_config", active_cfg);
cfg.profile=active_cfg;
cfg.profiles[cfg.profile].wavelog_url=$("#wavelog_url").val().trim();
cfg.profiles[cfg.profile].wavelog_key=$("#wavelog_key").val().trim();
cfg.profiles[cfg.profile].wavelog_id=$("#wavelog_id").val().trim();
cfg.profiles[cfg.profile].wavelog_radioname=$("#wavelog_radioname").val().trim();
cfg.profiles[cfg.profile].wavelog_pmode=$("#wavelog_pmode").is(':checked');
// Save radio configuration based on selected radio type
const selectedRadio = $('#radio_type').val();
// Reset all radio settings first
cfg.profiles[cfg.profile].flrig_ena = false;
cfg.profiles[cfg.profile].hamlib_ena = false;
switch(selectedRadio) {
case 'flrig':
cfg.profiles[cfg.profile].flrig_ena = true;
cfg.profiles[cfg.profile].flrig_host = $("#radio_host").val().trim();
cfg.profiles[cfg.profile].flrig_port = $("#radio_port").val().trim();
break;
case 'hamlib':
cfg.profiles[cfg.profile].hamlib_ena = true;
cfg.profiles[cfg.profile].hamlib_host = $("#radio_host").val().trim();
cfg.profiles[cfg.profile].hamlib_port = $("#radio_port").val().trim();
cfg.profiles[cfg.profile].ignore_pwr = $("#ignore_pwr").is(':checked');
break;
case 'none':
default:
// All radio settings already disabled
break;
}
cfg=await ipcRenderer.sendSync("set_config", cfg);
});
bt_quit.addEventListener('click', () => {
cleanup(); // Clear all timers and connections before quit
const x=ipcRenderer.sendSync("quit", '');
});
bt_test.addEventListener('click', () => {
cfg.profiles[active_cfg].wavelog_url=$("#wavelog_url").val().trim();
cfg.profiles[active_cfg].wavelog_key=$("#wavelog_key").val().trim();
cfg.profiles[active_cfg].wavelog_id=$("#wavelog_id").val().trim();
cfg.profiles[active_cfg].wavelog_radioname=$("#wavelog_radioname").val().trim();
const x=(ipcRenderer.sendSync("test", cfg.profiles[active_cfg]));
if (x.payload.status == 'created') {
$("#test").removeClass('btn-primary');
$("#test").removeClass('btn-danger');
$("#test").addClass('btn-success');
$("#msg2").hide();
$("#msg2").html("");
} else {
$("#test").removeClass('btn-primary');
$("#test").removeClass('btn-success');
$("#test").addClass('btn-danger');
$("#msg2").show();
$("#msg2").html("Test failed. Reason: "+x.payload.reason);
}
});
input_key.addEventListener('change', () => {
getStations();
});
input_url.addEventListener('change', () => {
getStations();
});
$('#reload_icon').on('click', () => {
getStations();
});
utcTimeInterval = setInterval(updateUtcTime, 1000);
window.onload = updateUtcTime;
$("#config-tab").on("click",function() {
const obj={};
obj.width=430;
obj.height=550;
obj.ani=false;
resizeme(obj);
});
$("#status-tab").on("click",function() {
const obj={};
obj.width=430;
obj.height=250;
obj.ani=false;
resizeme(obj);
});
ipcRenderer.on('get_info', async (event, arg) => {
const result = await getInfo(arg);
ipcRenderer.send('get_info_result', result);
});
// Handle cleanup request from main process
ipcRenderer.on('cleanup', () => {
cleanup();
});
// Dropdown change handler
$('#radio_type').change(function() {
updateRadioFields();
});
// Profile manager modal event listeners
$('#btnCreateProfile').click(createProfile);
$('#btnSelectProfile').click(switchToSelectedProfile);
$('#newProfileName').keypress((e) => {
if (e.which === 13) createProfile();
});
// Use event delegation for dynamically created radio buttons
$('#profileList').on('change', 'input[type="radio"]', function() {
selectedProfileIndex = parseInt($(this).val());
});
// Use event delegation for rename and delete buttons
$('#profileList').on('click', '.btn-rename', function() {
const index = parseInt($(this).closest('.list-group-item').data('index'));
renameProfile(index);
});
$('#profileList').on('click', '.btn-delete', function() {
const index = parseInt($(this).closest('.list-group-item').data('index'));
deleteProfile(index);
});
});
async function load_config() {
cfg=await ipcRenderer.sendSync("get_config", '');
active_cfg = cfg.profile || 0;
const profileName = cfg.profileNames?.[active_cfg] || `Profile ${active_cfg + 1}`;
$("#toggle").html(profileName);
$("#wavelog_url").val(cfg.profiles[active_cfg].wavelog_url);
$("#wavelog_key").val(cfg.profiles[active_cfg].wavelog_key);
// $("#wavelog_id").val(cfg.wavelog_id);
$("#wavelog_radioname").val(cfg.profiles[active_cfg].wavelog_radioname);
$("#wavelog_pmode").prop("checked", cfg.profiles[active_cfg].wavelog_pmode);
// Set radio type based on existing configuration
if (cfg.profiles[active_cfg].flrig_ena) {
$('#radio_type').val('flrig');
} else if (cfg.profiles[active_cfg].hamlib_ena) {
$('#radio_type').val('hamlib');
} else {
$('#radio_type').val('none');
}
// Update radio fields based on selection
updateRadioFields();
if (cfg.profiles[active_cfg].wavelog_key != "" && cfg.profiles[active_cfg].wavelog_url != "") {
getStations();
}
if (trxpoll === undefined) {
getsettrx();
}
}
function resizeme(size) {
x=(ipcRenderer.sendSync("resize", size))
return x;
}
function select(selector) {
return document.querySelector(selector);
}
function updateRadioFields() {
const selectedRadio = $('#radio_type').val();
// Reset all fields
$("#radio_host").prop('disabled', selectedRadio === 'none');
$("#radio_port").prop('disabled', selectedRadio === 'none');
$("#wavelog_pmode").prop('disabled', selectedRadio === 'none');
$("#hamlib_options").hide();
// Update field labels and values based on selection
switch(selectedRadio) {
case 'flrig':
$("#host_label").text("FLRig Host");
$("#port_label").text("FLRig Port");
$("#pmode_label").text("Set MODE via FLRig");
$("#radio_host").val(cfg.profiles[active_cfg].flrig_host || '127.0.0.1');
$("#radio_port").val(cfg.profiles[active_cfg].flrig_port || '12345');
$("#wavelog_pmode").prop('checked', cfg.profiles[active_cfg].wavelog_pmode);
break;
case 'hamlib':
$("#host_label").text("Hamlib Host");
$("#port_label").text("Hamlib Port");
$("#pmode_label").text("Set MODE via Hamlib");
$("#radio_host").val(cfg.profiles[active_cfg].hamlib_host || '127.0.0.1');
$("#radio_port").val(cfg.profiles[active_cfg].hamlib_port || '4532');
$("#wavelog_pmode").prop('checked', cfg.profiles[active_cfg].wavelog_pmode);
$("#hamlib_options").show();
$("#ignore_pwr").prop('checked', cfg.profiles[active_cfg].ignore_pwr);
break;
case 'none':
default:
$("#host_label").text("Radio Host");
$("#port_label").text("Radio Port");
$("#pmode_label").text("Set MODE via Radio");
$("#radio_host").val('');
$("#radio_port").val('');
break;
}
}
window.TX_API.onUpdateMsg((value) => {
$("#msg").html(value);
$("#msg2").html("");
});
window.TX_API.onUpdateTX((value) => {
if (value.created) {
$("#log").html('<div class="alert alert-success" role="alert">'+value.qsos[0].TIME_ON+" "+value.qsos[0].CALL+" ("+(value.qsos[0].GRIDSQUARE || 'No Grid')+") on "+(value.qsos[0].BAND || 'No BAND')+" (R:"+(value.qsos[0].RST_RCVD || 'No RST')+" / S:"+(value.qsos[0].RST_SENT || 'No RST')+') - OK</div>');
} else {
$("#log").html('<div class="alert alert-danger" role="alert">'+value.qsos[0].TIME_ON+" "+value.qsos[0].CALL+" ("+(value.qsos[0].GRIDSQUARE || 'No Grid')+") on "+(value.qsos[0].BAND || 'NO BAND')+" (R:"+(value.qsos[0].RST_RCVD || 'No RST')+" / S:"+(value.qsos[0].RST_SENT || 'No RST')+') - Error<br/>Reason: '+value.fail.payload.reason+'</div>');
}
})
async function get_trx() {
let currentCat={};
currentCat.vfo=await getInfo('rig.get_vfo');
currentCat.mode=await getInfo('rig.get_mode');
currentCat.ptt=await getInfo('rig.get_ptt');
if(!cfg.profiles[active_cfg].ignore_pwr){
currentCat.power=await getInfo('rig.get_power') ?? 0;
}
currentCat.split=await getInfo('rig.get_split');
currentCat.vfoB=await getInfo('rig.get_vfoB');
currentCat.modeB=await getInfo('rig.get_modeB');
$("#current_trx").html((currentCat.vfo/(1000*1000))+" MHz / "+currentCat.mode);
if (((Date.now()-lastCat) > (30*60*1000)) || (!(isDeepEqual(oldCat,currentCat)))) {
console.log(await informWavelog(currentCat));
}
oldCat=currentCat;
return currentCat;
}
async function getInfo(which) {
if (cfg.profiles[active_cfg].flrig_ena){
const abortController = new AbortController();
activeAbortControllers.add(abortController);
try {
const response = await fetch(
"http://"+$("#radio_host").val()+':'+$("#radio_port").val(), {
method: 'POST',
// mode: 'no-cors',
headers: {
'Accept': 'application/json, application/xml, text/plain, text/html, *.*',
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
},
body: '<?xml version="1.0"?><methodCall><methodName>'+which+'</methodName></methodCall>',
signal: abortController.signal
}
);
const data = await response.text();
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(data, "application/xml");
const valueNode = xmlDoc.querySelector("methodResponse > params > param > value");
if (!valueNode) {
return null;
}
const arrayNode = valueNode.querySelector("array > data");
if (arrayNode) {
const items = Array.from(arrayNode.querySelectorAll("value string, value"))
.map(node => node.textContent.trim());
return items;
} else {
return valueNode.textContent.trim();
}
} catch (e) {
return '';
} finally {
// Always clean up abort controller when done
activeAbortControllers.delete(abortController);
}
}
if (cfg.profiles[active_cfg].hamlib_ena) {
var commands = {"rig.get_vfo": "f", "rig.get_mode": "m", "rig.get_modes": "M ? 0", "rig.get_ptt": 0, "rig.get_power": 0, "rig.get_split": 0, "rig.get_vfoB": 0, "rig.get_modeB": 0};
const host = cfg.profiles[active_cfg].hamlib_host;
const port = parseInt(cfg.profiles[active_cfg].hamlib_port, 10);
return new Promise((resolve, reject) => {
if (commands[which]) {
const client = net.createConnection({ host, port }, () => {
client.write(commands[which] + "\n");
});
// Track the connection for cleanup
activeConnections.add(client);
client.on('data', (data) => {
data = data.toString()
if(data.startsWith("RPRT")){
reject();
} else {
if (which === 'rig.get_modes') {
// Parse modes list - split by whitespace and filter empty strings
const modes = data.trim().split(/\s+/).filter(mode => mode.length > 0);
resolve(modes);
} else {
resolve(data.split('\n')[0]);
}
}
client.end();
});
client.on('error', (err) => {
activeConnections.delete(client);
reject();
});
client.on("close", () => {
activeConnections.delete(client);
});
} else {
resolve(undefined);
}
});
}
}
async function getsettrx() {
if (cfg.profiles[active_cfg].flrig_ena || cfg.profiles[active_cfg].hamlib_ena) {
console.log('Polling TRX '+trxpoll);
const x=get_trx();
}
trxpoll = setTimeout(() => {
getsettrx();
}, 1000);
}
const isDeepEqual = (object1, object2) => {
const objKeys1 = Object.keys(object1);
const objKeys2 = Object.keys(object2);
if (objKeys1.length !== objKeys2.length) return false;
for (const key of objKeys1) {
const value1 = object1[key];
const value2 = object2[key];
const isObjects = isObject(value1) && isObject(value2);
if ((isObjects && !isDeepEqual(value1, value2)) ||
(!isObjects && value1 !== value2)
) {
return false;
}
}
return true;
};
const isObject = (object) => {
return object != null && typeof object === "object";
};
async function informWavelog(CAT) {
lastCat=Date.now();
let data = {
radio: cfg.profiles[active_cfg].wavelog_radioname || "WLGate",
key: cfg.profiles[active_cfg].wavelog_key,
};
if (CAT.power !== undefined && CAT.power !== 0) {
data.power = CAT.power;
}
// if (CAT.ptt !== undefined) { // not impleented yet in Wavelog, so maybe later
// data.ptt = CAT.ptt;
// }
if (CAT.split == '1') {
// data.split=true; // not implemented yet in Wavelog
data.frequency=CAT.vfoB;
data.mode=CAT.modeB;
data.frequency_rx=CAT.vfo;
data.mode_rx=CAT.mode;
} else {
data.frequency=CAT.vfo;
data.mode=CAT.mode;
}
const { ipcRenderer } = require('electron');
console.log(data);
ipcRenderer.send('radio_status_update', data);
let x=await fetch(cfg.profiles[active_cfg].wavelog_url + '/api/radio', {
method: 'POST',
rejectUnauthorized: false,
headers: {
Accept: 'application.json',
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
});
return x;
}
function cleanupConnections() {
console.log('Cleaning up renderer TCP connections...');
// Close all tracked TCP connections
activeConnections.forEach(connection => {
try {
if (connection && !connection.destroyed) {
connection.destroy();
console.log('Closed renderer TCP connection');
}
} catch (error) {
console.error('Error closing renderer TCP connection:', error);
}
});
// Clear the connections set
activeConnections.clear();
console.log('All renderer TCP connections cleaned up');
// Abort all in-flight HTTP requests
activeAbortControllers.forEach(controller => {
try {
controller.abort();
console.log('Aborted HTTP request');
} catch (error) {
console.error('Error aborting HTTP request:', error);
}
});
// Clear the abort controllers set
activeAbortControllers.clear();
console.log('All HTTP requests aborted');
}
function cleanup() {
// Clear radio polling timeout
if (trxpoll) {
clearTimeout(trxpoll);
trxpoll = undefined;
console.log('Cleared radio polling timeout');
}
// Clear UTC time update interval
if (utcTimeInterval) {
clearInterval(utcTimeInterval);
utcTimeInterval = undefined;
console.log('Cleared UTC time update interval');
}
// Clean up TCP connections
cleanupConnections();
}
function updateUtcTime() {
const now = new Date();
const hours = ('0' + now.getUTCHours()).slice(-2);
const minutes = ('0' + now.getUTCMinutes()).slice(-2);
const seconds = ('0' + now.getUTCSeconds()).slice(-2);
const formattedTime = `${hours}:${minutes}:${seconds}z`;
document.getElementById('utc').innerHTML = formattedTime;
}
async function getStations() {
const select = $('#wavelog_id');
select.empty();
select.prop('disabled', true);
try {
const x = await fetch($('#wavelog_url').val().trim() + '/api/station_info/' + $('#wavelog_key').val().trim(), {
method: 'GET',
rejectUnauthorized: false,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});
if (!x.ok) {
throw new Error(`HTTP error! Status: ${x.status}`);
}
const data = await x.json();
fillDropdown(data);
} catch (error) {
select.append(new Option('Failed to load stations', '0'));
console.error('Could not load station locations:', error.message);
}
}
function fillDropdown(data) {
const select = $('#wavelog_id');
select.empty();
select.prop('disabled', false);
data.forEach(function(station) {
const optionText = station.station_profile_name + " (" + station.station_callsign + ", ID: " + station.station_id + ")";
const optionValue = station.station_id;
select.append(new Option(optionText, optionValue));
});
if (cfg.profiles[active_cfg].wavelog_id && data.some(station => station.station_id == cfg.profiles[active_cfg].wavelog_id)) {
select.val(cfg.profiles[active_cfg].wavelog_id);
} else {
select.val(data.length > 0 ? data[0].station_id : null);
}
}
// Dynamic Profile System Functions
let selectedProfileIndex = null;
function openProfileManager() {
selectedProfileIndex = cfg.profile || 0;
renderProfileList();
$('#profileModal').modal('show');
}
function renderProfileList() {
const listEl = $('#profileList');
listEl.empty();
cfg.profiles.forEach((profile, index) => {
const isActive = index === (cfg.profile || 0);
const name = cfg.profileNames?.[index] || `Profile ${index + 1}`;
const item = $(`
<div class="list-group-item" data-index="${index}">
<div class="d-flex align-items-center">
<input type="radio" name="profileSelect" value="${index}"
${index === selectedProfileIndex ? 'checked' : ''}>
<span class="ml-2 profile-name">${name}</span>
${isActive ? '<span class="badge badge-success ml-2">Active</span>' : ''}
<div class="ml-auto">
<button class="btn btn-sm btn-outline-secondary btn-rename">Rename</button>
<button class="btn btn-sm btn-outline-danger btn-delete"
${isActive || cfg.profiles.length <= 2 ? 'disabled' : ''}>
Delete
</button>
</div>
</div>
</div>
`);
listEl.append(item);
});
}
async function createProfile() {
const name = $('#newProfileName').val().trim();
if (!name) {
alert('Please enter a profile name');
return;
}
const result = ipcRenderer.sendSync('create_profile', name);
if (result.success) {
$('#newProfileName').val('');
await load_config();
renderProfileList();
}
}
async function deleteProfile(index) {
const name = cfg.profileNames?.[index] || `Profile ${index + 1}`;
if (!confirm(`Delete "${name}"?`)) return;
const result = ipcRenderer.sendSync('delete_profile', index);
if (result.success) {
if ((cfg.profile || 0) === index) {
active_cfg = 0;
}
await load_config();
renderProfileList();
} else {
alert(result.error);
}
}
async function renameProfile(index) {
const currentName = cfg.profileNames?.[index] || `Profile ${index + 1}`;
// Use a simple Bootstrap prompt via the modal
const newName = await showRenamePrompt(currentName);
if (newName && newName.trim() && newName !== currentName) {
ipcRenderer.sendSync('rename_profile', index, newName.trim());
await load_config();
renderProfileList();
}
}
function showRenamePrompt(currentName) {
return new Promise((resolve) => {
// Create a simple Bootstrap modal for input
const modalHtml = `
<div class="modal fade" id="renameModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Rename Profile</h5>
<button type="button" class="close" data-dismiss="modal">
<span>×</span>
</button>
</div>
<div class="modal-body">
<input type="text" class="form-control" id="renameInput" value="${currentName}">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" id="renameCancel">Cancel</button>
<button type="button" class="btn btn-primary" id="renameOk">OK</button>
</div>
</div>
</div>
</div>
`;
// Remove any existing rename modal
$('#renameModal').remove();
// Add the new modal
$('body').append(modalHtml);
const $modal = $('#renameModal');
const $input = $('#renameInput');
// Handle OK button
$('#renameOk').click(() => {
$modal.modal('hide');
resolve($input.val());
});
// Handle Cancel button and X button
$('#renameCancel, #renameModal .close').click(() => {
$modal.modal('hide');
resolve(null);
});
// Handle Enter key
$input.keypress((e) => {
if (e.which === 13) {
$modal.modal('hide');
resolve($input.val());
}
});
// Handle modal hidden event
$modal.on('hidden.bs.modal', () => {
$('#renameModal').remove();
});
// Show the modal
$modal.modal('show');
$input.focus().select();
});
}
async function switchToSelectedProfile() {
if (selectedProfileIndex === null || selectedProfileIndex === (cfg.profile || 0)) {
$('#profileModal').modal('hide');
return;
}
ipcRenderer.sendSync('switch_profile', selectedProfileIndex);
active_cfg = selectedProfileIndex;
await load_config();
$('#profileModal').modal('hide');
// Reset test button to default state (no test run on new profile yet)
$("#test").removeClass('btn-success');
$("#test").removeClass('btn-danger');
$("#test").addClass('btn-primary');
$("#msg2").hide();
}