fix(tor-shield): Fix toggle using stale status, fetch fresh before action
The toggle handler was receiving status captured at render time which could be stale due to polling. Now fetches fresh status before deciding to enable or disable, and does a full page reload after action. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
98fafccf05
commit
e44f801f36
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=luci-app-tor-shield
|
PKG_NAME:=luci-app-tor-shield
|
||||||
PKG_VERSION:=1.0.0
|
PKG_VERSION:=1.0.0
|
||||||
PKG_RELEASE:=6
|
PKG_RELEASE:=7
|
||||||
PKG_ARCH:=all
|
PKG_ARCH:=all
|
||||||
|
|
||||||
PKG_LICENSE:=MIT
|
PKG_LICENSE:=MIT
|
||||||
|
|||||||
@ -15,27 +15,33 @@ return view.extend({
|
|||||||
return api.getDashboardData();
|
return api.getDashboardData();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Handle master toggle
|
// Handle master toggle - fetches fresh status first
|
||||||
handleToggle: function(status) {
|
handleToggle: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
// Show loading while fetching current status
|
||||||
|
ui.showModal(_('Please wait...'), [
|
||||||
|
E('p', { 'class': 'spinning' }, _('Checking current status...'))
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Get fresh status before deciding action
|
||||||
|
api.getStatus().then(function(status) {
|
||||||
|
ui.hideModal();
|
||||||
|
|
||||||
if (status.enabled && status.running) {
|
if (status.enabled && status.running) {
|
||||||
// Disable Tor
|
// Disable Tor
|
||||||
ui.showModal(_('Disable Tor Shield'), [
|
ui.showModal(_('Disable Tor Shield'), [
|
||||||
E('p', { 'class': 'spinning' }, _('Stopping Tor Shield...'))
|
E('p', { 'class': 'spinning' }, _('Stopping Tor Shield...'))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
api.disable().then(function(result) {
|
return api.disable().then(function(result) {
|
||||||
ui.hideModal();
|
ui.hideModal();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
ui.addNotification(null, E('p', _('Tor Shield disabled. Your traffic is no longer anonymized.')), 'warning');
|
ui.addNotification(null, E('p', _('Tor Shield disabled. Your traffic is no longer anonymized.')), 'warning');
|
||||||
self.render();
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
ui.addNotification(null, E('p', result.error || _('Failed to disable')), 'error');
|
ui.addNotification(null, E('p', result.error || _('Failed to disable')), 'error');
|
||||||
}
|
}
|
||||||
}).catch(function(err) {
|
|
||||||
ui.hideModal();
|
|
||||||
ui.addNotification(null, E('p', _('Error: %s').format(err.message || err)), 'error');
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Enable Tor with selected preset
|
// Enable Tor with selected preset
|
||||||
@ -43,18 +49,20 @@ return view.extend({
|
|||||||
E('p', { 'class': 'spinning' }, _('Starting Tor Shield with %s preset...').format(self.currentPreset))
|
E('p', { 'class': 'spinning' }, _('Starting Tor Shield with %s preset...').format(self.currentPreset))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
api.enable(self.currentPreset).then(function(result) {
|
return api.enable(self.currentPreset).then(function(result) {
|
||||||
ui.hideModal();
|
ui.hideModal();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
ui.addNotification(null, E('p', _('Tor Shield is starting. Please wait for bootstrap to complete.')), 'info');
|
ui.addNotification(null, E('p', _('Tor Shield is starting. Please wait for bootstrap to complete.')), 'info');
|
||||||
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
ui.addNotification(null, E('p', result.error || _('Failed to enable')), 'error');
|
ui.addNotification(null, E('p', result.error || _('Failed to enable')), 'error');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
ui.hideModal();
|
ui.hideModal();
|
||||||
ui.addNotification(null, E('p', _('Error: %s').format(err.message || err)), 'error');
|
ui.addNotification(null, E('p', _('Error: %s').format(err.message || err)), 'error');
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Handle preset selection
|
// Handle preset selection
|
||||||
@ -295,9 +303,7 @@ return view.extend({
|
|||||||
'type': 'checkbox',
|
'type': 'checkbox',
|
||||||
'checked': isActive ? 'checked' : null,
|
'checked': isActive ? 'checked' : null,
|
||||||
'style': 'opacity: 0; width: 0; height: 0;',
|
'style': 'opacity: 0; width: 0; height: 0;',
|
||||||
'change': L.bind(function(ev) {
|
'change': L.bind(this.handleToggle, this)
|
||||||
this.handleToggle(status);
|
|
||||||
}, this)
|
|
||||||
}),
|
}),
|
||||||
E('span', {
|
E('span', {
|
||||||
'style': 'position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: ' + (isActive ? '#fff' : 'rgba(255,255,255,0.3)') + '; transition: 0.3s; border-radius: 34px;'
|
'style': 'position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: ' + (isActive ? '#fff' : 'rgba(255,255,255,0.3)') + '; transition: 0.3s; border-radius: 34px;'
|
||||||
@ -381,7 +387,7 @@ return view.extend({
|
|||||||
E('div', { 'class': 'tor-toggle-section' }, [
|
E('div', { 'class': 'tor-toggle-section' }, [
|
||||||
E('button', {
|
E('button', {
|
||||||
'class': 'tor-master-toggle' + (isActive ? ' active' : ''),
|
'class': 'tor-master-toggle' + (isActive ? ' active' : ''),
|
||||||
'click': L.bind(function() { this.handleToggle(status); }, this),
|
'click': L.bind(this.handleToggle, this),
|
||||||
'title': isActive ? _('Click to disable') : _('Click to enable')
|
'title': isActive ? _('Click to disable') : _('Click to enable')
|
||||||
}, '\uD83E\uDDC5'),
|
}, '\uD83E\uDDC5'),
|
||||||
E('div', { 'class': 'tor-toggle-label' + (isActive ? ' active' : '') },
|
E('div', { 'class': 'tor-toggle-label' + (isActive ? ' active' : '') },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user