From 35fbc76df441756e5044bcc9784ab3219a8d6701 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 6 Dec 2020 21:17:05 -0500 Subject: Settings v2 testing setup (#1084) * Add option for using settings v2 * Add options/info about settings v2 * Use settings v2 URL when applicable * Update tests --- ext/bg/data/options-schema.json | 7 ++++++- ext/bg/js/backend.js | 15 ++++++++++++++- ext/bg/js/context-main.js | 4 +++- ext/bg/js/options.js | 2 ++ ext/bg/settings.html | 10 ++++++++++ ext/bg/settings2.html | 22 ++++++++++++++++++++++ test/test-options-util.js | 3 ++- 7 files changed, 59 insertions(+), 4 deletions(-) diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json index 2da48041..4a953243 100644 --- a/ext/bg/data/options-schema.json +++ b/ext/bg/data/options-schema.json @@ -797,7 +797,8 @@ "type": "object", "required": [ "database", - "showPopupPreview" + "showPopupPreview", + "useSettingsV2" ], "properties": { "database": { @@ -815,6 +816,10 @@ "showPopupPreview": { "type": "boolean", "default": false + }, + "useSettingsV2": { + "type": "boolean", + "default": false } } } diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index f9c308e5..012036dc 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -790,12 +790,25 @@ class Backend { } _onCommandOptions(params) { + const {useSettingsV2} = this._options.global; const {mode='existingOrNewTab'} = params || {}; if (mode === 'existingOrNewTab') { + if (useSettingsV2) { + (async () => { + const url = chrome.runtime.getURL('/bg/settings2.html'); + const tab = await this._findTab(1000, (url2) => url2.startsWith(url)); + if (tab !== null) { + await this._focusTab(tab); + } else { + chrome.tabs.create({url}); + } + })(); + return; + } chrome.runtime.openOptionsPage(); } else if (mode === 'newTab') { const manifest = chrome.runtime.getManifest(); - const url = chrome.runtime.getURL(manifest.options_ui.page); + const url = chrome.runtime.getURL(useSettingsV2 ? '/bg/settings2.html' : manifest.options_ui.page); chrome.tabs.create({url}); } } diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js index 93eebe72..b6736fd8 100644 --- a/ext/bg/js/context-main.js +++ b/ext/bg/js/context-main.js @@ -30,12 +30,14 @@ class DisplayController { this._showExtensionInfo(manifest); this._setupEnvironment(); this._setupButtonEvents('.action-open-search', 'search', chrome.runtime.getURL('/bg/search.html')); - this._setupButtonEvents('.action-open-options', 'options', chrome.runtime.getURL(manifest.options_ui.page)); this._setupButtonEvents('.action-open-help', 'help', 'https://foosoft.net/projects/yomichan/'); const optionsFull = await api.optionsGetFull(); this._optionsFull = optionsFull; + const optionsPageUrl = optionsFull.global.useSettingsV2 ? '/bg/settings2.html' : manifest.options_ui.page; + this._setupButtonEvents('.action-open-options', 'options', chrome.runtime.getURL(optionsPageUrl)); + const {profiles, profileCurrent} = optionsFull; const primaryProfile = (profileCurrent >= 0 && profileCurrent < profiles.length) ? profiles[profileCurrent] : null; if (primaryProfile !== null) { diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index dcc8471a..5fb10516 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -613,10 +613,12 @@ class OptionsUtil { // Version 6 changes: // Updated handlebars templates to include "conjugation" definition. // Added global option showPopupPreview. + // Added global option useSettingsV2. // Added anki.checkForDuplicates. // Added general.glossaryLayoutMode; removed general.compactGlossaries. await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v6.handlebars'); options.global.showPopupPreview = false; + options.global.useSettingsV2 = false; for (const profile of options.profiles) { profile.options.anki.checkForDuplicates = true; profile.options.general.glossaryLayoutMode = (profile.options.general.compactGlossaries ? 'compact' : 'default'); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index c168d7d8..acb07a60 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -21,6 +21,12 @@

Yomichan Options

+
+ + An updated version of the settings page is available for testing and feedback. + +
+

Profiles

@@ -192,6 +198,10 @@
+
+ +
+
+
+ + +

Profile

diff --git a/test/test-options-util.js b/test/test-options-util.js index 2e59c7ea..cfb1c87d 100644 --- a/test/test-options-util.js +++ b/test/test-options-util.js @@ -503,7 +503,8 @@ function createOptionsUpdatedTestData1() { database: { prefixWildcardsSupported: false }, - showPopupPreview: false + showPopupPreview: false, + useSettingsV2: false } }; } -- cgit v1.2.3