Skip to content

Commit

Permalink
feat: v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sketchbuch committed Dec 8, 2023
1 parent d6ff477 commit 6af85ba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [1.0.4](https://github.com/sketchbuch/vscode-file-theme-processor/compare/v1.0.3...v1.0.4) (2023-12-08)

- Updated readme.
- Notify now provides the current state

## [1.0.3](https://github.com/sketchbuch/vscode-file-theme-processor/compare/v1.0.2...v1.0.3) (2023-10-12)

- Updated readme. The readme showed an example using "vscode.Uri.parse()" when updating localResourceRoots. This was corrected to "vscode.Uri.file()" as parse did not let extension resources load on windows.
Expand Down
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Then pass the `FileThemeProcessor` instance to your webview's constructor.
```typescript
export const activate = (vscodeExtContext: vscode.ExtensionContext): void => {
const fileThemeProcessor = new FileThemeProcessor(vscodeExtContext)
const yourwebviewViewProvider = new YourwebviewViewProvider(vscodeExtContext, fileThemeProcessor)
const yourWebviewViewProvider = new YourWebviewViewProvider(vscodeExtContext, fileThemeProcessor)

...
}
Expand All @@ -36,8 +36,9 @@ Your webview should also implement the interface `FileThemeProcessorObserver`. T
When this happens, you should re-render your webview.

```typescript
export class YourwebviewViewProvider implements vscode.webviewViewProvider, FileThemeProcessorObserver {
export class YourWebviewViewProvider implements vscode.webviewViewProvider, FileThemeProcessorObserver {
private _cssGenerator: CssGenerator
private _view?: vscode.WebviewView

constructor(
private readonly _ctx: vscode.ExtensionContext,
Expand All @@ -47,11 +48,21 @@ export class YourwebviewViewProvider implements vscode.webviewViewProvider, File
this._fileThemeProcessor.subscribe(this)
}

private render() {
...
}

public resolveWebviewView(webviewView: vscode.WebviewView) {
this._view = webviewView

...
}

...

public notify() {
// Example: Only reender if this webview has been resolved
if (viewExists) {
public notify(state: FileThemeProcessorState) {
// Example: Only reender if this webview has been resolved and theme data has been collected
if (this._view && state === 'ready') {
this.render()
}
}
Expand Down Expand Up @@ -136,7 +147,7 @@ I can't see the need to distinguish between icons for language and extensions fo

3. **Why does the CSS Generator not cache the generated css in global storage?**

In order to generate the CSS, you need access to the webview's `asWebviewUri()` method for creating correct URLs. Looking at the source, it seems like the URLs generated could be different from web view to webview and from environment to environment.
In order to generate the CSS, you need access to the webview's `asWebviewUri()` method for creating correct URLs. Looking at the source, it seems like the URLs generated could be different from webview to webview and from environment to environment.

Since I could guarantee that the URLs would always be correct for each webview, I decided not to cache the data globally but just in memory with in each css generator. You are free to cache the CSS in global storage via your webview. If you do this you should clear the cache when you get a loading notification as the processor will have dumped the cached data for the theme and is in the process of loading theme data.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vscode-file-theme-processor",
"version": "1.0.3",
"version": "1.0.4",
"description": "Provides VSCode Webviews with access to file icon theme data and generates required css to render file icon themes in Webviews.",
"author": "Sketchbuch",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion src/FileThemeProcessor/FileThemeProcessor.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface FileThemeProcessorObserver {
/**
* The file theme processor will call this method on all observers, to inform them that the processor state has changed.
*/
notify(): void
notify(state: FileThemeProcessorState): void
}

export interface ObserverableFileThemeProcessor {
Expand Down
2 changes: 1 addition & 1 deletion src/FileThemeProcessor/FileThemeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class FileThemeProcessor implements ObserverableFileThemeProcessor {

private notifyAll() {
this._observers.forEach((observer) => {
observer.notify()
observer.notify(this._state)
})
}

Expand Down

0 comments on commit 6af85ba

Please sign in to comment.