diff --git a/src/bg/Settings.js b/src/bg/Settings.js index bd98dd6..b6b2ede 100644 --- a/src/bg/Settings.js +++ b/src/bg/Settings.js @@ -102,7 +102,7 @@ var Settings = { ns.defaults.local.isTorBrowser = true; // prevents reset from forgetting ns.defaults.sync.cascadeRestrictions = true; // we want this to be the default even on reset Sites.onionSecure = true; - + ns.local.torBrowserPolicy = policy; // save for reset if (!this.gotTorBrowserInit) { // First initialization message from the Tor Browser this.gotTorBrowserInit = true; @@ -111,13 +111,14 @@ var Settings = { // copying the Security Level preset on startup (only). // Manually changing the security level works as usual. ns.local.isTorBrowser = true; - await ns.save(ns.local); + await Promise.all([ns.saveSession(), ns.save(ns.local)]); + this.reloadOptionsUI(); return; } - } else { - reloadOptionsUI = true; } + reloadOptionsUI = true; + if (policy && policy.TRUSTED) { // Gracefully handle "new" capabilities still unknown to our settings host const knownCapabilities = settingsHost && settingsHost.knownCapabilities @@ -151,13 +152,9 @@ var Settings = { } if (settings.sync === null) { - // user is resetting options - policy = this.createDefaultDryPolicy(); - - // overriden defaults when user manually resets options - - // we want the reset options to stick (otherwise it gets very confusing) - ns.defaults.sync.overrideTorBrowserPolicy = true; + // User is resetting options: + // pick either current Tor Browser Security Level or default NoScript policy + policy = ns.local.torBrowserPolicy || this.createDefaultDryPolicy(); reloadOptionsUI = true; } diff --git a/src/bg/main.js b/src/bg/main.js index 306ce2f..4d32233 100644 --- a/src/bg/main.js +++ b/src/bg/main.js @@ -71,14 +71,12 @@ if (data) { ns.policy = new Policy(data.policy); ns.unrestrictedTabs = new Set(data.unrestrictedTabs); - Settings.gotTorBrowserInit = data.gotTorBrowserInit; } }, beforeSave() { // beforeSave return { policy: ns.policy.dry(true), unrestrictedTabs: [...ns.unrestrictedTabs], - gotTorBrowserInit: Settings.gotTorBrowserInit, }; }, } @@ -401,6 +399,10 @@ return obj; }, + async saveSession() { + await session.save(); + }, + async collectSeen(tabId) { await this.initializing; try {