diff --git a/apps/web/src-election/main/index.ts b/apps/web/src-election/main/index.ts index 146cf95..626fd45 100644 --- a/apps/web/src-election/main/index.ts +++ b/apps/web/src-election/main/index.ts @@ -251,13 +251,6 @@ function regShortcut() { ); screenshots.startCapture(); }); - - globalShortcut.register("esc", () => { - if (screenshots.$win?.isFocused()) { - screenshots.endCapture(); - } - }); - // 打开所有窗口控制台 globalShortcut.register("ctrl+shift+i", () => { let windows = BrowserWindow.getAllWindows(); @@ -383,6 +376,21 @@ app.on("ready", () => { } }; + // 截图添加快捷键esc + screenshots.on('windowCreated', ($win) => { + $win.on('focus', () => { + globalShortcut.register('esc', () => { + if ($win?.isFocused()) { + screenshots.endCapture(); + } + }); + }); + + $win.on('blur', () => { + globalShortcut.unregister('esc'); + }); + }); + // 点击确定按钮回调事件 screenshots.on("ok", (e, buffer, bounds) => { let filename = tmp.tmpNameSync() + '.png'; diff --git a/yarn.lock b/yarn.lock index 2f77070..221e53b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11002,7 +11002,7 @@ react-draggable@^4.0.3: clsx "^1.1.1" prop-types "^15.8.1" -react-error-overlay@^6.0.11: +react-error-overlay@6.0.11, react-error-overlay@^6.0.11: version "6.0.11" resolved "https://registry.npmmirror.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz#92835de5841c5cf08ba00ddd2d677b6d17ff9adb" integrity sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==