luci: Fix error on call L.hasSystemFeature('apk')

This commit is contained in:
remittor
2026-01-28 08:26:27 +03:00
parent cd21487f7d
commit 6c9587af06
4 changed files with 58 additions and 30 deletions

View File

@@ -31,24 +31,39 @@ return baseclass.extend({
autoHostListFN : '/opt/zapret2/ipset/zapret-hosts-auto.txt', autoHostListFN : '/opt/zapret2/ipset/zapret-hosts-auto.txt',
autoHostListDbgFN : '/opt/zapret2/ipset/zapret-hosts-auto-debug.log', autoHostListDbgFN : '/opt/zapret2/ipset/zapret-hosts-auto-debug.log',
load_env: function(dst_obj) { load_env: function(ctx)
{
let env_proto = Object.getPrototypeOf(this); let env_proto = Object.getPrototypeOf(this);
Object.getOwnPropertyNames(env_proto).forEach(function(key) { Object.getOwnPropertyNames(env_proto).forEach(function(key) {
if (key === 'constructor' || key === 'load_env' || key.startsWith('__')) if (key === 'constructor' || key.startsWith('__')) {
return; return;
dst_obj[key] = env_proto[key]; }
if (key === 'load_env' || key === 'load_feat_env') {
return;
}
ctx[key] = env_proto[key];
}); });
dst_obj.packager = { }; ctx.skey_pkg_dict = this.appName + '-pkg-dict';
ctx.skey_deffered_action = this.appName + '-deffered-action';
try {
L.hasSystemFeature('opkg');
this.load_feat_env(ctx);
} catch(e) {
// nothing
}
},
load_feat_env: function(ctx)
{
ctx.packager = { };
if (L.hasSystemFeature('apk')) { if (L.hasSystemFeature('apk')) {
dst_obj.packager.name = 'apk'; ctx.packager.name = 'apk';
dst_obj.packager.path = '/usr/bin/apk'; ctx.packager.path = '/usr/bin/apk';
dst_obj.packager.args = [ 'list', '-I', '*'+this.appName+'*' ]; ctx.packager.args = [ 'list', '-I', '*'+this.appName+'*' ];
} else { } else {
dst_obj.packager.name = 'opkg'; ctx.packager.name = 'opkg';
dst_obj.packager.path = '/bin/opkg'; ctx.packager.path = '/bin/opkg';
dst_obj.packager.args = [ 'list-installed', '*'+this.appName+'*' ]; ctx.packager.args = [ 'list-installed', '*'+this.appName+'*' ];
}
dst_obj.skey_pkg_dict = this.appName + '-pkg-dict';
dst_obj.skey_deffered_action = this.appName + '-deffered-action';
} }
},
}); });

View File

@@ -46,7 +46,8 @@ return view.extend({
btn.update.disabled = (error_code == 0) ? flag : false; btn.update.disabled = (error_code == 0) ? flag : false;
}, },
getAppStatus: function() { getAppStatus: function()
{
return Promise.all([ return Promise.all([
tools.getInitState(tools.appName), // svc_boot tools.getInitState(tools.appName), // svc_boot
fs.exec(tools.execPath, [ 'enabled' ]), // svc_en fs.exec(tools.execPath, [ 'enabled' ]), // svc_en
@@ -294,9 +295,9 @@ return view.extend({
load: function() load: function()
{ {
return Promise.all([ return tools.baseLoad(this, (data) => {
L.resolveDefault(fs.stat('/bin/cat'), null), //console.log('SYS FEATURES: '+JSON.stringify(data.sys_feat));
]).then( (data) => { tools.load_feat_env();
return this.getAppStatus(); return this.getAppStatus();
}); });
}, },

View File

@@ -15,11 +15,17 @@ document.head.appendChild(E('link', {
return view.extend({ return view.extend({
svc_info: null, svc_info: null,
load: function() { load: function()
return tools.baseLoad(); {
return tools.baseLoad(this, (data) => {
//console.log('SYS FEATURES: '+JSON.stringify(data.sys_feat));
tools.load_feat_env();
return data;
});
}, },
render: function(data) { render: function(data)
{
if (!data) { if (!data) {
return; return;
} }

View File

@@ -42,6 +42,11 @@ return baseclass.extend({
//console.log('PACKAGER: ' + this.packager.name); //console.log('PACKAGER: ' + this.packager.name);
}, },
load_feat_env: function()
{
env_tools.load_feat_env(this);
},
infoLabelRunning : '<span class="label-status running">' + _('Running') + '</span>', infoLabelRunning : '<span class="label-status running">' + _('Running') + '</span>',
infoLabelStarting : '<span class="label-status starting">' + _('Starting') + '</span>', infoLabelStarting : '<span class="label-status starting">' + _('Starting') + '</span>',
infoLabelStopped : '<span class="label-status stopped">' + _('Stopped') + '</span>', infoLabelStopped : '<span class="label-status stopped">' + _('Stopped') + '</span>',
@@ -189,19 +194,20 @@ return baseclass.extend({
} }
}, },
baseLoad: function(callback, cbarg) baseLoad: function(ctx, callback)
{ {
return Promise.all([ return Promise.all([
L.probeSystemFeatures(),
this.getSvcInfo(), // svc_info this.getSvcInfo(), // svc_info
uci.load(this.appName), uci.load(this.appName),
]) ])
.then( ([svcInfo, uci_data]) => { .then( ([ sys_feat, svcInfo, uci_data ]) => {
let svc_info = this.decodeSvcInfo(svcInfo); let svc_info = this.decodeSvcInfo(svcInfo);
let ret = { svc_info, uci_data }; let ret = { sys_feat, svc_info, uci_data };
if (typeof callback === 'function') { if (typeof(callback) === 'function') {
const res = callback(cbarg, ret); const res = callback.call(ctx, ret);
if (res && typeof res.then === 'function') { if (res && typeof(res.then) === 'function') {
return res.then(() => ret); return res.then(() => res);
} }
return ret; return ret;
} }