From 161888d9a3dc154261637c019ad152031be9ec8e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 11 Jul 2020 15:20:51 -0400 Subject: Remove backend options context (#661) * Add support for getting the current profile * Explicitly use current options --- ext/bg/js/backend.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ext/bg/js/backend.js') diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 07c32fa2..f6c2ef74 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -64,9 +64,6 @@ class Backend { }); this._templateRenderer = new TemplateRenderer(); - const url = (typeof window === 'object' && window !== null ? window.location.href : ''); - this._optionsContext = {depth: 0, url}; - this._clipboardPasteTarget = ( typeof document === 'object' && document !== null ? document.querySelector('#clipboard-paste-target') : @@ -208,7 +205,7 @@ class Backend { this._applyOptions('background'); - const options = this.getOptions(this._optionsContext); + const options = this.getOptions({current: true}); if (options.general.showGuide) { chrome.tabs.create({url: chrome.runtime.getURL('/bg/guide.html')}); } @@ -782,7 +779,7 @@ class Backend { async _onCommandSearch(params) { const {mode='existingOrNewTab', query} = params || {}; - const options = this.getOptions(this._optionsContext); + const options = this.getOptions({current: true}); const {popupWidth, popupHeight} = options.general; const baseUrl = chrome.runtime.getURL('/bg/search.html'); @@ -859,7 +856,7 @@ class Backend { async _onCommandToggle() { const source = 'popup'; - const options = this.getOptions(this._optionsContext); + const options = this.getOptions({current: true}); options.general.enable = !options.general.enable; await this._onApiOptionsSave({source}); } @@ -891,7 +888,7 @@ class Backend { } _applyOptions(source) { - const options = this.getOptions(this._optionsContext); + const options = this.getOptions({current: true}); this._updateBadge(); this._anki.setServer(options.anki.server); @@ -915,11 +912,14 @@ class Backend { _getProfile(optionsContext, useSchema=false) { const options = this.getFullOptions(useSchema); const profiles = options.profiles; + if (optionsContext.current) { + return profiles[options.profileCurrent]; + } if (typeof optionsContext.index === 'number') { return profiles[optionsContext.index]; } const profile = this._getProfileFromContext(options, optionsContext); - return profile !== null ? profile : options.profiles[options.profileCurrent]; + return profile !== null ? profile : profiles[options.profileCurrent]; } _getProfileFromContext(options, optionsContext) { -- cgit v1.2.3