From a190e1bff608b8b2e5324133fad3a34aa44e12ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=A1=E5=A4=8D=E4=B9=A0?= <2353956224@qq.com> Date: Wed, 22 Apr 2026 13:53:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 4 +- src/components/HostListDialog.vue | 102 ++++----------------- src/layout/WorkbenchLayout.vue | 4 +- src/utils/hostListGateMonitor.js | 143 ++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 90 deletions(-) create mode 100644 src/utils/hostListGateMonitor.js diff --git a/src/App.vue b/src/App.vue index c807af8..8d5965f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -212,7 +212,9 @@ const syncAutotkPermissionLimit = async () => { if (!isElectron()) return try { const permissions = getPermissions() - if (permissions?.autotk === 1) return + const hasAutotkPermission = permissions?.autotk === 1 + const hasWebAiPermission = permissions?.webAi === 1 + if (hasAutotkPermission || hasWebAiPermission) return await window.electronAPI.updateAutomationConfig({ filters: { maxAnchorCount: 1 diff --git a/src/components/HostListDialog.vue b/src/components/HostListDialog.vue index a767262..fe655f0 100644 --- a/src/components/HostListDialog.vue +++ b/src/components/HostListDialog.vue @@ -270,6 +270,7 @@ import { ref, computed, watch, onMounted, onUnmounted } from 'vue' import { isElectron } from '../utils/electronBridge' import { getPermissions } from '@/utils/storage' import { usePythonBridge } from '@/utils/pythonBridge' +import { ensureHostListGateMonitorRunning, stopHostListGateMonitor, syncHostListGateDecision } from '@/utils/hostListGateMonitor' const props = defineProps({ visible: { type: Boolean, required: true } @@ -339,11 +340,12 @@ const maxCount = ref() const checkTaskGateState = ref(null) const selectedLevels = ref(new Set()) const showLevelDropdown = ref(false) -const hostListDialogInstanceId = `host-list-dialog-${Math.random().toString(36).slice(2)}` const resolveRestrictedMaxAnchorCount = (fallbackValue = 9999999) => { const permissions = getPermissions() - return permissions?.webAi === 1 ? fallbackValue : 0 + const hasAutotkPermission = permissions?.autotk === 1 + const hasWebAiPermission = permissions?.webAi === 1 + return hasAutotkPermission || hasWebAiPermission ? fallbackValue : 1 } // 添加主播弹窗状态 @@ -402,23 +404,17 @@ watch(() => props.visible, (newVal) => { if (newVal) { document.body.style.overflow = 'hidden' loadLocalGateConfig() - if (gateEnabled.value) { - claimGateOwnership() - } + if (gateEnabled.value) ensureHostListGateMonitorRunning() loadHosts() loadConfig() } else { document.body.style.overflow = '' } - - refreshHostListMonitor() }) onMounted(() => { loadLocalGateConfig() - if (gateEnabled.value) { - claimGateOwnership() - } + if (gateEnabled.value) ensureHostListGateMonitorRunning() loadConfig() if (props.visible) { @@ -426,11 +422,13 @@ onMounted(() => { loadHosts() } - refreshHostListMonitor() + if (gateEnabled.value) { + void syncHostListGateDecision(true) + } }) onUnmounted(() => { - releaseGateOwnership() + document.body.style.overflow = '' }) // 监听过滤器变化,同步到后端配置 @@ -501,76 +499,6 @@ const loadConfig = async () => { } } -const getGateRuntime = () => { - if (typeof window === 'undefined') { - return { ownerId: null, timer: null } - } - - if (!window.__hostListGateRuntime) { - window.__hostListGateRuntime = { - ownerId: null, - timer: null, - } - } - - return window.__hostListGateRuntime -} - -const isGateOwner = () => { - return getGateRuntime().ownerId === hostListDialogInstanceId -} - -const claimGateOwnership = () => { - const runtime = getGateRuntime() - if (runtime.ownerId === hostListDialogInstanceId) return - - if (runtime.timer) { - clearInterval(runtime.timer) - runtime.timer = null - } - - runtime.ownerId = hostListDialogInstanceId -} - -const releaseGateOwnership = () => { - const runtime = getGateRuntime() - if (runtime.ownerId !== hostListDialogInstanceId) return - - if (runtime.timer) { - clearInterval(runtime.timer) - runtime.timer = null - } - - runtime.ownerId = null -} - -const refreshHostListMonitor = () => { - if (!isElectron()) return - - const runtime = getGateRuntime() - const shouldRun = gateEnabled.value && isGateOwner() - - if (!shouldRun) { - if (runtime.timer && isGateOwner()) { - clearInterval(runtime.timer) - runtime.timer = null - } - return - } - - if (runtime.timer) return - - runtime.timer = setInterval(async () => { - if (!gateEnabled.value || !isGateOwner()) { - refreshHostListMonitor() - return - } - - await loadHosts() - await syncControlCheckTaskGate() - }, HOST_LIST_MONITOR_INTERVAL_MS) -} - const loadLocalGateConfig = () => { try { const savedGateEnabled = sessionStorage.getItem(HOST_LIST_GATE_ENABLED_SESSION_KEY) @@ -634,7 +562,6 @@ const persistGateState = (value) => { const syncControlCheckTaskGate = async (forceSync = false) => { if (!isElectron()) return if (!gateEnabled.value) return - if (!isGateOwner()) return const hostCount = filteredHosts.value.length const upperLimit = Number(maxCount.value) @@ -766,16 +693,15 @@ watch(gateEnabled, async (enabled) => { persistGateEnabled() if (enabled) { - claimGateOwnership() - refreshHostListMonitor() + ensureHostListGateMonitorRunning() + void syncHostListGateDecision(true) void syncControlCheckTaskGate(true) return } checkTaskGateState.value = null persistGateState(null) - releaseGateOwnership() - refreshHostListMonitor() + stopHostListGateMonitor() if (!isElectron()) return @@ -809,6 +735,8 @@ const filteredHosts = computed(() => { watch( [() => filteredHosts.value.length, minCount, maxCount, gateEnabled], () => { + if (gateEnabled.value) ensureHostListGateMonitorRunning() + void syncHostListGateDecision() void syncControlCheckTaskGate() } ) diff --git a/src/layout/WorkbenchLayout.vue b/src/layout/WorkbenchLayout.vue index 1f535c9..5605bf3 100644 --- a/src/layout/WorkbenchLayout.vue +++ b/src/layout/WorkbenchLayout.vue @@ -30,12 +30,12 @@ 自动私信 - +