mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-31 20:03:37 +00:00
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
|
|
export interface WindowState {
|
|
isMaximized: boolean;
|
|
windowWidth: number;
|
|
windowHeight: number;
|
|
}
|
|
|
|
/**
|
|
* Hook to track window state (dimensions and maximized status)
|
|
* For Electron apps, considers window maximized if width > 1400px
|
|
* Also listens for window resize events to update state
|
|
*/
|
|
export function useWindowState(): WindowState {
|
|
const [windowState, setWindowState] = useState<WindowState>(() => {
|
|
if (typeof window === 'undefined') {
|
|
return { isMaximized: false, windowWidth: 0, windowHeight: 0 };
|
|
}
|
|
const width = window.innerWidth;
|
|
const height = window.innerHeight;
|
|
return {
|
|
isMaximized: width > 1400,
|
|
windowWidth: width,
|
|
windowHeight: height,
|
|
};
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (typeof window === 'undefined') return;
|
|
|
|
const updateWindowState = () => {
|
|
const width = window.innerWidth;
|
|
const height = window.innerHeight;
|
|
setWindowState({
|
|
isMaximized: width > 1400,
|
|
windowWidth: width,
|
|
windowHeight: height,
|
|
});
|
|
};
|
|
|
|
// Set initial state
|
|
updateWindowState();
|
|
|
|
// Listen for resize events
|
|
window.addEventListener('resize', updateWindowState);
|
|
|
|
return () => {
|
|
window.removeEventListener('resize', updateWindowState);
|
|
};
|
|
}, []);
|
|
|
|
return windowState;
|
|
}
|