|
1 | | -import { Plugin } from '@remixproject/engine' |
| 1 | +import { Plugin, PluginOptions } from '@remixproject/engine' |
2 | 2 | import { API } from '@remixproject/plugin-utils' |
3 | | -import { ITheme, Theme, themeProfile } from '@remixproject/plugin-api' |
| 3 | +import { ITheme, Theme, ThemeUrls, themeProfile } from '@remixproject/plugin-api' |
4 | 4 | import { window, ColorThemeKind, Disposable, ColorTheme } from 'vscode' |
5 | 5 |
|
| 6 | +interface ThemeOptions extends PluginOptions { |
| 7 | + urls?: Partial<ThemeUrls> |
| 8 | +} |
| 9 | + |
6 | 10 | // There is no way to get the value from the theme so the best solution is to reference the css varibles in webview |
7 | | -function getTheme(color: ColorTheme): Theme { |
| 11 | +export function getVscodeTheme(color: ColorTheme, urls: Partial<ThemeUrls> = {}): Theme { |
8 | 12 | const brightness = color.kind === ColorThemeKind.Dark ? 'dark' : 'light'; |
9 | 13 | return { |
10 | 14 | brightness, |
@@ -33,25 +37,35 @@ function getTheme(color: ColorTheme): Theme { |
33 | 37 | }, |
34 | 38 | fontFamily: 'Segoe WPC,Segoe UI,sans-serif', |
35 | 39 | space: 5, |
| 40 | + url: urls[brightness] |
36 | 41 | } |
37 | 42 | } |
38 | 43 |
|
39 | 44 | export class ThemePlugin extends Plugin implements API<ITheme> { |
| 45 | + protected getTheme = getVscodeTheme; |
| 46 | + protected options: ThemeOptions |
40 | 47 | listener: Disposable |
41 | | - constructor() { |
| 48 | + constructor(options: Partial<ThemeOptions> = {}) { |
42 | 49 | super(themeProfile) |
| 50 | + super.setOptions(options) |
| 51 | + } |
| 52 | + |
| 53 | + setOptions(options: Partial<ThemeOptions>) { |
| 54 | + super.setOptions(options) |
43 | 55 | } |
44 | 56 |
|
45 | 57 | onActivation() { |
46 | | - this.listener = window.onDidChangeActiveColorTheme(color => this.emit('themeChanged', getTheme(color))) |
| 58 | + this.listener = window.onDidChangeActiveColorTheme(color => { |
| 59 | + this.emit('themeChanged', this.getTheme(color, this.options.urls)) |
| 60 | + }) |
47 | 61 | } |
48 | 62 |
|
49 | 63 | onDeactivation() { |
50 | 64 | this.listener.dispose() |
51 | 65 | } |
52 | 66 |
|
53 | 67 | currentTheme(): Theme { |
54 | | - return getTheme(window.activeColorTheme) |
| 68 | + return this.getTheme(window.activeColorTheme, this.options.urls) |
55 | 69 | } |
56 | 70 |
|
57 | 71 | } |
|
0 commit comments