fix: resolve titlebar overlay and controlled component warnings

This commit is contained in:
pompurin404 2025-02-04 12:36:46 +08:00
parent a69d24b29c
commit 4a48445043
5 changed files with 15 additions and 7 deletions

View File

@ -213,7 +213,9 @@ export function registerIpcMainHandlers(): void {
}) })
ipcMain.handle('setTitleBarOverlay', (_e, overlay) => ipcMain.handle('setTitleBarOverlay', (_e, overlay) =>
ipcErrorWrapper(async (overlay): Promise<void> => { ipcErrorWrapper(async (overlay): Promise<void> => {
mainWindow?.setTitleBarOverlay(overlay) if (mainWindow && typeof mainWindow.setTitleBarOverlay === 'function') {
mainWindow.setTitleBarOverlay(overlay)
}
})(overlay) })(overlay)
) )
ipcMain.handle('setAlwaysOnTop', (_e, alwaysOnTop) => { ipcMain.handle('setAlwaysOnTop', (_e, alwaysOnTop) => {

View File

@ -2,12 +2,13 @@ import React from 'react'
import { cn, Switch, SwitchProps } from '@heroui/react' import { cn, Switch, SwitchProps } from '@heroui/react'
import './border-switch.css' import './border-switch.css'
interface SiderSwitchProps extends SwitchProps { interface BorderSwitchProps extends Omit<SwitchProps, 'isSelected'> {
isShowBorder?: boolean isShowBorder?: boolean
isSelected?: boolean
} }
const BorderSwitch: React.FC<SiderSwitchProps> = (props) => { const BorderSwitch: React.FC<BorderSwitchProps> = (props) => {
const { isShowBorder = false, classNames, ...switchProps } = props const { isShowBorder = false, isSelected = false, classNames, ...switchProps } = props
return ( return (
<Switch <Switch
@ -21,6 +22,7 @@ const BorderSwitch: React.FC<SiderSwitchProps> = (props) => {
...classNames ...classNames
}} }}
size="sm" size="sm"
isSelected={isSelected}
{...switchProps} {...switchProps}
/> />
) )

View File

@ -95,7 +95,7 @@ const SysproxySwitcher: React.FC<Props> = (props) => {
</Button> </Button>
<BorderSwitch <BorderSwitch
isShowBorder={match && enable} isShowBorder={match && enable}
isSelected={enable} isSelected={enable ?? false}
onValueChange={onChange} onValueChange={onChange}
/> />
</div> </div>

View File

@ -98,7 +98,7 @@ const TunSwitcher: React.FC<Props> = (props) => {
</Button> </Button>
<BorderSwitch <BorderSwitch
isShowBorder={match && enable} isShowBorder={match && enable}
isSelected={enable} isSelected={enable ?? false}
onValueChange={onChange} onValueChange={onChange}
/> />
</div> </div>

View File

@ -276,7 +276,11 @@ export async function webdavDelete(filename: string): Promise<void> {
} }
export async function setTitleBarOverlay(overlay: TitleBarOverlayOptions): Promise<void> { export async function setTitleBarOverlay(overlay: TitleBarOverlayOptions): Promise<void> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('setTitleBarOverlay', overlay)) try {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('setTitleBarOverlay', overlay))
} catch (error) {
console.debug('setTitleBarOverlay not supported on this platform')
}
} }
export async function setAlwaysOnTop(alwaysOnTop: boolean): Promise<void> { export async function setAlwaysOnTop(alwaysOnTop: boolean): Promise<void> {