pot-desktop icon indicating copy to clipboard operation
pot-desktop copied to clipboard

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

Open lanten opened this issue 1 year ago • 6 comments

Description

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

https://github.com/pot-app/pot-desktop/assets/16203518/9d554bf0-c742-4c6f-8d52-4c68629e93bd

首先在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

lanten avatar Apr 29 '24 09:04 lanten

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

HeronZhang avatar May 08 '24 15:05 HeronZhang

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

liwuxi avatar May 09 '24 03:05 liwuxi

感觉这个转换的显示,点击【英语】后显示 image

elarbor avatar Jul 30 '24 03:07 elarbor