From 73ad582fc33a6b806a041cd85fcd19107721bbb5 Mon Sep 17 00:00:00 2001 From: KaiserZh Date: Fri, 9 Sep 2022 22:17:46 +0800 Subject: [PATCH] Fix some bugs. --- src/backgrounds/decoder.ts | 19 ++++++++----------- src/decoder/cdecoder.ts | 1 + webpack.config.js | 9 +++------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/backgrounds/decoder.ts b/src/backgrounds/decoder.ts index c2d5ddb..76af5c1 100644 --- a/src/backgrounds/decoder.ts +++ b/src/backgrounds/decoder.ts @@ -17,19 +17,16 @@ if (process.env.ALL) { decoders.set(Decoders.ONLINE, OnlineDecoder); } -function getDecoderCode(name: string): [Decoders, string, string] { - let decoder = /wasm/.test(name) - ? Decoders.WASM - : /js/.test(name) - ? Decoders.JS - : Decoders.ONLINE; - let config = name.split("::"); +function getDecoderCode(code: string): [Decoders, string, string] { + let decoder = /wasm/.test(code) ? Decoders.WASM : Decoders.ONLINE; + let info = code.split("::"); let engineID, annotation; - if (config.length == 2) { - engineID = config[0]; - annotation = config[1]; + + if (info.length == 2) { + engineID = info[0]; + annotation = info[1]; } else { - engineID = config[0]; + engineID = info[0]; annotation = ""; } diff --git a/src/decoder/cdecoder.ts b/src/decoder/cdecoder.ts index 5daee76..94dbad1 100644 --- a/src/decoder/cdecoder.ts +++ b/src/decoder/cdecoder.ts @@ -19,6 +19,7 @@ export default class Decoder extends EventTarget implements IDecoder { this.#dataloader = new DataLoader(inputTool); this.#tokenDecoder = new TokenDecoder(this.#dataloader, solution); + this.#tokenDecoder.addEventListener('clear', this.clear.bind(this)); try { this.#decoder = new Module["Decoder"](); diff --git a/webpack.config.js b/webpack.config.js index 07fdadb..cd746c0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -43,20 +43,17 @@ let webpackConfig = manifests.map((manifest) => { // List of files to be copied. let copyPatterns = [ {from: `./src/manifests/manifest_${manifest}.json`, to: "./manifest.json", transform(content) { + let data = JSON.parse(content); if (mode == 'development') { - let data = JSON.parse(content); delete data['key']; - return JSON.stringify(data); } if (old && manifest == 'decoder') { - let data = JSON.parse(content); data["minimum_chrome_version"] = "45"; - data["content_security_policy"]["extension_page"] = "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"; + data["content_security_policy"]["extension_page"] = data["content_security_policy"]["extension_pages"]; delete data["content_security_policy"]["extension_pages"]; - return JSON.stringify(data); } - return content; + return JSON.stringify(data); }}, {from: "./src/asset", to: "."}, ]