tisfeng / Easydict

一个简洁优雅的词典翻译 macOS App。开箱即用,支持离线 OCR 识别,支持有道词典,🍎 苹果系统词典,🍎 苹果系统翻译,OpenAI,Gemini,DeepL,Google,Bing,腾讯,百度,阿里,小牛,彩云和火山翻译。A concise and elegant Dictionary and Translator macOS App for looking up words and translating text.
GNU General Public License v3.0
7.04k stars 356 forks source link

Main window cannot open after escape key pressed #472

Closed phlpsong closed 6 months ago

phlpsong commented 6 months ago

close https://github.com/tisfeng/Easydict/issues/471

tisfeng commented 6 months ago

After this PR https://github.com/tisfeng/Easydict/pull/448 , we now no longer need to destroy the main window in most cases, such as by clicking the close button in the upper left corner, or the escape key.

To simplify the logic, I think we can remove the closeFloatingWindowExceptMain method and use the closeFloatingWindow method, just like fixedWindow, and change the main window to not release when closed: mainWindow.releasedWhenClosed = NO.

I simply tested it and it works.

https://github.com/tisfeng/Easydict/blob/e5ce53bc20ad6b34d04dff62a05fa2d6a361818c/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m#L196

- (EZFixedQueryWindow *)fixedWindow {
    if (!_fixedWindow) {
        _fixedWindow = [EZFixedQueryWindow shared];
        _fixedWindow.releasedWhenClosed = NO;
    }
    return _fixedWindow;
}
phlpsong commented 6 months ago

You are right. It's a better approach.

tisfeng commented 6 months ago

@phlpsong Sorry, I didn't consider it thoroughly before. In some cases, it is not necessary to close the main window, such as when the main window loses focus or when opening App links.

I have improved the code by adding closeFloatingWindowIfNotPinned and closeFloatingWindowIfNotPinnedOrMain methods to handle different situations.

The specific usage here is a bit complex, please test the effect of the code carefully.

phlpsong commented 6 months ago

Looks good.

I have left some comments and would appreciate it if you could clarify them.