fix(tor-shield): Preset selection now immediately activates preset
- Clicking a preset card now enables/restarts Tor with that preset - Previously it only selected the preset for next toggle - Added better error handling for toggle and preset changes - Page reloads after successful preset change Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
2ebc06f2ce
commit
87f3dab30a
@ -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:=7
|
PKG_RELEASE:=8
|
||||||
PKG_ARCH:=all
|
PKG_ARCH:=all
|
||||||
|
|
||||||
PKG_LICENSE:=MIT
|
PKG_LICENSE:=MIT
|
||||||
|
|||||||
@ -19,6 +19,7 @@ return view.extend({
|
|||||||
handleToggle: function() {
|
handleToggle: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
||||||
// Show loading while fetching current status
|
// Show loading while fetching current status
|
||||||
ui.showModal(_('Please wait...'), [
|
ui.showModal(_('Please wait...'), [
|
||||||
E('p', { 'class': 'spinning' }, _('Checking current status...'))
|
E('p', { 'class': 'spinning' }, _('Checking current status...'))
|
||||||
@ -38,10 +39,13 @@ return view.extend({
|
|||||||
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');
|
||||||
window.location.reload();
|
setTimeout(function() { window.location.reload(); }, 1000);
|
||||||
} 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', _('Disable error: %s').format(err.message || String(err))), 'error');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Enable Tor with selected preset
|
// Enable Tor with selected preset
|
||||||
@ -53,27 +57,49 @@ return view.extend({
|
|||||||
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();
|
setTimeout(function() { window.location.reload(); }, 1000);
|
||||||
} 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) {
|
||||||
|
ui.hideModal();
|
||||||
|
ui.addNotification(null, E('p', _('Enable error: %s').format(err.message || String(err))), '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', _('Status error: %s').format(err.message || String(err))), 'error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Handle preset selection
|
// Handle preset selection - immediately activates the preset
|
||||||
handlePresetSelect: function(presetId) {
|
handlePresetSelect: function(presetId) {
|
||||||
|
var self = this;
|
||||||
this.currentPreset = presetId;
|
this.currentPreset = presetId;
|
||||||
|
|
||||||
// Update UI
|
// Update UI immediately
|
||||||
var presets = document.querySelectorAll('.tor-preset');
|
var presets = document.querySelectorAll('.tor-preset');
|
||||||
presets.forEach(function(p) {
|
presets.forEach(function(p) {
|
||||||
p.classList.toggle('active', p.dataset.preset === presetId);
|
p.classList.toggle('active', p.dataset.preset === presetId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Enable/restart with selected preset
|
||||||
|
ui.showModal(_('Applying Preset'), [
|
||||||
|
E('p', { 'class': 'spinning' }, _('Activating %s preset...').format(presetId))
|
||||||
|
]);
|
||||||
|
|
||||||
|
api.enable(presetId).then(function(result) {
|
||||||
|
ui.hideModal();
|
||||||
|
if (result.success) {
|
||||||
|
ui.addNotification(null, E('p', _('Preset %s activated').format(presetId)), 'info');
|
||||||
|
setTimeout(function() { window.location.reload(); }, 1000);
|
||||||
|
} else {
|
||||||
|
ui.addNotification(null, E('p', result.error || _('Failed to apply preset')), 'error');
|
||||||
|
}
|
||||||
|
}).catch(function(err) {
|
||||||
|
ui.hideModal();
|
||||||
|
ui.addNotification(null, E('p', _('Error: %s').format(err.message || String(err))), 'error');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Handle new identity request
|
// Handle new identity request
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user