Skip to content

Commit

Permalink
fix: ignore error when failed to instantiate worker (#64)
Browse files Browse the repository at this point in the history
* fix: ignore error when failed to instantiate worker

* fix: make enabled `false` when file protocol used
  • Loading branch information
bokuweb authored Aug 18, 2024
1 parent 4a4c282 commit 9198450
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const regData = (window as any)['__reg__'] as RegData;
const workerClient = new WorkerClient();
const ximgdiffConfig = regData.ximgdiffConfig || { enabled: false };

// INFO: set false on file: protocol
// ref: https://github.com/reg-viz/reg-cli/issues/506
if (window.location.protocol.startsWith('file')) {
ximgdiffConfig.enabled = false;
}

workerClient.start(ximgdiffConfig);

// Store
Expand Down
9 changes: 7 additions & 2 deletions src/worker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ export class WorkerClient {
}

this._ximgdiffEnabled = config.enabled;
this._worker = new Worker(config.workerUrl, {});
try {
this._worker = new Worker(config.workerUrl, {});
} catch (reason) {
// NOP: ignore error if failed to instantiate worker.
// ref: https://github.com/reg-viz/reg-cli/issues/506
}

this._worker.addEventListener('message', ({ data }: WorkerEvent) => {
this._worker?.addEventListener('message', ({ data }: WorkerEvent) => {
switch (data.type) {
case WorkerEventType.RESULT_CALC:
this._cache[data.payload.raw] = data.payload;
Expand Down

0 comments on commit 9198450

Please sign in to comment.