73 lines
2.9 KiB
TypeScript
73 lines
2.9 KiB
TypeScript
import { useCallback } from "react";
|
|
import type { CaptureOptions, CaptureResult } from "../../../types/global";
|
|
import { captureSelectedSourceAction, exportCurrentGoodAction, hideOverlayAction, loadStoredArtifactSnapshotAction, refreshCaptureSourcesAction, runDemoScanAction, showOverlayAction } from "../services/appControllerService";
|
|
import type { AppControllerContext } from "../services/appControllerService";
|
|
import { useToast } from "../../feedback";
|
|
|
|
interface AppControllerActionsInput {
|
|
appControllerContext: AppControllerContext;
|
|
}
|
|
|
|
export interface AppControllerActionsResult {
|
|
loadStoredArtifactSnapshot: () => Promise<void>;
|
|
refreshCaptureSources: () => Promise<void>;
|
|
captureSelectedSource: (delayMs?: number, focusGenshin?: boolean, options?: CaptureOptions) => Promise<CaptureResult | null>;
|
|
runDemoScan: () => Promise<void>;
|
|
exportCurrentGood: () => Promise<void>;
|
|
showOverlay: () => Promise<void>;
|
|
hideOverlay: () => Promise<void>;
|
|
}
|
|
|
|
export function useAppControllerActions({
|
|
appControllerContext,
|
|
}: AppControllerActionsInput): AppControllerActionsResult {
|
|
const toast = useToast();
|
|
const loadStoredArtifactSnapshot = useCallback(async () => {
|
|
await loadStoredArtifactSnapshotAction(appControllerContext);
|
|
}, [appControllerContext]);
|
|
|
|
const refreshCaptureSources = useCallback(async () => {
|
|
await refreshCaptureSourcesAction(appControllerContext);
|
|
}, [appControllerContext]);
|
|
|
|
const captureSelectedSource = useCallback(async (delayMs = 0, focusGenshin = false, options?: CaptureOptions) => {
|
|
return captureSelectedSourceAction(appControllerContext, delayMs, focusGenshin, options);
|
|
}, [appControllerContext]);
|
|
|
|
const runDemoScan = useCallback(async () => {
|
|
await runDemoScanAction(appControllerContext, captureSelectedSource);
|
|
}, [appControllerContext, captureSelectedSource]);
|
|
|
|
const exportCurrentGood = useCallback(async () => {
|
|
await exportCurrentGoodAction(appControllerContext);
|
|
}, [appControllerContext]);
|
|
|
|
const showOverlay = useCallback(async () => {
|
|
const result = await showOverlayAction(appControllerContext);
|
|
if (result.ok) {
|
|
toast.success("Overlay geoeffnet", { description: "Die schreibgeschuetzte Ergebnis-Karte ist jetzt sichtbar." });
|
|
} else {
|
|
toast.error("Overlay konnte nicht geoeffnet werden", { description: "Pruefe die Desktop-App-Verbindung und versuche es erneut." });
|
|
}
|
|
}, [appControllerContext, toast]);
|
|
|
|
const hideOverlay = useCallback(async () => {
|
|
const result = await hideOverlayAction(appControllerContext);
|
|
if (result.ok) {
|
|
toast.success("Overlay geschlossen");
|
|
} else {
|
|
toast.error("Overlay konnte nicht geschlossen werden", { description: "Es ist kein aktives Overlay vorhanden oder die App-Verbindung fehlt." });
|
|
}
|
|
}, [appControllerContext, toast]);
|
|
|
|
return {
|
|
loadStoredArtifactSnapshot,
|
|
refreshCaptureSources,
|
|
captureSelectedSource,
|
|
runDemoScan,
|
|
exportCurrentGood,
|
|
showOverlay,
|
|
hideOverlay,
|
|
};
|
|
}
|