Fix repeated reboots when useWindowFrame switch (#457)

- add debounce / statelock(isRelaunching) to avoid multiple restarts due to rapid consecutive clicks.
This commit is contained in:
MingLLuo 2025-01-17 08:43:55 +08:00 committed by GitHub
parent df7066a5f4
commit 749ac64698
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@ import {
writeTheme writeTheme
} from '@renderer/utils/ipc' } from '@renderer/utils/ipc'
import { useAppConfig } from '@renderer/hooks/use-app-config' import { useAppConfig } from '@renderer/hooks/use-app-config'
import debounce from '@renderer/utils/debounce'
import { platform } from '@renderer/utils/init' import { platform } from '@renderer/utils/init'
import { useTheme } from 'next-themes' import { useTheme } from 'next-themes'
import { IoIosHelpCircle, IoMdCloudDownload } from 'react-icons/io' import { IoIosHelpCircle, IoMdCloudDownload } from 'react-icons/io'
@ -35,6 +36,7 @@ const GeneralConfig: React.FC = () => {
const [customThemes, setCustomThemes] = useState<{ key: string; label: string }[]>() const [customThemes, setCustomThemes] = useState<{ key: string; label: string }[]>()
const [openCSSEditor, setOpenCSSEditor] = useState(false) const [openCSSEditor, setOpenCSSEditor] = useState(false)
const [fetching, setFetching] = useState(false) const [fetching, setFetching] = useState(false)
const [isRelaunching, setIsRelaunching] = useState(false)
const { setTheme } = useTheme() const { setTheme } = useTheme()
const { const {
silentStart = false, silentStart = false,
@ -270,10 +272,18 @@ const GeneralConfig: React.FC = () => {
<Switch <Switch
size="sm" size="sm"
isSelected={useWindowFrame} isSelected={useWindowFrame}
onValueChange={async (v) => { isDisabled={isRelaunching}
onValueChange={debounce(async (v) => {
if (isRelaunching) return
setIsRelaunching(true)
try {
await patchAppConfig({ useWindowFrame: v }) await patchAppConfig({ useWindowFrame: v })
await relaunchApp() await relaunchApp()
}} } catch (e) {
alert(e)
setIsRelaunching(false)
}
}, 1000)}
/> />
</SettingItem> </SettingItem>
<SettingItem title="背景色" divider> <SettingItem title="背景色" divider>