fix(plugin): defer restored tabs until manual refresh
This commit is contained in:
13 files changed
+148
-16
No files matched your search
@@ -161,6 +161,8 @@ watch(
|
||||
() => [props.pluginId, props.provider.id, props.connectionId, props.initialUri, rootUri.value] as const,
|
||||
() => void load(props.initialUri || rootUri.value),
|
||||
);
|
||||
|
||||
defineExpose({ refresh: () => load(currentUri.value) });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { AlertTriangle, Loader2 } from "@lucide/vue";
|
||||
import PluginFileManager from "@/components/plugins/PluginFileManager.vue";
|
||||
import PluginRefreshState from "@/components/plugins/PluginRefreshState.vue";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin";
|
||||
import type { InstalledPlugin } from "@/types/database";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
|
||||
const props = defineProps<{
|
||||
pluginId: string;
|
||||
@@ -16,10 +18,12 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const { t, locale: appLocale } = useI18n();
|
||||
const connectionStore = useConnectionStore();
|
||||
|
||||
const plugins = ref<InstalledPlugin[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const deferred = ref(false);
|
||||
let loadGeneration = 0;
|
||||
const entry = computed(() =>
|
||||
createFrontendPluginRegistry(plugins.value, appLocale.value)
|
||||
@@ -27,6 +31,7 @@ const entry = computed(() =>
|
||||
.find((candidate) => candidate.plugin.manifest.id === props.pluginId && candidate.contribution.id === props.providerId),
|
||||
);
|
||||
const provider = computed(() => (entry.value ? { ...entry.value.contribution, root_uri: props.rootUri || entry.value.contribution.root_uri } : undefined));
|
||||
const fileManagerRef = ref<InstanceType<typeof PluginFileManager>>();
|
||||
|
||||
async function load() {
|
||||
const generation = ++loadGeneration;
|
||||
@@ -45,20 +50,49 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => void load());
|
||||
watch(
|
||||
() => [props.pluginId, props.providerId],
|
||||
() => void load(),
|
||||
);
|
||||
async function refresh() {
|
||||
deferred.value = false;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
if (props.connectionId) await connectionStore.ensureConnected(props.connectionId);
|
||||
if (fileManagerRef.value?.refresh) {
|
||||
loading.value = false;
|
||||
return await fileManagerRef.value.refresh();
|
||||
}
|
||||
await load();
|
||||
} catch (cause) {
|
||||
loading.value = false;
|
||||
error.value = cause instanceof Error ? cause.message : String(cause);
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
deferred.value = !!props.connectionId && !connectionStore.connectedIds.has(props.connectionId);
|
||||
if (deferred.value) {
|
||||
loading.value = false;
|
||||
error.value = "";
|
||||
return;
|
||||
}
|
||||
void load();
|
||||
}
|
||||
|
||||
onMounted(start);
|
||||
watch(() => [props.pluginId, props.providerId, props.connectionId], start);
|
||||
|
||||
defineExpose({
|
||||
refresh,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex size-full min-h-0">
|
||||
<div v-if="loading" class="m-auto flex items-center text-sm text-muted-foreground"><Loader2 class="mr-2 size-4 animate-spin" />{{ t("pluginPlatform.loadingFilesystem") }}</div>
|
||||
<PluginRefreshState v-if="deferred" @refresh="void refresh()" />
|
||||
<div v-else-if="loading" class="m-auto flex items-center text-sm text-muted-foreground"><Loader2 class="mr-2 size-4 animate-spin" />{{ t("pluginPlatform.loadingFilesystem") }}</div>
|
||||
<div v-else-if="error || !provider" class="m-auto flex max-w-lg items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive">
|
||||
<AlertTriangle class="mt-0.5 size-4 shrink-0" />
|
||||
<span>{{ error || t("pluginPlatform.filesystemUnavailableFallback") }}</span>
|
||||
</div>
|
||||
<PluginFileManager v-else class="min-h-0 flex-1" :plugin-id="pluginId" :provider="provider" :connection-id="connectionId" :initial-uri="initialUri" />
|
||||
<PluginFileManager v-else ref="fileManagerRef" class="min-h-0 flex-1" :plugin-id="pluginId" :provider="provider" :connection-id="connectionId" :initial-uri="initialUri" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { Inbox, RefreshCcw } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { formatShortcut } from "@/lib/editor/shortcutRegistry";
|
||||
|
||||
const emit = defineEmits<{ refresh: [] }>();
|
||||
const { t } = useI18n();
|
||||
const modRKeys = formatShortcut("Mod+R")
|
||||
.split("+")
|
||||
.map((key) => (key === "Cmd" ? "⌘" : key));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex size-full flex-col items-center justify-center gap-3 text-sm text-muted-foreground">
|
||||
<Inbox class="h-8 w-8 opacity-60" />
|
||||
<div>{{ t("pluginPlatform.reloadRequired") }}</div>
|
||||
<div class="inline-flex items-center gap-1 text-xs text-muted-foreground/70">
|
||||
<span>{{ t("pluginPlatform.reloadHintPrefix") }}</span>
|
||||
<kbd v-for="key in modRKeys" :key="key" class="min-w-5 rounded border border-border/60 bg-muted/50 px-1.5 py-0.5 text-center font-mono text-[12px] leading-none text-muted-foreground shadow-xs">{{ key }}</kbd>
|
||||
<span>{{ t("pluginPlatform.reloadHintSuffix") }}</span>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" class="h-7 gap-1.5" @click="emit('refresh')">
|
||||
<RefreshCcw class="h-3.5 w-3.5" />
|
||||
{{ t("pluginPlatform.refresh") }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,25 +2,31 @@
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { AlertTriangle, Loader2 } from "@lucide/vue";
|
||||
import PluginWorkbenchHost from "@/components/plugins/PluginWorkbenchHost.vue";
|
||||
import PluginRefreshState from "@/components/plugins/PluginRefreshState.vue";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin";
|
||||
import type { PluginWorkbenchContext } from "@/lib/plugins/pluginHostBridge";
|
||||
import type { InstalledPlugin } from "@/types/database";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
|
||||
const props = defineProps<{
|
||||
pluginId: string;
|
||||
contributionId: string;
|
||||
connectionId?: string;
|
||||
context?: PluginWorkbenchContext;
|
||||
}>();
|
||||
|
||||
const { t, locale: appLocale } = useI18n();
|
||||
const connectionStore = useConnectionStore();
|
||||
const queryStore = useQueryStore();
|
||||
const plugins = ref<InstalledPlugin[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const deferred = ref(false);
|
||||
let loadGeneration = 0;
|
||||
const resolvedConnectionId = computed(() => props.connectionId || (typeof props.context?.connectionId === "string" ? props.context.connectionId : undefined));
|
||||
const entry = computed(() => createFrontendPluginRegistry(plugins.value, appLocale.value).findWorkbench(props.pluginId, props.contributionId));
|
||||
|
||||
async function load() {
|
||||
@@ -40,6 +46,30 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
deferred.value = false;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
if (resolvedConnectionId.value) await connectionStore.ensureConnected(resolvedConnectionId.value);
|
||||
await load();
|
||||
} catch (cause) {
|
||||
loading.value = false;
|
||||
error.value = cause instanceof Error ? cause.message : String(cause);
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
const connectionId = resolvedConnectionId.value;
|
||||
deferred.value = !!connectionId && !connectionStore.connectedIds.has(connectionId);
|
||||
if (deferred.value) {
|
||||
loading.value = false;
|
||||
error.value = "";
|
||||
return;
|
||||
}
|
||||
void load();
|
||||
}
|
||||
|
||||
function openWorkbench(pluginId: string, contributionId: string, context?: PluginWorkbenchContext) {
|
||||
const target = createFrontendPluginRegistry(plugins.value, appLocale.value).findWorkbench(pluginId, contributionId);
|
||||
queryStore.openPluginWorkbench(pluginId, contributionId, { title: target?.contribution.label || contributionId, context });
|
||||
@@ -58,16 +88,16 @@ function openFilesystem(pluginId: string, providerId: string, context?: PluginWo
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => void load());
|
||||
watch(
|
||||
() => [props.pluginId, props.contributionId],
|
||||
() => void load(),
|
||||
);
|
||||
onMounted(start);
|
||||
watch(() => [props.pluginId, props.contributionId, props.connectionId, props.context?.connectionId], start);
|
||||
|
||||
defineExpose({ refresh });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex size-full min-h-0">
|
||||
<div v-if="loading" class="m-auto flex items-center text-sm text-muted-foreground"><Loader2 class="mr-2 size-4 animate-spin" />{{ t("pluginPlatform.loadingWorkbench") }}</div>
|
||||
<PluginRefreshState v-if="deferred" @refresh="void refresh()" />
|
||||
<div v-else-if="loading" class="m-auto flex items-center text-sm text-muted-foreground"><Loader2 class="mr-2 size-4 animate-spin" />{{ t("pluginPlatform.loadingWorkbench") }}</div>
|
||||
<div v-else-if="error || !entry" class="m-auto flex max-w-lg items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive">
|
||||
<AlertTriangle class="mt-0.5 size-4 shrink-0" />
|
||||
<span>{{ error || t("pluginPlatform.workbenchUnavailableFallback") }}</span>
|
||||
|
||||
Reference in new issue
Block a user