Skip to content

Commit 91728f1

Browse files
authored
Merge pull request #33 from gotoradio/master
Advanced settngs
2 parents fddf1c2 + 8bd2fc9 commit 91728f1

File tree

5 files changed

+348
-63
lines changed

5 files changed

+348
-63
lines changed

advanced.html

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta http-equiv="Content-Security-Policy"
7+
content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9+
<!-- Bootstrap CSS -->
10+
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css" />
11+
<script>let $ = require("jquery");</script>
12+
<script>require("popper.js");</script>
13+
<script>require("bootstrap");</script>
14+
</head>
15+
16+
<style>
17+
html, body {
18+
overflow-x: hidden;
19+
margin: 0;
20+
padding: 0;
21+
background-color: #303030;
22+
color: #c6c6c6;
23+
}
24+
25+
body {
26+
background-color: #303030;
27+
color: #c6c6c6;
28+
}
29+
30+
input[type="checkbox"] {
31+
accent-color: #b3b3b3;
32+
}
33+
34+
.card {
35+
background-color: #303030;
36+
color: #c6c6c6;
37+
border: 1px solid #727272;
38+
}
39+
40+
.card {
41+
position: fixed;
42+
top: 0;
43+
left: 0;
44+
width: 100%;
45+
height: 100%;
46+
}
47+
48+
.card-header,
49+
.card-footer {
50+
background-color: #1c1c1c;
51+
}
52+
53+
.btn-primary {
54+
background-color: #375a7f;
55+
border-color: #375a7f;
56+
}
57+
58+
.bottom-right {
59+
position: fixed;
60+
bottom: 0;
61+
right: 0;
62+
padding: 4px;
63+
}
64+
65+
.nav-link {
66+
height: 30px;
67+
padding: 0px;
68+
color: #c6c6c6;
69+
border: 1px solid #303030;
70+
}
71+
72+
.nav-tabs .nav-item.show .nav-link,
73+
.nav-tabs .nav-link.active {
74+
color: #c6c6c6;
75+
background-color: #303030;
76+
border: 1px solid #303030;
77+
}
78+
79+
.nav-tabs .nav-link {
80+
background-color: #262626;
81+
}
82+
83+
.log,
84+
.log-qrg,
85+
.log-text {
86+
margin: 4px;
87+
padding-left: 4px;
88+
padding-right: 4px;
89+
}
90+
91+
.form-control,
92+
.log {
93+
background-color: #1c1c1c;
94+
color: #b3b3b3;
95+
border: 1px solid #727272;
96+
}
97+
98+
.form-control:focus {
99+
color: inherit;
100+
background-color: #1c1c1c;
101+
}
102+
103+
.form-control:disabled, .form-control[readonly] {
104+
background-color: #3e3e3e;
105+
opacity: 1;
106+
}
107+
108+
#buttonsRow {
109+
position: fixed;
110+
bottom: 8px;
111+
width: 100%;
112+
padding: 10px;
113+
}
114+
115+
#reload_icon {
116+
width: 16px;
117+
height: 16px;
118+
margin-left: 4px;
119+
margin-bottom: 2px;
120+
vertical-align: middle;
121+
fill: white;
122+
}
123+
124+
label {
125+
display: flex;
126+
align-items: center;
127+
}
128+
129+
label svg {
130+
cursor: pointer;
131+
}
132+
</style>
133+
134+
<body>
135+
<main>
136+
<div class="container">
137+
<div class="row">
138+
<div class="col">
139+
<div class="mb-3 col-mb-3">
140+
<label for="hamlib_host">Hamlib Host</label>
141+
<input type="text" class="form-control form-control-sm" name="hamlib_host"
142+
id="hamlib_host" value="" />
143+
</div>
144+
</div>
145+
<div class="col">
146+
<div class="mb-2 col-mb-2">
147+
<label for="hamlib_port">Hamlib Port</label>
148+
<input type="number" class="form-control form-control-sm" name="hamlib_port"
149+
id="hamlib_port" value="" />
150+
</div>
151+
</div>
152+
<div class="col">
153+
<div class="mb-1 col-mb-1">
154+
<label for="hamlib_ena">Hamlib Enabled</label>
155+
<input type="checkbox" value="1" class="form-control form-control-sm" name="hamlib_ena" id="hamlib_ena" value="" />
156+
</div>
157+
</div>
158+
</div>
159+
<div class="row">
160+
<div class="col">
161+
<div class="mb-1 col-mb-1">
162+
<label for="ignore_pwr">Ignore Power</label>
163+
<input type="checkbox" value="1" class="form-control form-control-sm" name="ignore_pwr" id="ignore_pwr" title="log out of wavelog to disregard old value" value="" />
164+
</div>
165+
</div>
166+
</div>
167+
<div class="row" id="buttonsRow">
168+
<div class="col">
169+
<div class="mb-3 col-mb-3" style="text-align: left">
170+
<button type="button" class="btn btn-primary" id="save"></i>Save</button>
171+
</div>
172+
</div>
173+
</div>
174+
<script src="./advanced.js"></script>
175+
</div>
176+
</main>
177+
</body>
178+
</html>

advanced.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const {ipcRenderer} = require('electron');
2+
3+
var cfg = {};
4+
5+
const bt_save=document.querySelector("#save");
6+
7+
$(document).ready(function() {
8+
cfg=ipcRenderer.sendSync("get_config", '');
9+
10+
$("#hamlib_host").val(cfg.hamlib_host);
11+
$("#hamlib_port").val(cfg.hamlib_port);
12+
$("#hamlib_ena").prop("checked", cfg.hamlib_ena);
13+
$("#ignore_pwr").prop("checked", cfg.ignore_pwr);
14+
15+
bt_save.addEventListener('click', () => {
16+
cfg=ipcRenderer.sendSync("get_config", '');
17+
cfg.hamlib_host=$("#hamlib_host").val().trim();
18+
cfg.hamlib_port=$("#hamlib_port").val().trim();
19+
cfg.hamlib_ena=$("#hamlib_ena").is(':checked');
20+
cfg.ignore_pwr=$("#ignore_pwr").is(':checked');
21+
22+
if ($("#hamlib_ena").is(':checked') && cfg.flrig_ena){cfg.flrig_ena = false;}
23+
24+
x=ipcRenderer.sendSync("set_config", cfg);
25+
// console.log(x);
26+
27+
});
28+
});

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@
112112
vertical-align: middle;
113113
fill: white;
114114
}
115-
115+
116116
label {
117117
display: flex;
118118
align-items: center;
119119
}
120-
120+
121121
label svg {
122-
cursor: pointer;
122+
cursor: pointer;
123123
}
124124
</style>
125125

main.js

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require('node:path');
33
const {ipcMain} = require('electron')
44
const http = require('http');
55
const xml = require("xml2js");
6+
const net = require('net');
67

78
let s_mainWindow;
89
let 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

2934
const storage = require('electron-json-storage');
3035

3136
app.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-
4338
function 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+
6894
ipcMain.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

77102
ipcMain.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

91119
ipcMain.on("setCAT", async (event,arg) => {
@@ -119,6 +147,7 @@ ipcMain.on("test", async (event,arg) => {
119147

120148
app.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

Comments
 (0)