-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] esc快捷键取消截图需求讨论 #203
Comments
可以考虑截图窗口失去焦点的时候取消esc事件注册: // 聚焦时候注册事件
screenshots.$win.on('focus', () => {
globalShortcut.register('esc', () => {
if (screenshots.$win?.isFocused()) {
screenshots.endCapture()
}
})
})
// 失去焦点取消事件
screenshots.$win.on('blur', () => {
globalShortcut.unegister('esc')
}) |
不行哦,new Screenshots 后,screenshots.$win 是null,没有恰当的时机进行注册focus和blur |
|
const singleWrapper = (fn) => {
let isBind = false;
return () => {
if(!isBind) {
isBind = true;
fn();
}
}
}
const bindScreEvent = () => {
screenshots.$win.on('focus', () => {
globalShortcut.register('esc', () => {
if (screenshots.$win?.isFocused()) {
screenshots.endCapture()
}
})
})
screenshots.$win.on('blur', () => {
globalShortcut.unegister('esc')
})
}
const singleBindScreEv = singleWrapper(bindScreEvent)
// 开始截图
await screenshots.startCapture()
singleBindScreEv() |
good job,测了下在 singleWindow 为 true 下是可行的,但发现当 singleWindow 为 false 时,blur 事件不会触发,需要换成监听 closed 事件。另外 escBound 变量,我就直接挂在 $win 下了~~ |
我这边添加一个 screenshots.on('windowCreated', ($win) => {
$win.on('focus', () => {
globalShortcut.register('esc', () => {
if ($win?.isFocused()) {
screenshots.endCapture();
}
});
});
$win.on('blur', () => {
globalShortcut.unregister('esc');
});
}); |
可以的,这样就不用在每次调用截屏时去检测处理。 另外,刚才报的0.5.21版本无法触发 $win.on('focus') 事件,mac和win7后面测试了都正常,就linux不行 |
我这边在 PopOS 上可以触发,你可以拉一下这个仓库的dev分支,运行一下 packages/electron-screenshots 下面的代码试试,克隆到本地后执行一下命令 cd screenshots
yarn
yarn build
cd packages/electron-screenshots
yarn start |
不好意思,统信OS的机器在公司,我得后天上班时试下了。0.5.19和0.5.20之前验证了统信是没问题的 刚看了一眼commit,有点没明白,为什么注释写了linux值为dock时不能触发focus,下面的的代码还是写的dock呢 ? const windowTypes: Record<string, string | undefined> = { |
1 similar comment
不好意思,统信OS的机器在公司,我得后天上班时试下了。0.5.19和0.5.20之前验证了统信是没问题的 刚看了一眼commit,有点没明白,为什么注释写了linux值为dock时不能触发focus,下面的的代码还是写的dock呢 ? const windowTypes: Record<string, string | undefined> = { |
注释忘去掉了 |
啊,注释是错的? 那好像没看到有对linux不能触发focus相关的修复改动? |
我修改了electron-screenshots下的index.ts文件,添加了 |
好的,明天到公司了就测下 |
刚刚测了下,在统信下还是没有触发 on focus(on windowCreated有触发),看到有一个报错不知道是否有关: electron-screenshots SCREENSHOTS:capture NodeScreenshots capture() error Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/xxx/Downloads/screenshots-dev/packages/electron-screenshots/node_modules/node-screenshots-linux-x64-gnu/node-screenshots.linux-x64-gnu.node) at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822) at Module._extensions..node (node:internal/modules/cjs/loader:1259:18) at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822) at Module.load (node:internal/modules/cjs/loader:1044:32) at Module._load (node:internal/modules/cjs/loader:885:12) at f._load (node:electron/js2c/asar_bundle:2:13330) at Module.require (node:internal/modules/cjs/loader:1068:19) at require (node:internal/modules/cjs/helpers:103:18) at Object. (/home/xxx/Downloads/screenshots-dev/packages/electron-screenshots/node_modules/node-screenshots/index.js:190:31) at Module._compile (node:internal/modules/cjs/loader:1174:14) { code: 'ERR_DLOPEN_FAILED' } +25ms 本机查了下,strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_,确实最高只到 GLIBC_2.28 |
应该不影响,这个问题我再看看吧 |
把 new BrowserWindow里的type: windowTypes[process.platform]注释掉,on focus就能触发了,但发现例子里的窗口白屏了无法加载github页面了,不知道相不相关 |
应该不相关,你可以替换为百度,应该也一样 |
在 Linux 上, 可能的类型有 desktop、dock、toolbar、splash、notification 这几个测了下,就只有toolbar的行为是比较正常的(跟不设的效果一样),其他几个值都有些问题 |
目前文档上推荐esc取消截图方案为下述代码,但一旦使用globalShortcut,如果需要在其他页面上使用mousetrap捕捉esc事件就办法了。
需求:提供esc取消截图只在开始截图后才生效。
或者暴露更多screenshots的事件,我们在开始时注册globalShortcut,关闭时取消注册,目前只有ok、cancel、save 三个事件没办法做到上述需求
globalShortcut.register('esc', () => {
if (screenshots.$win?.isFocused()) {
screenshots.endCapture()
}
})
The text was updated successfully, but these errors were encountered: