fix electron titlebar context menu freeze
This commit is contained in:
@@ -3119,6 +3119,16 @@ function attachDevToolsShortcut(win: BrowserWindow): void {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function suppressSystemContextMenu(win: BrowserWindow): void {
|
||||||
|
type SystemContextMenuWindow = BrowserWindow & {
|
||||||
|
on(event: 'system-context-menu', listener: (event: { preventDefault: () => void }) => void): BrowserWindow
|
||||||
|
}
|
||||||
|
|
||||||
|
;(win as SystemContextMenuWindow).on('system-context-menu', (event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function toggleFocusedDevTools(): void {
|
function toggleFocusedDevTools(): void {
|
||||||
const target = BrowserWindow.getFocusedWindow()
|
const target = BrowserWindow.getFocusedWindow()
|
||||||
if (!target) return
|
if (!target) return
|
||||||
@@ -3178,6 +3188,7 @@ function createWindow(): void {
|
|||||||
})
|
})
|
||||||
|
|
||||||
attachDevToolsShortcut(mainWindow)
|
attachDevToolsShortcut(mainWindow)
|
||||||
|
suppressSystemContextMenu(mainWindow)
|
||||||
mainWindow.once('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
splashWindow?.close()
|
splashWindow?.close()
|
||||||
|
|||||||
@@ -445,14 +445,24 @@ export default function TitleBar({ user, accessToken = '', onHelpClick, onOpenCo
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
}
|
}
|
||||||
|
const handleWindowControlMouseDown = (event: React.MouseEvent<HTMLButtonElement>): void => {
|
||||||
|
if (event.button !== 0) suppressTitlebarContextMenu(event)
|
||||||
|
}
|
||||||
|
const releaseWindowControlFocus = (event: React.SyntheticEvent<HTMLButtonElement>): void => {
|
||||||
|
event.currentTarget.blur()
|
||||||
|
}
|
||||||
|
const windowControlStyle = { WebkitAppRegion: 'no-drag' } as React.CSSProperties
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<header
|
<header
|
||||||
className="relative z-[10020] flex h-[38px] shrink-0 items-center justify-between rounded-t-[18px] bg-[#111520] px-3 pl-5"
|
className="relative z-[10020] flex h-[38px] shrink-0 items-center justify-between rounded-t-[18px] bg-[#111520] px-3 pl-5"
|
||||||
style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
|
style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
|
||||||
|
onContextMenuCapture={suppressTitlebarContextMenu}
|
||||||
onContextMenu={suppressTitlebarContextMenu}
|
onContextMenu={suppressTitlebarContextMenu}
|
||||||
|
onMouseDownCapture={(event) => {
|
||||||
|
if (event.button === 2) suppressTitlebarContextMenu(event)
|
||||||
|
}}
|
||||||
onMouseDown={(event) => {
|
onMouseDown={(event) => {
|
||||||
if (event.button === 2) suppressTitlebarContextMenu(event)
|
if (event.button === 2) suppressTitlebarContextMenu(event)
|
||||||
}}
|
}}
|
||||||
@@ -648,13 +658,61 @@ export default function TitleBar({ user, accessToken = '', onHelpClick, onOpenCo
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-1 flex items-center gap-0.5">
|
<div className="ml-1 flex items-center gap-0.5">
|
||||||
<button type="button" aria-label="Minimize" className={winButton} onClick={() => window.titlebar.minimize()}>
|
<button
|
||||||
|
type="button"
|
||||||
|
tabIndex={-1}
|
||||||
|
aria-label="Minimize"
|
||||||
|
className={winButton}
|
||||||
|
style={windowControlStyle}
|
||||||
|
onClick={(event) => {
|
||||||
|
releaseWindowControlFocus(event)
|
||||||
|
window.titlebar.minimize()
|
||||||
|
}}
|
||||||
|
onPointerDownCapture={handleWindowControlMouseDown}
|
||||||
|
onMouseDown={handleWindowControlMouseDown}
|
||||||
|
onMouseUp={releaseWindowControlFocus}
|
||||||
|
onAuxClick={suppressTitlebarContextMenu}
|
||||||
|
onContextMenuCapture={suppressTitlebarContextMenu}
|
||||||
|
onContextMenu={suppressTitlebarContextMenu}
|
||||||
|
>
|
||||||
<Minus size={15} />
|
<Minus size={15} />
|
||||||
</button>
|
</button>
|
||||||
<button type="button" aria-label="Maximize" className={winButton} onClick={() => window.titlebar.maximize()}>
|
<button
|
||||||
|
type="button"
|
||||||
|
tabIndex={-1}
|
||||||
|
aria-label="Maximize"
|
||||||
|
className={winButton}
|
||||||
|
style={windowControlStyle}
|
||||||
|
onClick={(event) => {
|
||||||
|
releaseWindowControlFocus(event)
|
||||||
|
window.titlebar.maximize()
|
||||||
|
}}
|
||||||
|
onPointerDownCapture={handleWindowControlMouseDown}
|
||||||
|
onMouseDown={handleWindowControlMouseDown}
|
||||||
|
onMouseUp={releaseWindowControlFocus}
|
||||||
|
onAuxClick={suppressTitlebarContextMenu}
|
||||||
|
onContextMenuCapture={suppressTitlebarContextMenu}
|
||||||
|
onContextMenu={suppressTitlebarContextMenu}
|
||||||
|
>
|
||||||
<Square size={13} />
|
<Square size={13} />
|
||||||
</button>
|
</button>
|
||||||
<button type="button" aria-label="Close" className={winButton} onClick={() => setShowCloseConfirm(true)}>
|
<button
|
||||||
|
type="button"
|
||||||
|
tabIndex={-1}
|
||||||
|
aria-label="Close"
|
||||||
|
className={winButton}
|
||||||
|
style={windowControlStyle}
|
||||||
|
onClick={(event) => {
|
||||||
|
releaseWindowControlFocus(event)
|
||||||
|
setShowCloseConfirm(true)
|
||||||
|
}}
|
||||||
|
onPointerDownCapture={handleWindowControlMouseDown}
|
||||||
|
onMouseDown={handleWindowControlMouseDown}
|
||||||
|
onMouseUp={releaseWindowControlFocus}
|
||||||
|
onAuxClick={suppressTitlebarContextMenu}
|
||||||
|
onContextMenuCapture={suppressTitlebarContextMenu}
|
||||||
|
onContextMenu={suppressTitlebarContextMenu}
|
||||||
|
>
|
||||||
<X size={15} />
|
<X size={15} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user