diff --git a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/env.js b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/env.js index 4548f4a..19b1222 100644 --- a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/env.js +++ b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/env.js @@ -31,24 +31,39 @@ return baseclass.extend({ autoHostListFN : '/opt/zapret2/ipset/zapret-hosts-auto.txt', autoHostListDbgFN : '/opt/zapret2/ipset/zapret-hosts-auto-debug.log', - load_env: function(dst_obj) { + load_env: function(ctx) + { let env_proto = Object.getPrototypeOf(this); Object.getOwnPropertyNames(env_proto).forEach(function(key) { - if (key === 'constructor' || key === 'load_env' || key.startsWith('__')) + if (key === 'constructor' || key.startsWith('__')) { return; - dst_obj[key] = env_proto[key]; + } + if (key === 'load_env' || key === 'load_feat_env') { + return; + } + ctx[key] = env_proto[key]; }); - dst_obj.packager = { }; - if (L.hasSystemFeature('apk')) { - dst_obj.packager.name = 'apk'; - dst_obj.packager.path = '/usr/bin/apk'; - dst_obj.packager.args = [ 'list', '-I', '*'+this.appName+'*' ]; - } else { - dst_obj.packager.name = 'opkg'; - dst_obj.packager.path = '/bin/opkg'; - dst_obj.packager.args = [ 'list-installed', '*'+this.appName+'*' ]; + 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 } - dst_obj.skey_pkg_dict = this.appName + '-pkg-dict'; - dst_obj.skey_deffered_action = this.appName + '-deffered-action'; - } + }, + + load_feat_env: function(ctx) + { + ctx.packager = { }; + if (L.hasSystemFeature('apk')) { + ctx.packager.name = 'apk'; + ctx.packager.path = '/usr/bin/apk'; + ctx.packager.args = [ 'list', '-I', '*'+this.appName+'*' ]; + } else { + ctx.packager.name = 'opkg'; + ctx.packager.path = '/bin/opkg'; + ctx.packager.args = [ 'list-installed', '*'+this.appName+'*' ]; + } + }, }); diff --git a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js index 3e6b46f..9075031 100644 --- a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js +++ b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js @@ -46,7 +46,8 @@ return view.extend({ btn.update.disabled = (error_code == 0) ? flag : false; }, - getAppStatus: function() { + getAppStatus: function() + { return Promise.all([ tools.getInitState(tools.appName), // svc_boot fs.exec(tools.execPath, [ 'enabled' ]), // svc_en @@ -294,9 +295,9 @@ return view.extend({ load: function() { - return Promise.all([ - L.resolveDefault(fs.stat('/bin/cat'), null), - ]).then( (data) => { + return tools.baseLoad(this, (data) => { + //console.log('SYS FEATURES: '+JSON.stringify(data.sys_feat)); + tools.load_feat_env(); return this.getAppStatus(); }); }, diff --git a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/settings.js b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/settings.js index 08b7353..2c3bc13 100644 --- a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/settings.js +++ b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/settings.js @@ -15,11 +15,17 @@ document.head.appendChild(E('link', { return view.extend({ svc_info: null, - load: function() { - return tools.baseLoad(); + load: function() + { + 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) { return; } diff --git a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/tools.js b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/tools.js index e860cc7..5631693 100644 --- a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/tools.js +++ b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/tools.js @@ -40,7 +40,12 @@ return baseclass.extend({ env_tools.load_env(this); //console.log('appName: ' + this.appName); //console.log('PACKAGER: ' + this.packager.name); - }, + }, + + load_feat_env: function() + { + env_tools.load_feat_env(this); + }, infoLabelRunning : '' + _('Running') + '', infoLabelStarting : '' + _('Starting') + '', @@ -189,19 +194,20 @@ return baseclass.extend({ } }, - baseLoad: function(callback, cbarg) + baseLoad: function(ctx, callback) { return Promise.all([ + L.probeSystemFeatures(), this.getSvcInfo(), // svc_info uci.load(this.appName), ]) - .then( ([svcInfo, uci_data]) => { + .then( ([ sys_feat, svcInfo, uci_data ]) => { let svc_info = this.decodeSvcInfo(svcInfo); - let ret = { svc_info, uci_data }; - if (typeof callback === 'function') { - const res = callback(cbarg, ret); - if (res && typeof res.then === 'function') { - return res.then(() => ret); + let ret = { sys_feat, svc_info, uci_data }; + if (typeof(callback) === 'function') { + const res = callback.call(ctx, ret); + if (res && typeof(res.then) === 'function') { + return res.then(() => res); } return ret; }