From 2abf46b6fa9d6c03be0d98045e111f2d8e1e41d5 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 1 Mar 2020 23:06:37 +0200 Subject: simplify backend prepare --- ext/bg/js/settings/backup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/js/settings/backup.js b/ext/bg/js/settings/backup.js index e945d186..acd21920 100644 --- a/ext/bg/js/settings/backup.js +++ b/ext/bg/js/settings/backup.js @@ -120,7 +120,7 @@ async function _onSettingsExportClick() { // Importing async function _settingsImportSetOptionsFull(optionsFull) { - return utilIsolate(await utilBackend().setFullOptions( + return utilIsolate(utilBackend().setFullOptions( utilBackgroundIsolate(optionsFull) )); } -- cgit v1.2.3 From e0edb30efd51ac18167880d77c2dea11c73a1bfc Mon Sep 17 00:00:00 2001 From: siikamiika Date: Mon, 2 Mar 2020 11:18:09 +0200 Subject: fix Backend prepare issues in settings --- ext/bg/js/backend.js | 4 ++++ ext/bg/js/settings/backup.js | 4 ++-- ext/bg/js/settings/main.js | 5 ++++- ext/bg/js/util.js | 6 +++++- 4 files changed, 15 insertions(+), 4 deletions(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index cdcfb7ad..be43ecf6 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -39,6 +39,8 @@ class Backend { url: window.location.href }; + this.isPrepared = false; + this.clipboardPasteTarget = document.querySelector('#clipboard-paste-target'); this.popupWindow = null; @@ -108,6 +110,8 @@ class Backend { } chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); + this.isPrepared = true; + const options = this.getOptions(this.optionsContext); if (options.general.showGuide) { chrome.tabs.create({url: chrome.runtime.getURL('/bg/guide.html')}); diff --git a/ext/bg/js/settings/backup.js b/ext/bg/js/settings/backup.js index acd21920..daa08c61 100644 --- a/ext/bg/js/settings/backup.js +++ b/ext/bg/js/settings/backup.js @@ -362,10 +362,10 @@ async function _onSettingsResetConfirmClick() { // Setup -window.addEventListener('DOMContentLoaded', () => { +function backupInitialize() { document.querySelector('#settings-export').addEventListener('click', _onSettingsExportClick, false); document.querySelector('#settings-import').addEventListener('click', _onSettingsImportClick, false); document.querySelector('#settings-import-file').addEventListener('change', _onSettingsImportFileChange, false); document.querySelector('#settings-reset').addEventListener('click', _onSettingsResetClick, false); document.querySelector('#settings-reset-modal-confirm').addEventListener('click', _onSettingsResetConfirmClick, false); -}, false); +} diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js index 127a6d2b..1bf1444c 100644 --- a/ext/bg/js/settings/main.js +++ b/ext/bg/js/settings/main.js @@ -21,7 +21,7 @@ utilBackend, utilIsolate, utilBackgroundIsolate ankiErrorShown, ankiFieldsToDict ankiTemplatesUpdateValue, onAnkiOptionsChanged, onDictionaryOptionsChanged appearanceInitialize, audioSettingsInitialize, profileOptionsSetup, dictSettingsInitialize -ankiInitialize, ankiTemplatesInitialize, storageInfoInitialize +ankiInitialize, ankiTemplatesInitialize, storageInfoInitialize, backupInitialize */ function getOptionsMutable(optionsContext) { @@ -262,6 +262,8 @@ function showExtensionInformation() { async function onReady() { + await yomichan.prepare(); + showExtensionInformation(); formSetupEventListeners(); @@ -271,6 +273,7 @@ async function onReady() { await dictSettingsInitialize(); ankiInitialize(); ankiTemplatesInitialize(); + backupInitialize(); storageInfoInitialize(); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 5ce4b08c..79c6af06 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -73,7 +73,11 @@ function utilStringHashCode(string) { } function utilBackend() { - return chrome.extension.getBackgroundPage().yomichanBackend; + const backend = chrome.extension.getBackgroundPage().yomichanBackend; + if (!backend.isPrepared) { + throw new Error('Backend not ready yet'); + } + return backend; } async function utilAnkiGetModelNames() { -- cgit v1.2.3