Replaces all direct usage of browser globals and infrastructure service imports in UI components with dedicated application/state backend hooks. Introduces lint rules to prevent direct access to backend bridges and localStorage from components, promoting a cleaner separation of concerns and improved maintainability. Moves user preferences (e.g., port forwarding form mode) to persistent state hooks, updates port forwarding and SFTP logic to rely on backend hooks, and centralizes logging through a logger utility. Cleans up debug code and removes obsolete scripts from HTML. Improves testability, prepares for alternative backend implementations, and enforces architectural boundaries.
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { useCallback } from "react";
|
|
import { netcattyBridge } from "../../infrastructure/services/netcattyBridge";
|
|
|
|
export const useWindowControls = () => {
|
|
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?.();
|
|
}, []);
|
|
|
|
return {
|
|
closeSettingsWindow,
|
|
openSettingsWindow,
|
|
minimize,
|
|
maximize,
|
|
close,
|
|
isMaximized,
|
|
};
|
|
};
|
|
|