Show error status for prepare() errors
This commit is contained in:
parent
5c5c70326d
commit
dee7d924a8
@ -77,6 +77,7 @@ class Backend {
|
|||||||
|
|
||||||
this._defaultBrowserActionTitle = null;
|
this._defaultBrowserActionTitle = null;
|
||||||
this._isPrepared = false;
|
this._isPrepared = false;
|
||||||
|
this._prepareError = false;
|
||||||
this._badgePrepareDelayTimer = null;
|
this._badgePrepareDelayTimer = null;
|
||||||
|
|
||||||
this._messageHandlers = new Map([
|
this._messageHandlers = new Map([
|
||||||
@ -123,24 +124,21 @@ class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async prepare() {
|
async prepare() {
|
||||||
|
try {
|
||||||
this._defaultBrowserActionTitle = await this._getBrowserIconTitle();
|
this._defaultBrowserActionTitle = await this._getBrowserIconTitle();
|
||||||
this._badgePrepareDelayTimer = setTimeout(() => {
|
this._badgePrepareDelayTimer = setTimeout(() => {
|
||||||
this._badgePrepareDelayTimer = null;
|
this._badgePrepareDelayTimer = null;
|
||||||
this._updateBadge();
|
this._updateBadge();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
this._updateBadge();
|
this._updateBadge();
|
||||||
|
|
||||||
await this.database.prepare();
|
await this.database.prepare();
|
||||||
await this.translator.prepare();
|
await this.translator.prepare();
|
||||||
|
|
||||||
this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET');
|
this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET');
|
||||||
this.defaultAnkiFieldTemplates = await requestText(chrome.runtime.getURL('/bg/data/default-anki-field-templates.handlebars'), 'GET');
|
this.defaultAnkiFieldTemplates = await requestText(chrome.runtime.getURL('/bg/data/default-anki-field-templates.handlebars'), 'GET');
|
||||||
this.options = await optionsLoad();
|
this.options = await optionsLoad();
|
||||||
try {
|
|
||||||
this.options = JsonSchema.getValidValueOrDefault(this.optionsSchema, this.options);
|
this.options = JsonSchema.getValidValueOrDefault(this.optionsSchema, this.options);
|
||||||
} catch (e) {
|
|
||||||
// This shouldn't happen, but catch errors just in case of bugs
|
|
||||||
logError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.onOptionsUpdated('background');
|
this.onOptionsUpdated('background');
|
||||||
|
|
||||||
@ -163,14 +161,20 @@ class Backend {
|
|||||||
const callback = () => this.checkLastError(chrome.runtime.lastError);
|
const callback = () => this.checkLastError(chrome.runtime.lastError);
|
||||||
chrome.runtime.sendMessage({action: 'backendPrepared'}, callback);
|
chrome.runtime.sendMessage({action: 'backendPrepared'}, callback);
|
||||||
|
|
||||||
|
this._isPrepared = true;
|
||||||
|
} catch (e) {
|
||||||
|
this._prepareError = true;
|
||||||
|
logError(e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
if (this._badgePrepareDelayTimer !== null) {
|
if (this._badgePrepareDelayTimer !== null) {
|
||||||
clearTimeout(this._badgePrepareDelayTimer);
|
clearTimeout(this._badgePrepareDelayTimer);
|
||||||
this._badgePrepareDelayTimer = null;
|
this._badgePrepareDelayTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._isPrepared = true;
|
|
||||||
this._updateBadge();
|
this._updateBadge();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isPrepared() {
|
isPrepared() {
|
||||||
return this._isPrepared;
|
return this._isPrepared;
|
||||||
@ -888,7 +892,11 @@ class Backend {
|
|||||||
let status = null;
|
let status = null;
|
||||||
|
|
||||||
if (!this._isPrepared) {
|
if (!this._isPrepared) {
|
||||||
if (this._badgePrepareDelayTimer === null) {
|
if (this._prepareError !== null) {
|
||||||
|
text = '!!';
|
||||||
|
color = '#f04e4e';
|
||||||
|
status = 'Error';
|
||||||
|
} else if (this._badgePrepareDelayTimer === null) {
|
||||||
text = '...';
|
text = '...';
|
||||||
color = '#f0ad4e';
|
color = '#f0ad4e';
|
||||||
status = 'Loading';
|
status = 'Loading';
|
||||||
|
Loading…
Reference in New Issue
Block a user