From 7e217f7034b415f6ae2f2c7d56c49fd1b231e49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E6=91=87=E5=B0=8F=E5=AD=90?= <969409112@qq.com> Date: Sun, 12 Jul 2026 01:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=8E=AF=E5=A2=83=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 4 ++++ src/renderer/src/App.tsx | 30 ++++++++++++------------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index 6492c05..285378e 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,10 @@ # WeChat Database Key (Optional, can be entered in UI) VITE_DB_KEY= +# Auto login on startup with VITE_DB_KEY or saved key. +# Set to true/1/yes/on for local development. Default is disabled. +VITE_AUTO_LOGIN=false + # AI API Configuration (Optional, can be entered in UI) VITE_DEEPSEEK_API_KEY= VITE_AI_BASE_URL=https://api.deepseek.com diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index e18fc9b..05e6340 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -48,6 +48,9 @@ interface SelfInfo { const MAC_KEY_FAQ_URL = 'https://github.com/hicccc77/WeFlow/blob/main/docs/MAC-KEY-FAQ.md' const MESSAGE_MONITOR_DEBOUNCE_MS = 8000 const VIEW_MESSAGE_LIMIT = 600 +const AUTO_LOGIN_ENABLED = ['1', 'true', 'yes', 'on'].includes( + String(import.meta.env.VITE_AUTO_LOGIN || '').trim().toLowerCase() +) const getMessageIdentity = (message: Message): string => { if (message.localId) return `local:${message.localId}` @@ -288,21 +291,18 @@ function App(): React.ReactElement { setDbKey(key) setAutoConnectSource(envKey ? 'env' : 'saved') setDbKeyStatus( - envKey ? '已加载环境变量中的密钥,请手动点击 Connect' : '已加载安全保存的密钥,请手动点击 Connect' - ) - setDbKeyStatusKind('normal') - setBootState('login') - } - if (true) return - if (active) { - setBootState('connecting') - setDbKey(key) - setAutoConnectSource(envKey ? 'env' : 'saved') - setDbKeyStatus( - envKey ? '检测到环境变量中的密钥,正在自动连接...' : '已加载安全保存的密钥,正在自动连接...' + AUTO_LOGIN_ENABLED + ? envKey + ? '检测到环境变量中的密钥,正在自动连接...' + : '已加载安全保存的密钥,正在自动连接...' + : envKey + ? '已加载环境变量中的密钥,请手动点击 Connect' + : '已加载安全保存的密钥,请手动点击 Connect' ) setDbKeyStatusKind('normal') + setBootState(AUTO_LOGIN_ENABLED ? 'connecting' : 'login') } + if (!AUTO_LOGIN_ENABLED) return try { const result: any = await window.api.initDb(key) if (!active) return @@ -342,12 +342,6 @@ function App(): React.ReactElement { } }, []) - // useEffect(() => { - // if (import.meta.env.VITE_DB_KEY) { - // handleLogin(import.meta.env.VITE_DB_KEY); - // } - // }, []); - const handleLogin = async (keyInput?: string): Promise => { const keyToUse = keyInput || dbKey if (!keyToUse) return