mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-31 14:50:48 +03:00
luci: Fix restart service when pressed on Save&Apply or Restart buttons
This commit is contained in:
@@ -50,6 +50,6 @@ return baseclass.extend({
|
|||||||
dst_obj.packager.args = [ 'list-installed', '*'+this.appName+'*' ];
|
dst_obj.packager.args = [ 'list-installed', '*'+this.appName+'*' ];
|
||||||
}
|
}
|
||||||
dst_obj.skey_pkg_dict = this.appName + '-pkg-dict';
|
dst_obj.skey_pkg_dict = this.appName + '-pkg-dict';
|
||||||
dst_obj.skey_need_restart = this.appName + '-need-restart';
|
dst_obj.skey_deffered_action = this.appName + '-deffered-action';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -62,7 +62,9 @@ return view.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setAppStatus: function(status_array, elems = { }, force_app_status = 0) {
|
setAppStatus: function(status_array, elems = { }, force_app_status = 0)
|
||||||
|
{
|
||||||
|
tools.execDefferedAction();
|
||||||
let cfg = uci.get(tools.appName, 'config');
|
let cfg = uci.get(tools.appName, 'config');
|
||||||
if (!status_array || cfg == null || typeof(cfg) !== 'object') {
|
if (!status_array || cfg == null || typeof(cfg) !== 'object') {
|
||||||
let elem_status = elems.status || document.getElementById("status");
|
let elem_status = elems.status || document.getElementById("status");
|
||||||
@@ -141,6 +143,15 @@ return view.extend({
|
|||||||
this.disableButtons(true, btn);
|
this.disableButtons(true, btn);
|
||||||
poll.stop();
|
poll.stop();
|
||||||
try {
|
try {
|
||||||
|
if (action == 'start' || action == 'restart') {
|
||||||
|
let apply_exec = tools.checkUnsavedChanges();
|
||||||
|
if (apply_exec) {
|
||||||
|
ui.changes.apply(true); // apply_rollback
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
tools.setDefferedAction(action, null, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
await tools.serviceActionEx(action, args, false);
|
await tools.serviceActionEx(action, args, false);
|
||||||
if (hide_modal) {
|
if (hide_modal) {
|
||||||
ui.hideModal();
|
ui.hideModal();
|
||||||
@@ -148,13 +159,14 @@ return view.extend({
|
|||||||
} catch(e) {
|
} catch(e) {
|
||||||
//ui.addNotification(null, E('p', 'Error: ' + e.message));
|
//ui.addNotification(null, E('p', 'Error: ' + e.message));
|
||||||
} finally {
|
} finally {
|
||||||
if (btn && btn_dis) {
|
setTimeout(() => {
|
||||||
setTimeout(() => { btn.disabled = true; }, 0);
|
if (btn && btn_dis) {
|
||||||
}
|
btn.disabled = true;
|
||||||
if (!poll.active()) {
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, 10));
|
if (!poll.active()) {
|
||||||
poll.start();
|
poll.start();
|
||||||
}
|
}
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -285,8 +297,6 @@ return view.extend({
|
|||||||
}
|
}
|
||||||
let cfg = uci.get(tools.appName, 'config');
|
let cfg = uci.get(tools.appName, 'config');
|
||||||
|
|
||||||
tools.checkAndRestartSvc(status_array[2]); // svc_info
|
|
||||||
|
|
||||||
let pkgdict = status_array[4];
|
let pkgdict = status_array[4];
|
||||||
if (pkgdict == null) {
|
if (pkgdict == null) {
|
||||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': render()'));
|
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': render()'));
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ return view.extend({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.svc_info = data.svc_info;
|
this.svc_info = data.svc_info;
|
||||||
tools.checkAndRestartSvc(this.svc_info);
|
tools.execDefferedAction(this.svc_info);
|
||||||
|
|
||||||
let m, s, o, tabname;
|
let m, s, o, tabname;
|
||||||
|
|
||||||
@@ -458,10 +458,14 @@ return view.extend({
|
|||||||
handleSaveApply: function(ev, mode)
|
handleSaveApply: function(ev, mode)
|
||||||
{
|
{
|
||||||
return this.handleSave(ev).then(() => {
|
return this.handleSave(ev).then(() => {
|
||||||
ui.changes.apply(mode == '0');
|
let apply_exec = tools.checkUnsavedChanges();
|
||||||
if (this.svc_info?.dmn.inited) {
|
if (apply_exec) {
|
||||||
localStorage.setItem(tools.skey_need_restart, '1');
|
ui.changes.apply(mode == '0');
|
||||||
console.log('STOR KEY: '+tools.skey_need_restart+' = 1');
|
tools.setDefferedAction('restart', this.svc_info);
|
||||||
|
} else {
|
||||||
|
if (this.svc_info?.dmn.inited) {
|
||||||
|
tools.serviceActionEx('restart');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -160,10 +160,6 @@ return baseclass.extend({
|
|||||||
let exec_cmd = null;
|
let exec_cmd = null;
|
||||||
let exec_arg = [ ];
|
let exec_arg = [ ];
|
||||||
if (action == 'start' || action == 'restart') {
|
if (action == 'start' || action == 'restart') {
|
||||||
if (this.checkUnsavedChanges()) {
|
|
||||||
await ui.changes.apply(true);
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
|
||||||
}
|
|
||||||
exec_cmd = this.syncCfgPath;
|
exec_cmd = this.syncCfgPath;
|
||||||
errmsg = _('Unable to run sync_config.sh script.');
|
errmsg = _('Unable to run sync_config.sh script.');
|
||||||
}
|
}
|
||||||
@@ -198,7 +194,7 @@ return baseclass.extend({
|
|||||||
uci.load(this.appName),
|
uci.load(this.appName),
|
||||||
])
|
])
|
||||||
.then( ([svcInfo, uci_data]) => {
|
.then( ([svcInfo, uci_data]) => {
|
||||||
let svc_info = this.decode_svc_info(true, svcInfo, [ ], null);
|
let svc_info = this.decodeSvcInfo(svcInfo);
|
||||||
let ret = { svc_info, uci_data };
|
let ret = { svc_info, uci_data };
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
const res = callback(cbarg, ret);
|
const res = callback(cbarg, ret);
|
||||||
@@ -215,23 +211,49 @@ return baseclass.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
checkAndRestartSvc: function(svcInfo)
|
decodeSvcInfo: function(svc_info, svc_autorun = true, proc_list = [ ])
|
||||||
{
|
{
|
||||||
let svc_info = null;
|
if (svc_info?.autorun !== undefined && svc_info?.dmn !== undefined) {
|
||||||
if (svcInfo?.autorun !== undefined && svcInfo?.dmn !== undefined) {
|
return svc_info;
|
||||||
svc_info = svcInfo;
|
|
||||||
} else
|
|
||||||
if (typeof(svcInfo) == 'object') {
|
|
||||||
svc_info = this.decode_svc_info(true, svcInfo, [ ], null);
|
|
||||||
}
|
}
|
||||||
//console.log('checkAndRestartSvc: svc_info = '+JSON.stringify(svc_info));
|
if (svc_info != null && typeof(svc_info) == 'object') {
|
||||||
let need_restart = localStorage.getItem(this.skey_need_restart);
|
return this.decode_svc_info(svc_autorun, svc_info, proc_list);
|
||||||
if (need_restart) {
|
}
|
||||||
localStorage.removeItem(this.skey_need_restart);
|
return null;
|
||||||
if (svcInfo?.dmn !== undefined && svc_info.dmn.inited) {
|
},
|
||||||
this.serviceActionEx('restart');
|
|
||||||
|
setDefferedAction: function(action, svcInfo = null, forced = false)
|
||||||
|
{
|
||||||
|
let svc_info = this.decodeSvcInfo(svcInfo);
|
||||||
|
if (action == 'start' && svc_info?.dmn.inited) {
|
||||||
|
action = 'restart';
|
||||||
|
}
|
||||||
|
if (action == 'start') {
|
||||||
|
if (!forced && svc_info?.dmn.inited) {
|
||||||
|
action = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (action == 'restart') {
|
||||||
|
if (!forced && !svc_info?.dmn.inited) {
|
||||||
|
action = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (action && localStorage.getItem(this.skey_deffered_action) == null) {
|
||||||
|
localStorage.setItem(this.skey_deffered_action, action);
|
||||||
|
console.log('setDefferedAction: '+this.skey_deffered_action+' = '+action);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
execDefferedAction: function(svcInfo = null)
|
||||||
|
{
|
||||||
|
let svc_info = this.decodeSvcInfo(svcInfo);
|
||||||
|
//console.log('execDefferedAction: svc_info = '+JSON.stringify(svc_info));
|
||||||
|
let action = localStorage.getItem(this.skey_deffered_action);
|
||||||
|
if (action) {
|
||||||
|
localStorage.removeItem(this.skey_deffered_action);
|
||||||
|
console.log('execDefferedAction: '+action);
|
||||||
|
this.serviceActionEx(action);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
checkUnsavedChanges: function()
|
checkUnsavedChanges: function()
|
||||||
@@ -320,7 +342,8 @@ return baseclass.extend({
|
|||||||
return plist;
|
return plist;
|
||||||
},
|
},
|
||||||
|
|
||||||
decode_svc_info: function(svc_autorun, svc_info, proc_list, cfg) {
|
decode_svc_info: function(svc_autorun, svc_info, proc_list, cfg = null)
|
||||||
|
{
|
||||||
let result = {
|
let result = {
|
||||||
"autorun": svc_autorun,
|
"autorun": svc_autorun,
|
||||||
"dmn": {
|
"dmn": {
|
||||||
@@ -341,6 +364,9 @@ return baseclass.extend({
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (svc_info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (typeof(svc_info) !== 'object') {
|
if (typeof(svc_info) !== 'object') {
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user