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

[Feature]: 翻译窗口加载速度优化建议 #798

Open
lanten opened this issue Apr 29, 2024 · 2 comments
Open

[Feature]: 翻译窗口加载速度优化建议 #798

lanten opened this issue Apr 29, 2024 · 2 comments

Comments

@lanten
Copy link

lanten commented Apr 29, 2024

Description

从按下快捷键到显示翻译窗口通常需要等待1-2秒钟。这个问题我忍了很久了,今天看了一下代码,实现了一个秒开的 demo:

2024-04-29.170403.mp4

首先在windows下需要跳过窗口创建动画,可以直接使用下面这个函数:

pub fn set_skip_animation(win: &Window) {
    #[cfg(target_os = "windows")]
    {
        use windows::Win32::{
            Foundation::{BOOL, HWND},
            Graphics::Dwm::{DwmSetWindowAttribute, DWMWA_TRANSITIONS_FORCEDISABLED},
        };
        let hwnd = win.hwnd().unwrap();
        unsafe {
            let _ = DwmSetWindowAttribute(
                HWND(hwnd.0),
                DWMWA_TRANSITIONS_FORCEDISABLED,
                &mut BOOL::from(true) as *mut _ as *mut std::ffi::c_void,
                std::mem::size_of::<BOOL>() as u32,
            );
        }
    }
}

并在 windows crate 中 添加 feature:Win32_Graphics_Dwm

跳过窗口动画可以加快窗口展示速度,配合翻译窗口的webview进程常驻内存可以实现瞬间打开。
两秒的启动速度实在是太慢了
跳过窗口启动动画比较简单,如果管理者认可的话我可以直接提PR
翻译窗口常驻内的存改动会比较大,可能需要进一步讨论

Application Scenario

all

References

No response

@HeronZhang
Copy link

发现这个问题+1,窗口加载速度有点慢,而且快捷键打开后没有默认选中文本框,还需要用鼠标手动点一下。

@liwuxi
Copy link

liwuxi commented May 9, 2024

666,快点提交 PR 吧,我已经迫不及待了

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

No branches or pull requests

3 participants