Files
Netcatty/application/state/useWindowControls.ts
T
atoz03 e948a7a869 fix: route Cmd+W through existing tab close flow (#1234)
* fix: route Cmd+W through existing tab close flow

Keep the original tab-close behavior intact, and close the main or settings window only when there is no active closable tab to handle.

* fix: fall back to closing non-listener windows on Cmd+W

Treat BrowserWindow instances that do not participate in Netcatty's command-close bridge as regular closable windows. Keep the existing command-close path for the main and settings windows, and add tests that cover both the fallback close behavior and the renderer-capable send path.
2026-06-04 17:20:44 +08:00

71 lines
1.9 KiB
TypeScript

import { useCallback } from "react";
import { netcattyBridge } from "../../infrastructure/services/netcattyBridge";
export const useWindowControls = () => {
const notifyRendererReady = useCallback(() => {
try {
netcattyBridge.get()?.rendererReady?.();
} catch {
// ignore
}
}, []);
const closeSettingsWindow = useCallback(async () => {
const bridge = netcattyBridge.get();
await bridge?.closeSettingsWindow?.();
}, []);
const openSettingsWindow = useCallback(async () => {
const bridge = netcattyBridge.get();
return bridge?.openSettingsWindow?.();
}, []);
const minimize = useCallback(async () => {
const bridge = netcattyBridge.get();
await bridge?.windowMinimize?.();
}, []);
const maximize = useCallback(async () => {
const bridge = netcattyBridge.get();
return bridge?.windowMaximize?.();
}, []);
const close = useCallback(async () => {
const bridge = netcattyBridge.get();
await bridge?.windowClose?.();
}, []);
const isMaximized = useCallback(async () => {
const bridge = netcattyBridge.get();
return bridge?.windowIsMaximized?.();
}, []);
const isFullscreen = useCallback(async () => {
const bridge = netcattyBridge.get();
return bridge?.windowIsFullscreen?.() ?? false;
}, []);
const onFullscreenChanged = useCallback((cb: (isFullscreen: boolean) => void) => {
const bridge = netcattyBridge.get();
return bridge?.onWindowFullScreenChanged?.(cb) ?? (() => {});
}, []);
const onWindowCommandCloseRequested = useCallback((cb: () => void) => {
const bridge = netcattyBridge.get();
return bridge?.onWindowCommandCloseRequested?.(cb) ?? (() => {});
}, []);
return {
notifyRendererReady,
closeSettingsWindow,
openSettingsWindow,
minimize,
maximize,
close,
isMaximized,
isFullscreen,
onFullscreenChanged,
onWindowCommandCloseRequested,
};
};