aboutsummaryrefslogtreecommitdiff
path: root/ext/js/application.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-18 08:01:22 -0500
committerGitHub <noreply@github.com>2024-02-18 13:01:22 +0000
commit90449bc745546f0f25bc93ee4b06d21b7c0210e8 (patch)
tree728153aaa4588a7340c3f3a45008989c0f5521b3 /ext/js/application.js
parentc2e3f60e51529f05284fea5f5bc1afcd1674f5ca (diff)
Log update (#701)
* Don't export Logger * Rename logger.js to log.js * Move helper function * Update extension name configuration * Simplify docs * Move issue URL to a field * Simplify context * Remove optional params that are never used * Configure backend * Update eslint * Simplify * Rename function * Simplify _api reference * Simplify docs * Remove unused log levels (except 'log') * Add log function * Rename for more clear intent * Use log.log
Diffstat (limited to 'ext/js/application.js')
-rw-r--r--ext/js/application.js24
1 files changed, 6 insertions, 18 deletions
diff --git a/ext/js/application.js b/ext/js/application.js
index 7a2f216c..350a4210 100644
--- a/ext/js/application.js
+++ b/ext/js/application.js
@@ -21,7 +21,7 @@ import {CrossFrameAPI} from './comm/cross-frame-api.js';
import {createApiMap, invokeApiMapHandler} from './core/api-map.js';
import {EventDispatcher} from './core/event-dispatcher.js';
import {ExtensionError} from './core/extension-error.js';
-import {log} from './core/logger.js';
+import {log} from './core/log.js';
import {deferPromise} from './core/utilities.js';
import {WebExtension} from './extension/web-extension.js';
@@ -63,19 +63,8 @@ export class Application extends EventDispatcher {
*/
constructor(api, crossFrameApi) {
super();
-
/** @type {WebExtension} */
this._webExtension = new WebExtension();
-
- /** @type {string} */
- this._extensionName = 'Yomitan';
- try {
- const manifest = chrome.runtime.getManifest();
- this._extensionName = `${manifest.name} v${manifest.version}`;
- } catch (e) {
- // NOP
- }
-
/** @type {?boolean} */
this._isBackground = null;
/** @type {API} */
@@ -84,7 +73,6 @@ export class Application extends EventDispatcher {
this._crossFrame = crossFrameApi;
/** @type {boolean} */
this._isReady = false;
-
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {import('application').ApiMap} */
this._apiMap = createApiMap([
@@ -139,7 +127,7 @@ export class Application extends EventDispatcher {
*/
prepare() {
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
- log.on('log', this._onForwardLog.bind(this));
+ log.on('logGenericError', this._onLogGenericError.bind(this));
}
/**
@@ -167,6 +155,7 @@ export class Application extends EventDispatcher {
*/
static async main(mainFunction) {
const webExtension = new WebExtension();
+ log.configure(webExtension.extensionName);
const api = new API(webExtension);
await this.waitForBackendReady(webExtension);
const {tabId, frameId} = await api.frameInformationGet();
@@ -243,12 +232,11 @@ export class Application extends EventDispatcher {
}
/**
- * @param {{error: unknown, level: import('log').LogLevel, context?: import('log').LogContext}} params
+ * @param {import('log').Events['logGenericError']} params
*/
- async _onForwardLog({error, level, context}) {
+ async _onLogGenericError({error, level, context}) {
try {
- const api = /** @type {API} */ (this._api);
- await api.log(ExtensionError.serialize(error), level, context);
+ await this._api.logGenericErrorBackend(ExtensionError.serialize(error), level, context);
} catch (e) {
// NOP
}