refactor(dashboard): replace legacy isElectron bridge fields with isDesktop (#5269)

* refactor dashboard desktop bridge fields from isElectron to isDesktop

* refactor dashboard runtime detection into shared helper
This commit is contained in:
エイカク
2026-02-21 01:35:23 +09:00
committed by GitHub
parent a4d37e2c20
commit 5d0fc8ac7a
5 changed files with 52 additions and 22 deletions
+2 -3
View File
@@ -18,7 +18,6 @@ import { RouterView } from 'vue-router';
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { useToastStore } from '@/stores/toast'
import WaitingForRestart from '@/components/shared/WaitingForRestart.vue'
import { restartAstrBot } from '@/utils/restartAstrBot'
const toastStore = useToastStore()
const globalWaitingRef = ref(null)
@@ -33,12 +32,12 @@ const snackbarShow = computed({
onMounted(() => {
const desktopBridge = window.astrbotDesktop
if (!desktopBridge?.isElectron || !desktopBridge.onTrayRestartBackend) {
if (!desktopBridge?.onTrayRestartBackend) {
return
}
disposeTrayRestartListener = desktopBridge.onTrayRestartBackend(async () => {
try {
await restartAstrBot(globalWaitingRef.value)
await globalWaitingRef.value?.check?.()
} catch (error) {
globalWaitingRef.value?.stop?.()
console.error('Tray restart backend failed:', error)
@@ -18,6 +18,7 @@ import StyledMenu from '@/components/shared/StyledMenu.vue';
import { useLanguageSwitcher } from '@/i18n/composables';
import type { Locale } from '@/i18n/types';
import AboutPage from '@/views/AboutPage.vue';
import { getDesktopRuntimeInfo } from '@/utils/desktopRuntime';
enableKatex();
enableMermaid();
@@ -46,8 +47,8 @@ let version = ref('');
let releases = ref([]);
let updatingDashboardLoading = ref(false);
let installLoading = ref(false);
const isElectronApp = ref(
typeof window !== 'undefined' && !!window.astrbotDesktop?.isElectron
const isDesktopReleaseMode = ref(
typeof window !== 'undefined' && !!window.astrbotDesktop?.isDesktop
);
const redirectConfirmDialog = ref(false);
const pendingRedirectUrl = ref('');
@@ -133,7 +134,7 @@ function confirmExternalRedirect() {
}
}
const getReleaseUrlForElectron = () => {
const getReleaseUrlForDesktop = () => {
const firstRelease = (releases.value as any[])?.[0];
if (firstRelease?.tag_name) {
const tag = firstRelease.tag_name as string;
@@ -147,12 +148,12 @@ const getReleaseUrlForElectron = () => {
};
function handleUpdateClick() {
if (isElectronApp.value) {
if (isDesktopReleaseMode.value) {
requestExternalRedirect('');
resolvingReleaseTarget.value = true;
checkUpdate();
void getReleases().finally(() => {
pendingRedirectUrl.value = getReleaseUrlForElectron() || fallbackReleaseUrl;
pendingRedirectUrl.value = getReleaseUrlForDesktop() || fallbackReleaseUrl;
resolvingReleaseTarget.value = false;
});
return;
@@ -246,7 +247,7 @@ function checkUpdate() {
} else {
updateStatus.value = res.data.message;
}
dashboardHasNewVersion.value = isElectronApp.value
dashboardHasNewVersion.value = isDesktopReleaseMode.value
? false
: res.data.data.dashboard_has_new_version;
})
@@ -388,13 +389,9 @@ const changeLanguage = async (langCode: string) => {
};
onMounted(async () => {
try {
isElectronApp.value = !!window.astrbotDesktop?.isElectron ||
!!(await window.astrbotDesktop?.isElectronRuntime?.());
} catch {
isElectronApp.value = false;
}
if (isElectronApp.value) {
const runtimeInfo = await getDesktopRuntimeInfo();
isDesktopReleaseMode.value = runtimeInfo.isDesktopRuntime;
if (isDesktopReleaseMode.value) {
dashboardHasNewVersion.value = false;
}
});
@@ -441,7 +438,7 @@ onMounted(async () => {
<small v-if="hasNewVersion">
{{ t('core.header.version.hasNewVersion') }}
</small>
<small v-else-if="dashboardHasNewVersion && !isElectronApp">
<small v-else-if="dashboardHasNewVersion && !isDesktopReleaseMode">
{{ t('core.header.version.dashboardHasNewVersion') }}
</small>
</div>
@@ -524,7 +521,7 @@ onMounted(async () => {
<v-icon>mdi-arrow-up-circle</v-icon>
</template>
<v-list-item-title>{{ t('core.header.updateDialog.title') }}</v-list-item-title>
<template v-slot:append v-if="hasNewVersion || (dashboardHasNewVersion && !isElectronApp)">
<template v-slot:append v-if="hasNewVersion || (dashboardHasNewVersion && !isDesktopReleaseMode)">
<v-chip size="x-small" color="primary" variant="tonal" class="ml-2">!</v-chip>
</template>
</v-list-item>
+2 -2
View File
@@ -3,8 +3,8 @@ export {};
declare global {
interface Window {
astrbotDesktop?: {
isElectron: boolean;
isElectronRuntime: () => Promise<boolean>;
isDesktop: boolean;
isDesktopRuntime: () => Promise<boolean>;
getBackendState: () => Promise<{
running: boolean;
spawning: boolean;
+32
View File
@@ -0,0 +1,32 @@
export type DesktopRuntimeInfo = {
bridge: Window['astrbotDesktop'] | undefined
hasDesktopRuntimeProbe: boolean
hasDesktopRestartCapability: boolean
isDesktopRuntime: boolean
}
export async function getDesktopRuntimeInfo(): Promise<DesktopRuntimeInfo> {
const bridge = window.astrbotDesktop
const hasDesktopRuntimeProbe =
!!bridge && typeof bridge.isDesktopRuntime === 'function'
const hasDesktopRestartCapability =
!!bridge &&
typeof bridge.restartBackend === 'function' &&
hasDesktopRuntimeProbe
let isDesktopRuntime = !!bridge?.isDesktop
if (hasDesktopRuntimeProbe) {
try {
isDesktopRuntime = isDesktopRuntime || !!(await bridge.isDesktopRuntime())
} catch (error) {
console.warn('[desktop-runtime] Failed to detect desktop runtime.', error)
}
}
return {
bridge,
hasDesktopRuntimeProbe,
hasDesktopRestartCapability,
isDesktopRuntime,
}
}
+4 -2
View File
@@ -1,4 +1,5 @@
import axios from 'axios'
import { getDesktopRuntimeInfo } from '@/utils/desktopRuntime'
type WaitingForRestartRef = {
check: (initialStartTime?: number | null) => void | Promise<void>
@@ -27,9 +28,10 @@ async function fetchCurrentStartTime(): Promise<number | null> {
export async function restartAstrBot(
waitingRef?: WaitingForRestartRef | null
): Promise<void> {
const desktopBridge = window.astrbotDesktop
const { bridge: desktopBridge, hasDesktopRestartCapability, isDesktopRuntime } =
await getDesktopRuntimeInfo()
if (desktopBridge?.isElectron) {
if (desktopBridge && hasDesktopRestartCapability && isDesktopRuntime) {
const authToken = localStorage.getItem('token')
const initialStartTime = await fetchCurrentStartTime()
try {