Skip to content

Commit

Permalink
Remove status bar entries on webview disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Sep 7, 2024
1 parent 0a85053 commit dd7b066
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.0.5 (2024-09-07)

- Remove status bar entries when webview is disposed

## v1.0.4 (2024-09-07)

- Add screenshot to README
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jpeg-xl",
"displayName": "JPEG XL",
"description": "JPEG XL support in VS Code",
"version": "1.0.4",
"version": "1.0.5",
"publisher": "printfn",
"icon": "images/icon.png",
"engines": {
Expand Down
52 changes: 26 additions & 26 deletions src/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ import init, { JxlImage } from 'jxl-oxide-wasm';
import module from 'jxl-oxide-wasm/module.wasm';

export type DecodedImage = {
png?: Uint8Array;
error?: string;
resolutionX: number;
resolutionY: number;
png?: Uint8Array;
error?: string;
resolutionX: number;
resolutionY: number;
};

export async function decode(data: Uint8Array): Promise<DecodedImage> {
if (data.length === 0) {
return {
error: 'File is empty',
resolutionX: 0,
resolutionY: 0,
};
}
await init(module);
const image = new JxlImage();
image.feedBytes(data);
if (!image.tryInit()) {
return {
error: 'Malformed data',
resolutionX: 0,
resolutionY: 0,
};
}
const renderResult = image.render(undefined);
const png = renderResult.encodeToPng();
const resolutionX = png[16] << 24 | png[17] << 16 | png[18] << 8 | png[19];
const resolutionY = png[20] << 24 | png[21] << 16 | png[22] << 8 | png[23];
return { png, resolutionX, resolutionY };
if (data.length === 0) {
return {
error: 'File is empty',
resolutionX: 0,
resolutionY: 0,
};
}
await init(module);
const image = new JxlImage();
image.feedBytes(data);
if (!image.tryInit()) {
return {
error: 'Malformed data',
resolutionX: 0,
resolutionY: 0,
};
}
const renderResult = image.render();
const png = renderResult.encodeToPng();
const resolutionX = png[16] << 24 | png[17] << 16 | png[18] << 8 | png[19];
const resolutionY = png[20] << 24 | png[21] << 16 | png[22] << 8 | png[23];
return { png, resolutionX, resolutionY };
}
21 changes: 11 additions & 10 deletions src/jpeg-xl-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ export class JXLEditorProvider implements vscode.CustomReadonlyEditorProvider<JX
// Wait for the webview to be properly ready before we init
webviewPanel.webview.onDidReceiveMessage(async e => {
if (e.type === 'ready') {
this.postMessage(webviewPanel, 'update', {
content: document.decodedImage,
});
this.postMessage(webviewPanel, 'update', {
content: document.decodedImage,
});
}
});

webviewPanel.onDidChangeViewState(e => this.updateStatusBarItems(e.webviewPanel.active, document));
webviewPanel.onDidDispose(() => this.updateStatusBarItems(false, document));
this.updateStatusBarItems(webviewPanel.active, document);
}

Expand Down Expand Up @@ -212,13 +213,13 @@ export class JXLEditorProvider implements vscode.CustomReadonlyEditorProvider<JX
callback?.(message.body);
return;
}
case 'log':
console.log(message.body);
break;
case 'ready':
break;
default:
console.error('unknown message', message);
case 'log':
console.log(message.body);
break;
case 'ready':
break;
default:
console.error('unknown message', message);
}
}
}
Expand Down

0 comments on commit dd7b066

Please sign in to comment.