mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-11 15:07:51 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,108 @@
|
||||
'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() {
|
||||
uci.load('modeminfo');
|
||||
|
||||
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() === '') {
|
||||
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) {
|
||||
ca = "+";
|
||||
} else {
|
||||
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'));
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user