Merge pull request #842 from Jasonzhu1207/main

feat: add silent startup
This commit is contained in:
cc
2026-04-25 18:37:51 +08:00
committed by GitHub
4 changed files with 92 additions and 20 deletions

View File

@@ -195,6 +195,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
const [launchAtStartup, setLaunchAtStartup] = useState(false)
const [launchAtStartupSupported, setLaunchAtStartupSupported] = useState(isWindows || isMac)
const [launchAtStartupReason, setLaunchAtStartupReason] = useState('')
const [silentStartup, setSilentStartup] = useState(false)
const [windowCloseBehavior, setWindowCloseBehavior] = useState<configService.WindowCloseBehavior>('ask')
const [quoteLayout, setQuoteLayout] = useState<configService.QuoteLayout>('quote-top')
const [updateChannel, setUpdateChannel] = useState<configService.UpdateChannel>('stable')
@@ -222,6 +223,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
const [isFetchingImageKey, setIsFetchingImageKey] = useState(false)
const [isCheckingUpdate, setIsCheckingUpdate] = useState(false)
const [isUpdatingLaunchAtStartup, setIsUpdatingLaunchAtStartup] = useState(false)
const [isUpdatingSilentStartup, setIsUpdatingSilentStartup] = useState(false)
const [appVersion, setAppVersion] = useState('')
const [message, setMessage] = useState<{ text: string; success: boolean } | null>(null)
const [showDecryptKey, setShowDecryptKey] = useState(false)
@@ -445,6 +447,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
const savedMessagePushFilterList = await configService.getMessagePushFilterList()
const contactsResult = await window.electronAPI.chat.getContacts({ lite: true })
const savedLaunchAtStartupStatus = await window.electronAPI.app.getLaunchAtStartupStatus()
const savedSilentStartup = await configService.getSilentStartup()
const savedWindowCloseBehavior = await configService.getWindowCloseBehavior()
const savedQuoteLayout = await configService.getQuoteLayout()
const savedUpdateChannel = await configService.getUpdateChannel()
@@ -502,6 +505,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
setLaunchAtStartup(savedLaunchAtStartupStatus.enabled)
setLaunchAtStartupSupported(savedLaunchAtStartupStatus.supported)
setLaunchAtStartupReason(savedLaunchAtStartupStatus.reason || '')
setSilentStartup(savedSilentStartup)
setWindowCloseBehavior(savedWindowCloseBehavior)
setQuoteLayout(savedQuoteLayout)
if (savedUpdateChannel) {
@@ -615,6 +619,21 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
}
}
const handleSilentStartupChange = async (enabled: boolean) => {
if (isUpdatingSilentStartup) return
try {
setIsUpdatingSilentStartup(true)
await configService.setSilentStartup(enabled)
setSilentStartup(enabled)
showMessage(enabled ? '已开启静默启动' : '已关闭静默启动', true)
} catch (e: any) {
showMessage(`设置静默启动失败: ${e?.message || String(e)}`, false)
} finally {
setIsUpdatingSilentStartup(false)
}
}
const refreshWhisperStatus = async (modelDirValue = whisperModelDir) => {
try {
const result = await window.electronAPI.whisper?.getModelStatus()
@@ -1684,6 +1703,35 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
<div className="divider" />
<div className="form-group">
<label></label>
<span className="form-hint">
</span>
<div className="log-toggle-line">
<span className="log-status">
{isUpdatingSilentStartup
? '保存中...'
: (silentStartup ? '已开启' : '已关闭')}
</span>
<label className="switch" htmlFor="silent-startup-toggle">
<input
id="silent-startup-toggle"
className="switch-input"
type="checkbox"
checked={silentStartup}
disabled={isUpdatingSilentStartup}
onChange={(e) => {
void handleSilentStartupChange(e.target.checked)
}}
/>
<span className="switch-slider" />
</label>
</div>
</div>
<div className="divider" />
<div className="form-group">
<label></label>
<span className="form-hint"></span>