Skip to content

Commit 5e9e2e7

Browse files
authored
feat: sync theme of Explo view with VS Code (#11)
Closes #10
1 parent aa9eeb2 commit 5e9e2e7

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ modules.xml
337337
.LSOverride
338338

339339
# Icon must end with two \r
340-
Icon
340+
Icon
341+
341342

342343
# Thumbnails
343344
._*
@@ -536,3 +537,4 @@ $RECYCLE.BIN/
536537

537538
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
538539

540+
*.vsix

explo-code/src/explo_view_commands.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
ColorThemeKind,
23
commands,
34
Disposable,
45
ExtensionContext,
@@ -92,6 +93,9 @@ export class ExploViewCommands implements Disposable {
9293
panel.webview.html = exploWebviewContent({
9394
baseUri: baseUri.toString(),
9495
vmServiceUri: session.vmServiceUri!,
96+
themeMode: vscodeColorThemeKindToExploThemeMode(
97+
window.activeColorTheme.kind
98+
),
9599
})
96100

97101
this.openViewPanels.set(session, panel)
@@ -112,12 +116,29 @@ export class ExploViewCommands implements Disposable {
112116
}
113117
}
114118

119+
enum ExploThemeMode {
120+
light = 'light',
121+
dark = 'dark',
122+
}
123+
124+
function vscodeColorThemeKindToExploThemeMode(kind: ColorThemeKind) {
125+
switch (kind) {
126+
case ColorThemeKind.HighContrast:
127+
case ColorThemeKind.Dark:
128+
return ExploThemeMode.dark
129+
case ColorThemeKind.Light:
130+
return ExploThemeMode.light
131+
}
132+
}
133+
115134
function exploWebviewContent({
116135
baseUri,
117136
vmServiceUri,
137+
themeMode,
118138
}: {
119139
baseUri: string
120140
vmServiceUri: string
141+
themeMode: 'light' | 'dark'
121142
}): string {
122143
return `
123144
<!DOCTYPE html>
@@ -132,7 +153,8 @@ function exploWebviewContent({
132153
// Prepare browser environment for the view.
133154
window.explo = {
134155
config: {
135-
vmServiceUri: '${vmServiceUri}'
156+
vmServiceUri: '${vmServiceUri}',
157+
themeMode: '${themeMode}'
136158
}
137159
}
138160
+33-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1+
/// The config properties in this library have to be set in the browser
2+
/// environment, before the Flutter app is loaded.
3+
///
4+
/// ```js
5+
/// window.explo = {
6+
/// config: {
7+
/// vmServiceUri: ...,
8+
/// themeMode: ...,
9+
/// }
10+
/// }
11+
/// ```
112
@JS('explo.config')
213
library config;
314

15+
import 'package:flutter/material.dart';
416
import 'package:js/js.dart';
517

618
/// The VM Service URI of the target.
7-
///
8-
/// This has to be set in the browser environment, before the Flutter app is
9-
/// loaded.
10-
///
11-
/// ```js
12-
/// window.explo = { config: { vmServiceUri: ... } }
13-
/// ```
14-
@JS()
15-
external String get vmServiceUri;
19+
Uri get vmServiceUri => Uri.parse(_vmServiceUri);
20+
21+
@JS('vmServiceUri')
22+
external String get _vmServiceUri;
23+
24+
/// The theme mode to use for the view.
25+
ThemeMode get themeMode => parseThemeMode(_themeMode);
26+
27+
@JS('themeMode')
28+
external String get _themeMode;
29+
30+
ThemeMode parseThemeMode(String value) {
31+
switch (value) {
32+
case 'dark':
33+
return ThemeMode.dark;
34+
case 'light':
35+
return ThemeMode.light;
36+
default:
37+
throw ArgumentError.value(value, 'value', 'Unknown theme mode');
38+
}
39+
}

packages/explo_ide_view/lib/main.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class MyApp extends StatelessWidget {
1919
return MaterialApp(
2020
theme: ThemeData.from(colorScheme: const ColorScheme.light()),
2121
darkTheme: ThemeData.from(colorScheme: const ColorScheme.dark()),
22-
home: ExploView(vmServiceUri: Uri.parse(vmServiceUri)),
22+
home: ExploView(
23+
vmServiceUri: vmServiceUri,
24+
themeMode: themeMode,
25+
),
2326
);
2427
}
2528
}

0 commit comments

Comments
 (0)