Script ready state change (#672)
* Update how backend/frontend ready states are awaited and signaled * Log errors on the search page * Update action name
This commit is contained in:
parent
e696dc84a8
commit
d7f78c23b5
@ -85,7 +85,7 @@ class Backend {
|
|||||||
this._logErrorLevel = null;
|
this._logErrorLevel = null;
|
||||||
|
|
||||||
this._messageHandlers = new Map([
|
this._messageHandlers = new Map([
|
||||||
['yomichanCoreReady', {async: false, contentScript: true, handler: this._onApiYomichanCoreReady.bind(this)}],
|
['requestBackendReadySignal', {async: false, contentScript: true, handler: this._onApiRequestBackendReadySignal.bind(this)}],
|
||||||
['optionsSchemaGet', {async: false, contentScript: true, handler: this._onApiOptionsSchemaGet.bind(this)}],
|
['optionsSchemaGet', {async: false, contentScript: true, handler: this._onApiOptionsSchemaGet.bind(this)}],
|
||||||
['optionsGet', {async: false, contentScript: true, handler: this._onApiOptionsGet.bind(this)}],
|
['optionsGet', {async: false, contentScript: true, handler: this._onApiOptionsGet.bind(this)}],
|
||||||
['optionsGetFull', {async: false, contentScript: true, handler: this._onApiOptionsGetFull.bind(this)}],
|
['optionsGetFull', {async: false, contentScript: true, handler: this._onApiOptionsGetFull.bind(this)}],
|
||||||
@ -212,9 +212,9 @@ class Backend {
|
|||||||
|
|
||||||
this._clipboardMonitor.on('change', this._onClipboardTextChange.bind(this));
|
this._clipboardMonitor.on('change', this._onClipboardTextChange.bind(this));
|
||||||
|
|
||||||
this._sendMessageAllTabs('backendPrepared');
|
this._sendMessageAllTabs('backendReady');
|
||||||
const callback = () => this._checkLastError(chrome.runtime.lastError);
|
const callback = () => this._checkLastError(chrome.runtime.lastError);
|
||||||
chrome.runtime.sendMessage({action: 'backendPrepared'}, callback);
|
chrome.runtime.sendMessage({action: 'backendReady'}, callback);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yomichan.logError(e);
|
yomichan.logError(e);
|
||||||
throw e;
|
throw e;
|
||||||
@ -361,10 +361,10 @@ class Backend {
|
|||||||
|
|
||||||
// Message handlers
|
// Message handlers
|
||||||
|
|
||||||
_onApiYomichanCoreReady(_params, sender) {
|
_onApiRequestBackendReadySignal(_params, sender) {
|
||||||
// tab ID isn't set in background (e.g. browser_action)
|
// tab ID isn't set in background (e.g. browser_action)
|
||||||
const callback = () => this._checkLastError(chrome.runtime.lastError);
|
const callback = () => this._checkLastError(chrome.runtime.lastError);
|
||||||
const data = {action: 'backendPrepared'};
|
const data = {action: 'backendReady'};
|
||||||
if (typeof sender.tab === 'undefined') {
|
if (typeof sender.tab === 'undefined') {
|
||||||
chrome.runtime.sendMessage(data, callback);
|
chrome.runtime.sendMessage(data, callback);
|
||||||
return false;
|
return false;
|
||||||
@ -1393,7 +1393,7 @@ class Backend {
|
|||||||
sender.tab.id !== tabId ||
|
sender.tab.id !== tabId ||
|
||||||
sender.frameId !== frameId ||
|
sender.frameId !== frameId ||
|
||||||
!isObject(message) ||
|
!isObject(message) ||
|
||||||
message.action !== 'yomichanCoreReady'
|
message.action !== 'yomichanReady'
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ async function setupOptions() {
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
api.forwardLogsToBackend();
|
api.forwardLogsToBackend();
|
||||||
await yomichan.ready();
|
await yomichan.backendReady();
|
||||||
|
|
||||||
const manifest = chrome.runtime.getManifest();
|
const manifest = chrome.runtime.getManifest();
|
||||||
|
|
||||||
@ -87,4 +87,6 @@ async function setupOptions() {
|
|||||||
setupButtonEvents('.action-open-search', 'search', chrome.runtime.getURL('/bg/search.html'));
|
setupButtonEvents('.action-open-search', 'search', chrome.runtime.getURL('/bg/search.html'));
|
||||||
setupButtonEvents('.action-open-options', 'options', chrome.runtime.getURL(manifest.options_ui.page));
|
setupButtonEvents('.action-open-options', 'options', chrome.runtime.getURL(manifest.options_ui.page));
|
||||||
setupButtonEvents('.action-open-help', 'help', 'https://foosoft.net/projects/yomichan/');
|
setupButtonEvents('.action-open-help', 'help', 'https://foosoft.net/projects/yomichan/');
|
||||||
|
|
||||||
|
yomichan.ready();
|
||||||
})();
|
})();
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
api.forwardLogsToBackend();
|
api.forwardLogsToBackend();
|
||||||
await yomichan.ready();
|
await yomichan.backendReady();
|
||||||
|
|
||||||
const displaySearch = new DisplaySearch();
|
const displaySearch = new DisplaySearch();
|
||||||
await displaySearch.prepare();
|
await displaySearch.prepare();
|
||||||
|
|
||||||
|
yomichan.ready();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yomichan.logError(e);
|
yomichan.logError(e);
|
||||||
}
|
}
|
||||||
|
@ -63,45 +63,51 @@ async function setupEnvironmentInfo() {
|
|||||||
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
api.forwardLogsToBackend();
|
try {
|
||||||
await yomichan.ready();
|
api.forwardLogsToBackend();
|
||||||
|
await yomichan.backendReady();
|
||||||
|
|
||||||
setupEnvironmentInfo();
|
setupEnvironmentInfo();
|
||||||
showExtensionInformation();
|
showExtensionInformation();
|
||||||
settingsPopulateModifierKeys();
|
settingsPopulateModifierKeys();
|
||||||
|
|
||||||
const optionsFull = await api.optionsGetFull();
|
const optionsFull = await api.optionsGetFull();
|
||||||
|
|
||||||
const settingsController = new SettingsController(optionsFull.profileCurrent);
|
const settingsController = new SettingsController(optionsFull.profileCurrent);
|
||||||
settingsController.prepare();
|
settingsController.prepare();
|
||||||
|
|
||||||
const storageController = new StorageController();
|
const storageController = new StorageController();
|
||||||
storageController.prepare();
|
storageController.prepare();
|
||||||
|
|
||||||
const genericSettingController = new GenericSettingController(settingsController);
|
const genericSettingController = new GenericSettingController(settingsController);
|
||||||
genericSettingController.prepare();
|
genericSettingController.prepare();
|
||||||
|
|
||||||
const clipboardPopupsController = new ClipboardPopupsController(settingsController);
|
const clipboardPopupsController = new ClipboardPopupsController(settingsController);
|
||||||
clipboardPopupsController.prepare();
|
clipboardPopupsController.prepare();
|
||||||
|
|
||||||
const popupPreviewController = new PopupPreviewController(settingsController);
|
const popupPreviewController = new PopupPreviewController(settingsController);
|
||||||
popupPreviewController.prepare();
|
popupPreviewController.prepare();
|
||||||
|
|
||||||
const audioController = new AudioController(settingsController);
|
const audioController = new AudioController(settingsController);
|
||||||
audioController.prepare();
|
audioController.prepare();
|
||||||
|
|
||||||
const profileController = new ProfileController(settingsController);
|
const profileController = new ProfileController(settingsController);
|
||||||
profileController.prepare();
|
profileController.prepare();
|
||||||
|
|
||||||
const dictionaryController = new DictionaryController(settingsController, storageController);
|
const dictionaryController = new DictionaryController(settingsController, storageController);
|
||||||
dictionaryController.prepare();
|
dictionaryController.prepare();
|
||||||
|
|
||||||
const ankiController = new AnkiController(settingsController);
|
const ankiController = new AnkiController(settingsController);
|
||||||
ankiController.prepare();
|
ankiController.prepare();
|
||||||
|
|
||||||
const ankiTemplatesController = new AnkiTemplatesController(settingsController, ankiController);
|
const ankiTemplatesController = new AnkiTemplatesController(settingsController, ankiController);
|
||||||
ankiTemplatesController.prepare();
|
ankiTemplatesController.prepare();
|
||||||
|
|
||||||
const settingsBackup = new SettingsBackup(settingsController);
|
const settingsBackup = new SettingsBackup(settingsController);
|
||||||
settingsBackup.prepare();
|
settingsBackup.prepare();
|
||||||
|
|
||||||
|
yomichan.ready();
|
||||||
|
} catch (e) {
|
||||||
|
yomichan.logError(e);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
api.forwardLogsToBackend();
|
api.forwardLogsToBackend();
|
||||||
await yomichan.ready();
|
await yomichan.backendReady();
|
||||||
|
|
||||||
const {frameId} = await api.frameInformationGet();
|
const {frameId} = await api.frameInformationGet();
|
||||||
if (typeof frameId !== 'number') {
|
if (typeof frameId !== 'number') {
|
||||||
@ -40,6 +40,8 @@
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
await frontend.prepare();
|
await frontend.prepare();
|
||||||
|
|
||||||
|
yomichan.ready();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yomichan.logError(e);
|
yomichan.logError(e);
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
api.forwardLogsToBackend();
|
api.forwardLogsToBackend();
|
||||||
await yomichan.ready();
|
await yomichan.backendReady();
|
||||||
|
|
||||||
const display = new DisplayFloat();
|
const display = new DisplayFloat();
|
||||||
await display.prepare();
|
await display.prepare();
|
||||||
|
|
||||||
|
yomichan.ready();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yomichan.logError(e);
|
yomichan.logError(e);
|
||||||
}
|
}
|
||||||
|
@ -51,15 +51,15 @@ const yomichan = (() => {
|
|||||||
this._isReady = false;
|
this._isReady = false;
|
||||||
|
|
||||||
const {promise, resolve} = deferPromise();
|
const {promise, resolve} = deferPromise();
|
||||||
this._isBackendPreparedPromise = promise;
|
this._isBackendReadyPromise = promise;
|
||||||
this._isBackendPreparedPromiseResolve = resolve;
|
this._isBackendReadyPromiseResolve = resolve;
|
||||||
|
|
||||||
this._messageHandlers = new Map([
|
this._messageHandlers = new Map([
|
||||||
['isReady', {async: false, handler: this._onMessageIsReady.bind(this)}],
|
['isReady', {async: false, handler: this._onMessageIsReady.bind(this)}],
|
||||||
['backendPrepared', {async: false, handler: this._onMessageBackendPrepared.bind(this)}],
|
['backendReady', {async: false, handler: this._onMessageBackendReady.bind(this)}],
|
||||||
['getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}],
|
['getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}],
|
||||||
['optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}],
|
['optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}],
|
||||||
['zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}]
|
['zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,10 +73,14 @@ const yomichan = (() => {
|
|||||||
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backendReady() {
|
||||||
|
this.sendMessage({action: 'requestBackendReadySignal'});
|
||||||
|
return this._isBackendReadyPromise;
|
||||||
|
}
|
||||||
|
|
||||||
ready() {
|
ready() {
|
||||||
this._isReady = true;
|
this._isReady = true;
|
||||||
this.sendMessage({action: 'yomichanCoreReady'});
|
this.sendMessage({action: 'yomichanReady'});
|
||||||
return this._isBackendPreparedPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
generateId(length) {
|
generateId(length) {
|
||||||
@ -275,10 +279,10 @@ const yomichan = (() => {
|
|||||||
return this._isReady;
|
return this._isReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMessageBackendPrepared() {
|
_onMessageBackendReady() {
|
||||||
if (this._isBackendPreparedPromiseResolve === null) { return; }
|
if (this._isBackendReadyPromiseResolve === null) { return; }
|
||||||
this._isBackendPreparedPromiseResolve();
|
this._isBackendReadyPromiseResolve();
|
||||||
this._isBackendPreparedPromiseResolve = null;
|
this._isBackendReadyPromiseResolve = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMessageGetUrl() {
|
_onMessageGetUrl() {
|
||||||
|
Loading…
Reference in New Issue
Block a user