mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-05 21:05:39 +08:00
feat: 抽离保留进程功能到设置里
This commit is contained in:
@@ -9,15 +9,7 @@ import type {
|
||||
PersonalWechatRuntimeProgressEvent,
|
||||
PersonalWechatRuntimeStatus
|
||||
} from '../../../../shared/personal-wechat-runtime'
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
Switch
|
||||
} from '../ui'
|
||||
import { Button, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '../ui'
|
||||
import { isMac, isWindows } from '../../utils/runtime-environment'
|
||||
import { PersonalWechatChatComposer, type ChatMessage } from './PersonalWechatChatComposer'
|
||||
import { PersonalWechatSetupGuide } from './PersonalWechatSetupGuide'
|
||||
@@ -89,7 +81,6 @@ function PersonalWechatMacSendDialog({
|
||||
const [sendError, setSendError] = useState<string | null>(null)
|
||||
const [voiceDiagnostic, setVoiceDiagnostic] = useState<PersonalWechatVoiceDiagnostic | null>(null)
|
||||
const [voiceDiagnosticOpen, setVoiceDiagnosticOpen] = useState(false)
|
||||
const [keepOneBotProcess, setKeepOneBotProcess] = useState(false)
|
||||
const requestIdRef = useRef(0)
|
||||
const restoreFocusRef = useRef<HTMLElement | null>(null)
|
||||
const closingRef = useRef(false)
|
||||
@@ -155,36 +146,6 @@ function PersonalWechatMacSendDialog({
|
||||
return () => window.clearInterval(timer)
|
||||
}, [refreshStatus, senderStatus])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMac) return undefined
|
||||
let active = true
|
||||
const readKeepProcess = window.api.getPersonalWechatKeepOneBotProcess
|
||||
if (!readKeepProcess) return undefined
|
||||
void readKeepProcess().then((keep) => {
|
||||
if (active && typeof keep === 'boolean') setKeepOneBotProcess(keep)
|
||||
})
|
||||
return () => {
|
||||
active = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleKeepOneBotProcessChange = async (keep: boolean): Promise<void> => {
|
||||
if (!isMac) return
|
||||
const saveKeepProcess = window.api.setPersonalWechatKeepOneBotProcess
|
||||
if (!saveKeepProcess) {
|
||||
setSendError('请重启 TraceMemo 后再使用“保留 OneBot 进程”')
|
||||
return
|
||||
}
|
||||
setKeepOneBotProcess(keep)
|
||||
try {
|
||||
const saved = await saveKeepProcess(keep)
|
||||
if (typeof saved === 'boolean') setKeepOneBotProcess(saved)
|
||||
} catch (error) {
|
||||
setKeepOneBotProcess(!keep)
|
||||
setSendError(error instanceof Error ? error.message : String(error))
|
||||
}
|
||||
}
|
||||
|
||||
const handleDownloadRuntime = async (): Promise<void> => {
|
||||
if (runtimeBusy) return
|
||||
setRuntimeBusy(true)
|
||||
@@ -399,34 +360,14 @@ function PersonalWechatMacSendDialog({
|
||||
)}
|
||||
</div>
|
||||
{setupReady && isMac && (
|
||||
<div className="personal-wechat-chat-footer flex items-center justify-between">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<span>保留 OneBot 进程</span>
|
||||
<Switch
|
||||
checked={keepOneBotProcess}
|
||||
onCheckedChange={(checked) => void handleKeepOneBotProcessChange(checked)}
|
||||
aria-label="保留 OneBot 进程"
|
||||
/>
|
||||
</div>
|
||||
<div className="personal-wechat-chat-footer flex items-center justify-end">
|
||||
<Button variant="link" size="sm" onClick={() => void handleOpenVoiceDiagnostic()}>
|
||||
语音发送诊断
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{!setupReady && (
|
||||
<div
|
||||
className={`personal-wechat-chat-footer flex items-center ${isMac ? 'justify-between' : 'justify-end'}`}
|
||||
>
|
||||
{isMac && (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<span>保留 OneBot 进程</span>
|
||||
<Switch
|
||||
checked={keepOneBotProcess}
|
||||
onCheckedChange={(checked) => void handleKeepOneBotProcessChange(checked)}
|
||||
aria-label="保留 OneBot 进程"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="personal-wechat-chat-footer flex items-center justify-end">
|
||||
<Button variant="outline" onClick={handleClose} disabled={isBusy}>
|
||||
关闭
|
||||
</Button>
|
||||
|
||||
@@ -15,7 +15,8 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
Input,
|
||||
Skeleton
|
||||
Skeleton,
|
||||
Switch
|
||||
} from '../../../components/ui'
|
||||
import { PersonalWechatSetupGuide } from '../../../components/chat/PersonalWechatSetupGuide'
|
||||
import { PersonalWechatSupportedVersionsContent } from '../../../components/chat/PersonalWechatSupportedVersionsContent'
|
||||
@@ -88,6 +89,8 @@ export function PersonalWechatSendPage({
|
||||
const [windowsPortInput, setWindowsPortInput] = useState('')
|
||||
const [windowsDetectedPort, setWindowsDetectedPort] = useState('')
|
||||
const [windowsEndpointBusy, setWindowsEndpointBusy] = useState(false)
|
||||
const [keepOneBotProcess, setKeepOneBotProcess] = useState(false)
|
||||
const [keepProcessBusy, setKeepProcessBusy] = useState(false)
|
||||
const [showWechatVersions, setShowWechatVersions] = useState(false)
|
||||
const runtimeVersionsTriggerRef = useRef<HTMLButtonElement | null>(null)
|
||||
const personalWechatRuntimeSupported = isMac && Boolean(runtimeStatus?.supported)
|
||||
@@ -128,6 +131,21 @@ export function PersonalWechatSendPage({
|
||||
return () => unsubscribe?.()
|
||||
}, [refresh])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMac) return undefined
|
||||
let active = true
|
||||
const readKeepProcess = window.api.getPersonalWechatKeepOneBotProcess
|
||||
if (typeof readKeepProcess !== 'function') return undefined
|
||||
void readKeepProcess()
|
||||
.then((keep) => {
|
||||
if (active && typeof keep === 'boolean') setKeepOneBotProcess(keep)
|
||||
})
|
||||
.catch(() => undefined)
|
||||
return () => {
|
||||
active = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (isWindows || !senderStatus || senderStatus.canSend || senderStatus.state === 'error') {
|
||||
return undefined
|
||||
@@ -219,6 +237,26 @@ export function PersonalWechatSendPage({
|
||||
}
|
||||
}
|
||||
|
||||
const handleKeepOneBotProcessChange = async (keep: boolean): Promise<void> => {
|
||||
if (!isMac || keepProcessBusy) return
|
||||
const saveKeepProcess = window.api.setPersonalWechatKeepOneBotProcess
|
||||
if (typeof saveKeepProcess !== 'function') {
|
||||
onNotice('请重启 TraceMemo 后再使用“保留 OneBot 进程”')
|
||||
return
|
||||
}
|
||||
setKeepProcessBusy(true)
|
||||
setKeepOneBotProcess(keep)
|
||||
try {
|
||||
const saved = await saveKeepProcess(keep)
|
||||
if (typeof saved === 'boolean') setKeepOneBotProcess(saved)
|
||||
} catch (reason) {
|
||||
setKeepOneBotProcess(!keep)
|
||||
onNotice(reason instanceof Error ? reason.message : String(reason))
|
||||
} finally {
|
||||
setKeepProcessBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const bindWechat = async (): Promise<void> => {
|
||||
if (binding) return
|
||||
setBinding(true)
|
||||
@@ -578,6 +616,20 @@ export function PersonalWechatSendPage({
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="col-span-full flex items-center justify-between gap-4 border-t border-border-subtle pt-4">
|
||||
<div>
|
||||
<strong className="block text-sm">保留 OneBot 进程</strong>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
退出 TraceMemo 后继续保留进程,重新打开时可以复用。
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={keepOneBotProcess}
|
||||
disabled={keepProcessBusy}
|
||||
onCheckedChange={(checked) => void handleKeepOneBotProcessChange(checked)}
|
||||
aria-label="保留 OneBot 进程"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<h2 className="settings-section-heading">配置状态</h2>
|
||||
|
||||
Reference in New Issue
Block a user