Skip to content

Commit 3826187

Browse files
committed
refactor: call plugin mount with single argument and sync locale
1 parent 8e45762 commit 3826187

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

console/atest-ui/src/views/Extension.vue

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
<script setup lang="ts">
2-
import { ref, type Ref } from 'vue'
2+
import { ref, watch } from 'vue'
33
import { useI18n } from 'vue-i18n'
4-
import { API } from './net';
5-
import { Cache } from './cache';
4+
import { API } from './net'
65
76
interface Props {
87
name: string
98
}
109
const props = defineProps<Props>()
11-
const { t, locale } = useI18n()
10+
const { locale } = useI18n()
1211
13-
interface PluginAppContext {
14-
i18n: {
15-
t: (key: string) => string
16-
locale: Ref<string>
17-
}
18-
API: typeof API
19-
Cache: typeof Cache
20-
}
21-
22-
const pluginContext: PluginAppContext = {
23-
i18n: { t, locale },
24-
API,
25-
Cache
26-
}
12+
let pluginInstance: { setLocale?: (value: string) => void } | undefined
2713
2814
const loading = ref(true)
2915
const loadPlugin = async (): Promise<void> => {
@@ -44,14 +30,16 @@ const loadPlugin = async (): Promise<void> => {
4430
4531
// Implement retry mechanism with exponential backoff
4632
const checkPluginLoad = (retries = 0, maxRetries = 10) => {
47-
const globalScope = globalThis as { ATestPlugin?: { mount?: (el: Element, context: PluginAppContext) => void } };
33+
const globalScope = globalThis as { ATestPlugin?: { mount?: (el: Element) => void, setLocale?: (value: string) => void } };
4834
const plugin = globalScope.ATestPlugin;
4935
5036
if (plugin && plugin.mount) {
5137
const container = document.getElementById("plugin-container");
5238
if (container) {
5339
container.innerHTML = ''; // Clear previous content
54-
plugin.mount(container, pluginContext);
40+
plugin.mount(container);
41+
plugin.setLocale?.(locale.value);
42+
pluginInstance = plugin;
5543
loading.value = false;
5644
} else {
5745
loading.value = false;
@@ -78,6 +66,11 @@ loadPlugin().catch((error) => {
7866
loading.value = false;
7967
console.error('Failed to initialize extension plugin', error);
8068
});
69+
70+
watch(locale, (value) => {
71+
const normalized = value ?? 'en';
72+
pluginInstance?.setLocale?.(normalized);
73+
});
8174
</script>
8275

8376
<template>

0 commit comments

Comments
 (0)