mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-08-02 07:29:28 +08:00
116 lines
3.1 KiB
JavaScript
116 lines
3.1 KiB
JavaScript
'use strict';
|
|
'require baseclass';
|
|
'require form';
|
|
'require fs';
|
|
'require ui';
|
|
'require uci';
|
|
|
|
/*
|
|
Written by Konstantine Shevlakov at <shevlakov@132lan.ru> 2023
|
|
|
|
Licensed to the GNU General Public License v3.0.
|
|
|
|
Special Thanks to Vladislav Kadulin aka @Kodo-kakaku
|
|
https://github.com/Kodo-kakaku/ to fix update overview page
|
|
|
|
*/
|
|
|
|
return baseclass.extend({
|
|
title: _('Cellular network'),
|
|
|
|
load: async function() {
|
|
await uci.load('modeminfo');
|
|
var index = uci.sections('modeminfo', 'general');
|
|
if (!index || !index[0] || index[0].index !== "1") {
|
|
return null;
|
|
};
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const timeout = setTimeout(() => {
|
|
reject(new Error('Timeout: modeminfo execution took too long'));
|
|
}, 30000); // 30 sec timeout
|
|
|
|
fs.exec_direct('/usr/bin/modeminfo')
|
|
.then(result => {
|
|
clearTimeout(timeout);
|
|
resolve(result);
|
|
})
|
|
.catch(error => {
|
|
clearTimeout(timeout);
|
|
reject(error);
|
|
});
|
|
}).catch(error => {
|
|
console.error('Error loading modeminfo:', error);
|
|
return '';
|
|
});
|
|
},
|
|
|
|
render: function(data){
|
|
if (!data || data.trim() === '') {
|
|
var index = uci.sections('modeminfo', 'general');
|
|
if (!index || !index[0] || index[0].index !== "1") {
|
|
return null;
|
|
} else {
|
|
return E('div', {
|
|
'class': 'cbi-section',
|
|
'style': 'color: #999; text-align: center;'
|
|
}, _('Wait devices information'));
|
|
}
|
|
}
|
|
|
|
try {
|
|
var json = JSON.parse(data);
|
|
var index = uci.sections('modeminfo', 'general');
|
|
let modemTBL = E('div', { 'class': 'cbi-section' });
|
|
|
|
if (json.modem && index[0].index == "1"){
|
|
for (var i = 0; i < json.modem.length; i++) {
|
|
var signal = document.createElement('div');
|
|
var icn;
|
|
var signalIcons = [
|
|
{ max: -1, icn: 'signal-000-000.svg' },
|
|
{ max: 0, icn: 'signal-000-000.svg' },
|
|
{ max: 10, icn: 'signal-000-000.svg' },
|
|
{ max: 25, icn: 'signal-000-025.svg' },
|
|
{ max: 50, icn: 'signal-025-050.svg' },
|
|
{ max: 75, icn: 'signal-050-075.svg' },
|
|
{ max: Infinity, icn: 'signal-075-100.svg' }
|
|
];
|
|
|
|
var p = json.modem[i].csq_per || 0;
|
|
var { icn } = signalIcons.find(({ max }) => p <= max);
|
|
var icon = L.resource(`view/modem/icons/${icn}`);
|
|
|
|
var per = p+'%';
|
|
|
|
var ca = "";
|
|
if (json.modem[i].lteca > 0 && json.modem[i].mode !== 'LTE+NR') {
|
|
ca = "+";
|
|
}
|
|
|
|
signal.innerHTML = String.format(
|
|
'<span class="ifacebadge">' + json.modem[i].cops + " " +
|
|
'<img src="%s"/><b>'+per.fontcolor(json.modem[i].csq_col) + "</b> " +
|
|
json.modem[i].mode+ca + '</span>', icon, p );
|
|
|
|
modemTBL.append(
|
|
E('table', { 'class': 'table' }, [
|
|
E('tr', { 'class': 'tr' }, [
|
|
E('td', { 'class': 'td left', 'width': '33%' }, [ json.modem[i].device ]),
|
|
E('td', { 'class': 'td left', 'id': 'device' }, [ signal ])
|
|
])
|
|
])
|
|
);
|
|
};
|
|
return modemTBL;
|
|
};
|
|
} catch (error) {
|
|
console.error('Error parsing modeminfo data:', error);
|
|
return E('div', {
|
|
'class': 'cbi-section',
|
|
'style': 'color: #999; text-align: center;'
|
|
}, _('Error loading information'));
|
|
}
|
|
},
|
|
});
|