Skip to content

Commit e5b4b70

Browse files
committed
fix: theme reactivity
1 parent 21ca6cf commit e5b4b70

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/App.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import type { EventMessage, TaskAttributes } from '../shared/events';
33
import type { RunnerState } from './utils';
4+
import { useMutationObserver } from '@vueuse/core';
45
import mixpanel from 'mixpanel-browser';
56
import { nanoid } from 'nanoid';
67
import { computed, onMounted, provide, ref, useTemplateRef } from 'vue';
@@ -11,8 +12,6 @@ import Runner from './components/Runner.vue';
1112
import TooltipProvider from './components/ui/tooltip/TooltipProvider.vue';
1213
import { logger, postEvent, ThemeInjectKey } from './utils';
1314
14-
provide(ThemeInjectKey, ref('dark' as const));
15-
1615
const runner = useTemplateRef('runner');
1716
const loading = ref(true);
1817
const states = new Map<string, RunnerState>();
@@ -118,6 +117,19 @@ window.addEventListener('message', (ev) => {
118117
}
119118
});
120119
120+
const theme = ref<'dark' | 'light'>('dark');
121+
useMutationObserver(
122+
document.body,
123+
() => {
124+
const t = document.body.getAttribute('data-vscode-theme-kind');
125+
theme.value = t === 'vscode-light' || t === 'vscode-high-contrast-light'
126+
? 'light'
127+
: 'dark';
128+
},
129+
{ attributes: true },
130+
);
131+
provide(ThemeInjectKey, theme);
132+
121133
let ready = false;
122134
onMounted(() => {
123135
if (ready)

0 commit comments

Comments
 (0)