Fixed init status

This commit is contained in:
gSpot
2021-11-03 19:11:15 +03:00
parent a008297225
commit 8d5022cdfd
10 changed files with 46 additions and 22 deletions

View File

@@ -11,16 +11,16 @@ Dependences: lua, luci-lib-nixio, libuci-lua
opkg install /tmp/internet-detector_0.3.0-1_all.ipk opkg install /tmp/internet-detector_0.3.0-1_all.ipk
rm /tmp/internet-detector_0.3.0-1_all.ipk rm /tmp/internet-detector_0.3.0-1_all.ipk
wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.3.0-1_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-app-internet-detector_0.3.0-1_all.ipk wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.3.0-2_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-app-internet-detector_0.3.0-2_all.ipk
opkg install /tmp/luci-app-internet-detector_0.3.0-1_all.ipk opkg install /tmp/luci-app-internet-detector_0.3.0-2_all.ipk
rm /tmp/luci-app-internet-detector_0.3.0-1_all.ipk rm /tmp/luci-app-internet-detector_0.3.0-2_all.ipk
/etc/init.d/rpcd reload /etc/init.d/rpcd reload
**i18n-ru:** **i18n-ru:**
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk https://github.com/gSpotx2f/luci-app-internet-detector/raw/master/packages/19.07/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk opkg install /tmp/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_0.3.0-1_all.ipk rm /tmp/luci-i18n-internet-detector-ru_0.3.0-2_all.ipk
**Script for LED control:** **Script for LED control:**

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_VERSION:=0.3.0 PKG_VERSION:=0.3.0
PKG_RELEASE:=1 PKG_RELEASE:=2
LUCI_TITLE:=LuCI support for internet-detector LUCI_TITLE:=LuCI support for internet-detector
LUCI_DEPENDS:=+internet-detector LUCI_DEPENDS:=+internet-detector
LUCI_PKGARCH:=all LUCI_PKGARCH:=all

View File

@@ -11,7 +11,6 @@ const btnStyleApply = 'btn cbi-button-apply';
return L.view.extend({ return L.view.extend({
execPath : '/usr/bin/internet-detector', execPath : '/usr/bin/internet-detector',
initPath : '/etc/init.d/internet-detector',
upScriptPath : '/etc/internet-detector/up-script', upScriptPath : '/etc/internet-detector/up-script',
downScriptPath : '/etc/internet-detector/down-script', downScriptPath : '/etc/internet-detector/down-script',
runScriptPath : '/etc/internet-detector/run-script', runScriptPath : '/etc/internet-detector/run-script',
@@ -30,6 +29,26 @@ return L.view.extend({
uiCheckIntervalDown : null, uiCheckIntervalDown : null,
currentAppMode : '0', currentAppMode : '0',
callInitStatus: rpc.declare({
object: 'luci',
method: 'getInitList',
params: [ 'name' ],
expect: { '': {} }
}),
getInitStatus: function() {
return this.callInitStatus('internet-detector').then(res => {
if(res) {
return res['internet-detector'].enabled;
} else {
throw _('Command failed');
}
}).catch(e => {
ui.addNotification(null,
E('p', _('Failed to get %s init status: %s').format('internet-detector', e)));
});
},
callInitAction: rpc.declare({ callInitAction: rpc.declare({
object: 'luci', object: 'luci',
method: 'setInitAction', method: 'setInitAction',
@@ -45,7 +64,7 @@ return L.view.extend({
return true; return true;
}).catch(e => { }).catch(e => {
ui.addNotification(null, ui.addNotification(null,
E('p', _('Failed to execute "%s %s": %s').format(this.initPath, action, e))); E('p', _('Service action failed "%s %s": %s').format('internet-detector', action, e)));
}); });
}, },
@@ -191,27 +210,27 @@ return L.view.extend({
'click': ui.createHandlerFn(this.ctx, this.ctx.serviceRestart), 'click': ui.createHandlerFn(this.ctx, this.ctx.serviceRestart),
}, _('Restart')); }, _('Restart'));
this.ctx.initButton = E('button', { this.ctx.initButton = E('button', {
'class': (this.ctx.initStatus === 1) ? btnStyleDisabled : btnStyleEnabled, 'class': (!this.ctx.initStatus) ? btnStyleDisabled : btnStyleEnabled,
'click': ui.createHandlerFn(this, () => { 'click': ui.createHandlerFn(this, () => {
return this.ctx.handleServiceAction( return this.ctx.handleServiceAction(
(this.ctx.initStatus === 1) ? 'enable' : 'disable' (!this.ctx.initStatus) ? 'enable' : 'disable'
).then(success => { ).then(success => {
if(!success) { if(!success) {
return; return;
}; };
if(this.ctx.initStatus === 1) { if(!this.ctx.initStatus) {
this.ctx.initButton.textContent = _('Enabled'); this.ctx.initButton.textContent = _('Enabled');
this.ctx.initButton.className = btnStyleEnabled; this.ctx.initButton.className = btnStyleEnabled;
this.ctx.initStatus = 0; this.ctx.initStatus = true;
} }
else { else {
this.ctx.initButton.textContent = _('Disabled'); this.ctx.initButton.textContent = _('Disabled');
this.ctx.initButton.className = btnStyleDisabled; this.ctx.initButton.className = btnStyleDisabled;
this.ctx.initStatus = 1; this.ctx.initStatus = false;
}; };
}); });
}), }),
}, (this.ctx.initStatus == 1) ? _('Disabled') : _('Enabled')); }, (!this.ctx.initStatus) ? _('Disabled') : _('Enabled'));
this.ctx.setInternetStatus(true); this.ctx.setInternetStatus(true);
@@ -316,7 +335,7 @@ return L.view.extend({
load: function() { load: function() {
return Promise.all([ return Promise.all([
fs.exec(this.execPath, [ 'status' ]), fs.exec(this.execPath, [ 'status' ]),
fs.exec(this.initPath, [ 'enabled' ]), this.getInitStatus(),
uci.load('internet-detector'), uci.load('internet-detector'),
]).catch(e => { ]).catch(e => {
ui.addNotification(null, E('p', _('An error has occurred') + ': %s'.format(e.message))); ui.addNotification(null, E('p', _('An error has occurred') + ': %s'.format(e.message)));
@@ -328,7 +347,7 @@ return L.view.extend({
return; return;
}; };
this.appStatus = (data[0].code === 0) ? data[0].stdout.trim() : null; this.appStatus = (data[0].code === 0) ? data[0].stdout.trim() : null;
this.initStatus = data[1].code; this.initStatus = data[1];
this.currentAppMode = uci.get('internet-detector', 'config', 'mode'); this.currentAppMode = uci.get('internet-detector', 'config', 'mode');
this.uiCheckIntervalUp = Number(uci.get('internet-detector', 'config', 'ui_interval_up')); this.uiCheckIntervalUp = Number(uci.get('internet-detector', 'config', 'ui_interval_up'));
this.uiCheckIntervalDown = Number(uci.get('internet-detector', 'config', 'ui_interval_down')); this.uiCheckIntervalDown = Number(uci.get('internet-detector', 'config', 'ui_interval_down'));

View File

@@ -93,8 +93,8 @@ msgstr "Выполнение команд при подключении к Ин
msgid "Execute commands when the Internet is disconnected" msgid "Execute commands when the Internet is disconnected"
msgstr "Выполнение команд при отключении от Интернет" msgstr "Выполнение команд при отключении от Интернет"
msgid "Failed to execute \"%s %s\": %s" msgid "Failed to get %s init status: %s"
msgstr "Не удалось выполнить \"%s %s\": %s" msgstr "Не удалось получить статус инициализации %s: %s"
msgid "Host availability check type" msgid "Host availability check type"
msgstr "Тип проверки доступности хоста" msgstr "Тип проверки доступности хоста"
@@ -156,6 +156,9 @@ msgstr "Сохранить"
msgid "Service" msgid "Service"
msgstr "Служба" msgstr "Служба"
msgid "Service action failed \"%s %s\": %s"
msgstr "Не удалось выполнить действие службы \"%s %s\": %s"
msgid "Service configuration" msgid "Service configuration"
msgstr "Конфигурация службы" msgstr "Конфигурация службы"

View File

@@ -82,7 +82,7 @@ msgstr ""
msgid "Execute commands when the Internet is disconnected" msgid "Execute commands when the Internet is disconnected"
msgstr "" msgstr ""
msgid "Failed to execute \"%s %s\": %s" msgid "Failed to get %s init status: %s"
msgstr "" msgstr ""
msgid "Host availability check type" msgid "Host availability check type"
@@ -142,6 +142,9 @@ msgstr ""
msgid "Service" msgid "Service"
msgstr "" msgstr ""
msgid "Service action failed \"%s %s\": %s"
msgstr ""
msgid "Service configuration" msgid "Service configuration"
msgstr "" msgstr ""

View File

@@ -6,12 +6,11 @@
"/etc/internet-detector/up-script": [ "read" ], "/etc/internet-detector/up-script": [ "read" ],
"/etc/internet-detector/down-script": [ "read" ], "/etc/internet-detector/down-script": [ "read" ],
"/etc/internet-detector/run-script": [ "read" ], "/etc/internet-detector/run-script": [ "read" ],
"/etc/init.d/internet-detector": [ "exec" ],
"/usr/bin/internet-detector*": [ "exec" ] "/usr/bin/internet-detector*": [ "exec" ]
}, },
"uci": [ "internet-detector" ], "uci": [ "internet-detector" ],
"ubus": { "ubus": {
"luci": [ "setInitAction" ] "luci": [ "getInitList", "setInitAction" ]
} }
}, },
"write": { "write": {

Binary file not shown.

Binary file not shown.