Skip to content
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

新增:输入框有内容时ESC也会关闭窗口 #233

Closed
wants to merge 5 commits into from

Conversation

jiongjiongJOJO
Copy link
Contributor

优化功能:QQ默认在输入框内有内容的时候,按下Esc键不会隐藏窗口。此功能就是忽略这一操作,只要按下Esc就会隐藏。同时考虑到原有功能“阻止 ESC 关闭窗口”可能会有冲突,所以在处理时,一旦开启了“阻止 ESC 关闭窗口”功能,该功能就会失效。

平时开发没使用过js,对这块很不熟,但是已经测试过正常处理,如果有什么不对的地方,非常希望能够提出来。

@jiongjiongJOJO
Copy link
Contributor Author

README.md文档的功能列表没添加,如果能够合并的话,可以加一下这个功能到列表

src/main_modules/escapeWindowWithInput.js Outdated Show resolved Hide resolved
todoList.md Outdated Show resolved Hide resolved
@xiyuesaves
Copy link
Owner

xiyuesaves commented May 15, 2024

经测试,功能无效,webContents 中没有 keyup 这个事件,相关代码并不会被执行

* @return {void} 此函数不返回任何内容。
*/
export function escapeWindowWithInput(window) {
window.webContents.on("keyup", async (event, input) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webContents 中没有 keyup 事件,该监听不会在任何时候被触发

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个问题解决了,我后面再提交吧,现在问题是窗口隐藏和关闭怎么判断,到时候如果成了一起提交,不成就直接close吧😥

if (input.key == "Escape") {
try {
if (config.escapeWindowWithInput && !config.preventEscape) {
if (window.isClosable()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isClosable 方法不支持 Linux 系统,而且它返回的是窗口是否可以被用户手动关闭,这并不能作为判断标准,因为主窗口该函数返回的也是 true
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否直接使用window.close()方法,close方法是模拟用户点击X按钮,正常情况下的窗口,应该都包含X,都能使用户主动关闭,直接用close方法应该是可行的吧,目前测试,使用close方法关闭多重窗口,均正常处理,且重新打开时未出现异常。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接调用 window.close() 是可行的,但我想将两个功能放在一个模块内,方便后续调试和整理

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

刚测试 子窗口关不掉,跟官方的不一致。
比如个人资料编辑页面。侧边栏管理页面。
😨😨麻了

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honeyview_4888762ded82468b要不单独做成一个插件?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是不是可以理解成两个功能,一个是老板键一个是阻止ESC关闭
我上面提到的好像也还行,没有写css,大致看一下效果。
Clip_2024-05-16_12-04-16

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm当我前面没说,还是继续研究要怎么实现这个功能吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我通过窗口的源码找到了相关的内容,有什么方法检测是否打开了对话框吗?

    <div class="q-dialog lite-tools-vue-component vue-component" style="position: fixed; z-index: 4000;">
        <div class="q-dialog-modal" style="position: inherit; background: var(--overlay_mask_standard);"></div>
        <div class="modify-profile-dialog q-dialog-main lite-tools-vue-component vue-component" style="margin: auto 10px;">
            <div class="q-dialog-header">
                <div class="q-dialog-window-title">编辑资料</div><i class="q-svg-icon q-icon q-dialog-close lite-tools-vue-component vue-component" data-v-d4820ab3="" style="width: 20px; height: 20px; --234e3e61: var(--icon-primary);"><svg viewBox="0 0 24 24"><use xlink:href="/_upper_/resource/icons/close_24.svg#close_24"></use></svg></i>
            </div>
            <div class="q-dialog-body">
                <div class="q-dialog-text-area">
                    <!---->
                    <div class="q-dialog-content">

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最简单的办法是在 DOM 中查找是否存在弹窗的 class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我使用这个代码在有弹窗的页面获取到的数量是0:

const hasDialog = await window.webContents.executeJavaScript(`
  document.getElementsByClassName("q-dialog").length;
`);

Clip_2024-05-16_21-09-01

但是我使用chii-devtools工具在console里获取到的数量是1,不知道这个是为什么😪
image

@jiongjiongJOJO
Copy link
Contributor Author

Windows新版本好像已经修复了这个bug。。。被官方背刺了,之前反馈的时候说是不修,现在又正常了。。。我这边关掉所有插件后测试是正常的,其他人可以帮忙测试一下是不是官方做了这个功能。
版本: 9.9.10-23873 (64位)

@jiongjiongJOJO
Copy link
Contributor Author

Windows新版本好像已经修复了这个bug。。。被官方背刺了,之前反馈的时候说是不修,现在又正常了。。。我这边关掉所有插件后测试是正常的,其他人可以帮忙测试一下是不是官方做了这个功能。 版本: 9.9.10-23873 (64位)

官方那边回复输入框有内容不会关闭。也就是说他们设计的是有内容不会关闭。
不知道这个是不是bug。。。

@jiongjiongJOJO
Copy link
Contributor Author

Windows新版本好像已经修复了这个bug。。。被官方背刺了,之前反馈的时候说是不修,现在又正常了。。。我这边关掉所有插件后测试是正常的,其他人可以帮忙测试一下是不是官方做了这个功能。 版本: 9.9.10-23873 (64位)

官方那边回复输入框有内容不会关闭。也就是说他们设计的是有内容不会关闭。 不知道这个是不是bug。。。

暂时关闭吧,不知道官方那边动态是什么

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants