Skip to content

Commit be856f5

Browse files
committed
refactor: align ui helpers with code quality guidance
1 parent 6171a02 commit be856f5

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

console/atest-ui/src/App.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const appVersion = ref('')
4141
const appVersionLink = ref('https://github.com/LinuxSuRen/api-testing')
4242
API.GetVersion((d) => {
4343
appVersion.value = d.version
44-
const version = d.version.match('^v\\d*.\\d*.\\d*')
45-
const dirtyVersion = d.version.match('^v\\d*.\\d*.\\d*-\\d*-g')
44+
const version = d.version.match(String.raw`^v\d*.\d*.\d*`)
45+
const dirtyVersion = d.version.match(String.raw`^v\d*.\d*.\d*-\d*-g`)
4646
4747
if (!version && !dirtyVersion) {
4848
return
@@ -55,16 +55,18 @@ API.GetVersion((d) => {
5555
}
5656
})
5757
58+
const hasLocalStorage = typeof globalThis !== 'undefined' && 'localStorage' in globalThis
59+
const storage = hasLocalStorage ? globalThis.localStorage : undefined
5860
const isCollapse = ref(true)
5961
watch(isCollapse, (v: boolean) => {
60-
window.localStorage.setItem('button.style', v ? 'simple' : '')
62+
storage?.setItem('button.style', v ? 'simple' : '')
6163
})
62-
const lastActiveMenu = window.localStorage.getItem('activeMenu')
64+
const lastActiveMenu = storage?.getItem('activeMenu') ?? 'welcome'
6365
const activeMenu = ref(lastActiveMenu === '' ? 'welcome' : lastActiveMenu)
6466
const panelName = ref(activeMenu)
6567
const handleSelect = (key: string) => {
6668
panelName.value = key
67-
window.localStorage.setItem('activeMenu', key)
69+
storage?.setItem('activeMenu', key)
6870
}
6971
7072
const locale = ref(Cache.GetPreference().language)

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const loadPlugin = async (): Promise<void> => {
2525
2626
// Implement retry mechanism with exponential backoff
2727
const checkPluginLoad = (retries = 0, maxRetries = 10) => {
28-
const plugin = (window as any).ATestPlugin;
28+
const globalScope = globalThis as { ATestPlugin?: { mount?: (el: Element) => void } };
29+
const plugin = globalScope.ATestPlugin;
2930
3031
if (plugin && plugin.mount) {
3132
const container = document.getElementById("plugin-container");
@@ -50,13 +51,14 @@ const loadPlugin = async (): Promise<void> => {
5051
});
5152
} catch (error) {
5253
loading.value = false; // Set loading to false on error
54+
console.error('Failed to load extension assets', error);
5355
}
5456
};
55-
try {
56-
loadPlugin();
57-
} catch (error) {
58-
// Handle error silently, loading state will indicate failure
59-
}
57+
58+
loadPlugin().catch((error) => {
59+
loading.value = false;
60+
console.error('Failed to initialize extension plugin', error);
61+
});
6062
</script>
6163

6264
<template>

0 commit comments

Comments
 (0)