From 0506cfbee5443635ebd6ac79054b85f171775039 Mon Sep 17 00:00:00 2001 From: praschke Date: Tue, 17 Oct 2023 21:21:30 +0100 Subject: initial handlebars patch --- ext/js/data/options-util.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ext/js/data') diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 2674701f..7b050416 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -470,7 +470,8 @@ class OptionsUtil { {async: false, update: this._updateVersion17.bind(this)}, {async: false, update: this._updateVersion18.bind(this)}, {async: false, update: this._updateVersion19.bind(this)}, - {async: false, update: this._updateVersion20.bind(this)} + {async: false, update: this._updateVersion20.bind(this)}, + {async: true, update: this._updateVersion21.bind(this)} ]; if (typeof targetVersion === 'number' && targetVersion < result.length) { result.splice(targetVersion); @@ -997,4 +998,9 @@ class OptionsUtil { } return options; } + + async _updateVersion21(options) { + await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v21.handlebars'); + return options; + } } -- cgit v1.2.3 From 757707539690b6aec45e9de8cd37fdfc907d8843 Mon Sep 17 00:00:00 2001 From: praschke Date: Sun, 22 Oct 2023 17:23:04 +0100 Subject: warn about custom templates in the welcome page --- ext/css/settings.css | 7 +++++++ ext/js/background/backend.js | 20 ++++++-------------- ext/js/data/options-util.js | 27 +++++++++++++++++++++++++++ ext/js/pages/welcome-main.js | 7 +++++++ ext/welcome.html | 27 ++++++++++++++++++++++----- 5 files changed, 69 insertions(+), 19 deletions(-) (limited to 'ext/js/data') diff --git a/ext/css/settings.css b/ext/css/settings.css index eaebc3af..a2618d88 100644 --- a/ext/css/settings.css +++ b/ext/css/settings.css @@ -2167,6 +2167,13 @@ button.hotkey-list-item-enabled-button[data-scope-count='0'] { display: none; } +.warn-custom-templates-notification { + border: 1px solid var(--danger-color); +} +:root:not([data-warn-custom-templates=true]) .warn-custom-templates-notification { + display: none; +} + .test-anki-note-viewer-container { margin-top: 0.85em; display: flex; diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 565f4abf..755010a3 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -2099,20 +2099,12 @@ class Backend { } async _openWelcomeGuidePageOnce() { - if (isObject(chrome.storage) && isObject(chrome.storage.session)) { - // Chrome - chrome.storage.session.get(['openedWelcomePage']).then((result) => { - if (!result.openedWelcomePage) { - this._openWelcomeGuidePage(); - chrome.storage.session.set({'openedWelcomePage': true}); - } - }); - } else { - // Firefox (storage.session is not supported yet) - // NOTE: This means that the welcome page will repeatedly open in Firefox - // until they support storage.session. - this._openWelcomeGuidePage(); - } + chrome.storage.session.get(['openedWelcomePage']).then((result) => { + if (!result.openedWelcomePage) { + this._openWelcomeGuidePage(); + chrome.storage.session.set({'openedWelcomePage': true}); + } + }); } async _openWelcomeGuidePage() { diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 7b050416..1f2ffb05 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -1001,6 +1001,33 @@ class OptionsUtil { async _updateVersion21(options) { await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v21.handlebars'); + + let customTemplates = false; + for (const {options: profileOptions} of options.profiles) { + if (profileOptions.anki.fieldTemplates !== null) { + customTemplates = true; + } + } + + if (customTemplates && isObject(chrome.storage)) { + chrome.storage.session.set({'needsCustomTemplatesWarning': true}); + await this._createTab(chrome.runtime.getURL('/welcome.html')); + chrome.storage.session.set({'openedWelcomePage': true}); + } + return options; } + + _createTab(url) { + return new Promise((resolve, reject) => { + chrome.tabs.create({url}, (tab) => { + const e = chrome.runtime.lastError; + if (e) { + reject(new Error(e.message)); + } else { + resolve(tab); + } + }); + }); + } } diff --git a/ext/js/pages/welcome-main.js b/ext/js/pages/welcome-main.js index 521ce2c2..8039dae5 100644 --- a/ext/js/pages/welcome-main.js +++ b/ext/js/pages/welcome-main.js @@ -58,6 +58,13 @@ async function setupGenericSettingsController(genericSettingController) { setupEnvironmentInfo(); + chrome.storage.session.get({'needsCustomTemplatesWarning': false}).then((result) => { + if (result.needsCustomTemplatesWarning) { + document.documentElement.dataset.warnCustomTemplates = 'true'; + chrome.storage.session.remove(['needsCustomTemplatesWarning']); + } + }); + const preparePromises = []; const modalController = new ModalController(); diff --git a/ext/welcome.html b/ext/welcome.html index 14e98367..56167866 100644 --- a/ext/welcome.html +++ b/ext/welcome.html @@ -25,6 +25,19 @@

Welcome to Yomitan!

+ +
+
+
+

+ There are custom Anki templates in your settings. Note that some syntax has changed from previous versions of Yomitan. + Please ensure that your custom templates are using the updated syntax. +

+
+
+
+ +

Here are some basics to get started

@@ -49,10 +62,9 @@
Yomitan requires one or more dictionaries to be installed in order to look up terms, kanji, and other information. - Several downloadable dictionaries can be found on the Yomitan homepage, - allowing you to choose the dictionaries most relevant for you. + Several downloadable dictionaries can be found on the Yomitan homepage. Dictionaries can be configured using the button below, - or later from the the Settings page. + or later from the Settings page.
@@ -67,12 +79,17 @@
- You can also import an exported collection of dictionaries to migrate from a different device or browser from the Backup section of the Settings page. + You can also import an exported collection of dictionaries from the Backup section of the Settings page.

- If you are migrating from Yomichan, you may be particularly interested in migrating your data from Yomichan into Yomitan. + If you are migrating from Yomichan, you may be interested in importing your data into Yomitan. Please follow instructions from Yomitan's README for that. + +

+ + If you are using or planning to use custom templates for Anki note creation, note that some syntax has changed from Yomichan and Yomibaba. + Please ensure that your custom templates are using the updated syntax.
-- cgit v1.2.3