Skip to content

Commit 1904e3b

Browse files
Merge pull request #286 from ethereum/vscode/theme
update theme plugin
2 parents 4ddb20a + 60c7c50 commit 1904e3b

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

packages/api/src/lib/theme/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface Theme {
2-
/** @deprecated Use colors directly instead */
32
url?: string
43
/** @deprecated Use brightness instead */
54
quality?: 'dark' | 'light'
@@ -30,4 +29,9 @@ export interface Theme {
3029
fontFamily: string
3130
/** A unit to multiply for margin & padding */
3231
space: number
33-
}
32+
}
33+
34+
export interface ThemeUrls {
35+
light: string;
36+
dark: string;
37+
}

packages/engine/vscode/src/lib/theme.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Plugin } from '@remixproject/engine'
1+
import { Plugin, PluginOptions } from '@remixproject/engine'
22
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'
44
import { window, ColorThemeKind, Disposable, ColorTheme } from 'vscode'
55

6+
interface ThemeOptions extends PluginOptions {
7+
urls?: Partial<ThemeUrls>
8+
}
9+
610
// 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 {
812
const brightness = color.kind === ColorThemeKind.Dark ? 'dark' : 'light';
913
return {
1014
brightness,
@@ -33,25 +37,35 @@ function getTheme(color: ColorTheme): Theme {
3337
},
3438
fontFamily: 'Segoe WPC,Segoe UI,sans-serif',
3539
space: 5,
40+
url: urls[brightness]
3641
}
3742
}
3843

3944
export class ThemePlugin extends Plugin implements API<ITheme> {
45+
protected getTheme = getVscodeTheme;
46+
protected options: ThemeOptions
4047
listener: Disposable
41-
constructor() {
48+
constructor(options: Partial<ThemeOptions> = {}) {
4249
super(themeProfile)
50+
super.setOptions(options)
51+
}
52+
53+
setOptions(options: Partial<ThemeOptions>) {
54+
super.setOptions(options)
4355
}
4456

4557
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+
})
4761
}
4862

4963
onDeactivation() {
5064
this.listener.dispose()
5165
}
5266

5367
currentTheme(): Theme {
54-
return getTheme(window.activeColorTheme)
68+
return this.getTheme(window.activeColorTheme, this.options.urls)
5569
}
5670

5771
}

packages/engine/web/src/lib/theme.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ export function createTheme(params: DeepPartial<Theme> = {}): Theme {
4949
}
5050

5151
export class ThemePlugin extends Plugin implements MethodApi<ITheme> {
52-
protected theme: Theme = createTheme()
52+
protected getTheme = createTheme
53+
protected theme: Theme
5354
constructor() {
5455
super(themeProfile)
56+
this.theme = this.getTheme()
5557
}
5658

5759
/** Internal API to set the current theme */
5860
setTheme(theme: DeepPartial<Theme>) {
59-
this.theme = createTheme(theme)
61+
this.theme = this.getTheme(theme)
6062
this.emit('themeChanged', this.theme)
6163
}
6264

0 commit comments

Comments
 (0)