diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a7fc7c..3792147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 9bfad9b..f067f43 100644 --- a/README.md +++ b/README.md @@ -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) ... } @@ -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, @@ -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() } } @@ -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. diff --git a/package.json b/package.json index 4f0ea3e..03bcfa1 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/FileThemeProcessor/FileThemeProcessor.interface.ts b/src/FileThemeProcessor/FileThemeProcessor.interface.ts index 2fea16c..07b1d53 100644 --- a/src/FileThemeProcessor/FileThemeProcessor.interface.ts +++ b/src/FileThemeProcessor/FileThemeProcessor.interface.ts @@ -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 { diff --git a/src/FileThemeProcessor/FileThemeProcessor.ts b/src/FileThemeProcessor/FileThemeProcessor.ts index 5f73811..69d70d5 100644 --- a/src/FileThemeProcessor/FileThemeProcessor.ts +++ b/src/FileThemeProcessor/FileThemeProcessor.ts @@ -147,7 +147,7 @@ export class FileThemeProcessor implements ObserverableFileThemeProcessor { private notifyAll() { this._observers.forEach((observer) => { - observer.notify() + observer.notify(this._state) }) }