feat(electron): add Electron UI components and layout integration
This commit is contained in:
30
dashboard/src/hooks/useWindowControls.ts
Normal file
30
dashboard/src/hooks/useWindowControls.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { isElectron } from '@/lib/runtime'
|
||||
|
||||
export function useWindowControls() {
|
||||
const [isMaximized, setIsMaximized] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isElectron()) return
|
||||
|
||||
const api = window.electronAPI
|
||||
if (!api) return
|
||||
|
||||
api.isMaximized().then(setIsMaximized)
|
||||
|
||||
const unsubMax = api.onWindowMaximized(() => setIsMaximized(true))
|
||||
const unsubUnmax = api.onWindowUnmaximized(() => setIsMaximized(false))
|
||||
|
||||
return () => {
|
||||
unsubMax?.()
|
||||
unsubUnmax?.()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const minimize = useCallback(() => window.electronAPI?.minimizeWindow(), [])
|
||||
const toggleMaximize = useCallback(() => window.electronAPI?.maximizeWindow(), [])
|
||||
const close = useCallback(() => window.electronAPI?.closeWindow(), [])
|
||||
|
||||
return { close, isMaximized, minimize, toggleMaximize }
|
||||
}
|
||||
Reference in New Issue
Block a user