Files
genshin-assistant/electron/preload.cjs
T
AzuTear c8ae0dd7bf fix(input): force Genshin foreground via AttachThreadInput (auto-scan no longer aborts)
Auto-scan aborted immediately with "Genshin konnte nicht in den Vordergrund
geholt werden". Root cause: the focus call runs in the background input/capture
helper process, and Windows' foreground lock silently refuses SetForegroundWindow
from a process that is neither foreground nor the last input source. When the user
clicks "Auto-Scan starten" the Electron window is foreground, so the helper's plain
SetForegroundWindow is dropped and focus stays false.

Fix (both the C# sidecar and the PowerShell fallback): before SetForegroundWindow,
attach our thread's input queue to the target (and current-foreground) window
thread with AttachThreadInput and clear SPI_..FOREGROUNDLOCKTIMEOUT, then restore.
This is the same technique Inventory Kamera and other reliable automators use; it
is what our helper was missing after the old ALT-tap workaround was removed on the
wrong assumption that equal integrity level is sufficient (that only covers UIPI
input injection, not foreground changes).

Sidecar recompiled + republished; electron build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 16:07:30 +02:00

32 lines
2.0 KiB
JavaScript

const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("assistantApi", {
loadSnapshot: () => ipcRenderer.invoke("snapshot:load"),
saveSnapshot: (snapshot) => ipcRenderer.invoke("snapshot:save", snapshot),
runMockScan: () => ipcRenderer.invoke("scan:runMock"),
listCaptureSources: () => ipcRenderer.invoke("capture:listSources"),
captureSource: (sourceId, delayMs = 0, focusGenshin = false, options) => ipcRenderer.invoke("capture:captureSource", sourceId, delayMs, focusGenshin, options),
clickScreen: (x, y) => ipcRenderer.invoke("automation:clickScreen", x, y),
scrollScreen: (notches, anchorX, anchorY) => ipcRenderer.invoke("automation:scrollScreen", notches, anchorX, anchorY),
getAutomationGuard: () => ipcRenderer.invoke("automation:getGuard"),
focusMainWindow: () => ipcRenderer.invoke("app:focusMainWindow"),
focusGenshin: () => ipcRenderer.invoke("automation:focusGenshin"),
focusGenshinForScanStart: () => ipcRenderer.invoke("automation:focusGenshin"),
getRuntimeInfo: () => ipcRenderer.invoke("app:getRuntimeInfo"),
saveReviewSample: (sample) => ipcRenderer.invoke("review:saveSample", sample),
loadReviewSamples: (limit = 50) => ipcRenderer.invoke("review:loadSamples", limit),
loadScannerLearningRules: () => ipcRenderer.invoke("scanner:loadLearningRules"),
saveScannerLearningRules: (rules) => ipcRenderer.invoke("scanner:saveLearningRules", rules),
loadArtifacts: () => ipcRenderer.invoke("artifacts:load"),
saveArtifacts: (records) => ipcRenderer.invoke("artifacts:saveMany", records),
exportGood: (payload) => ipcRenderer.invoke("good:export", payload),
publishScannerStatus: (status) => ipcRenderer.invoke("scanner:publishStatus", status),
showOverlay: () => ipcRenderer.invoke("overlay:show"),
hideOverlay: () => ipcRenderer.invoke("overlay:hide"),
onScannerCommand: (callback) => {
const listener = (_event, command) => callback(command);
ipcRenderer.on("scanner:command", listener);
return () => ipcRenderer.removeListener("scanner:command", listener);
},
});