ejbills / DockDoor

Window peeking for macOS
https://dockdoor.net
GNU General Public License v3.0
1.1k stars 29 forks source link

Doesn't work for Chrome PWA's #75

Closed SABRE1982 closed 2 months ago

SABRE1982 commented 3 months ago

When hovering over icons for Chrome PWA's ("installed" web apps), no preview is shown. Chrome itself works, as well as most native apps.

ShlomoCode commented 3 months ago

It seems that the AX API doesn't return a title for PWAs: CleanShot 2024-07-07 at 02 40 56@2x

However, the private API _AXUIElementGetWindow does return window id successfuly (which is also much more accurate than title). And when I added the following lines inside the loop at the top of findWindow (Of course, after defining the function signature so that XCode recognizes it):

var cgWindowId: CGWindowID = 0
let windowIDStatus = _AXUIElementGetWindow(axWindow, &cgWindowId)
if windowIDStatus == .success && window.windowID == cgWindowId {
    return axWindow
}

CleanShot 2024-07-07 at 03 26 44@2x

The preview works well for PWAs.

I think eventually there will be no choice but to use some private APIs for the critical operations that have no official replacement, such as getting a window ID and taking screenshots of windows in other spaces, etc.

Refs: https://stackoverflow.com/a/74914146 https://stackoverflow.com/a/10134254 https://stackoverflow.com/a/73349397

https://github.com/rxhanson/Rectangle/blob/main/Rectangle/TodoMode/TodoManager.swift#L160-L162 https://github.com/rxhanson/Rectangle/blob/main/Rectangle/Utilities/AXExtension.swift#L87-L92 https://github.com/rxhanson/Rectangle/blob/main/Rectangle/ShortcutManager.swift#L86

https://github.com/lwouis/alt-tab-macos/blob/master/src/logic/Window.swift#L233 https://github.com/lwouis/alt-tab-macos/blob/master/src/api-wrappers/PrivateApis.swift#L171-L174

ejbills commented 2 months ago

@ShlomoCode thoughts on making this a PR?

ShlomoCode commented 2 months ago

happily. The question is, after we use the window id is it still necessary to guess based on the size and position title, or can this part be removed?

ejbills commented 2 months ago

Maybe we can keep it as a fallback method, and just prioritize the private API usage? Though, I'm not sure which scenarios that method could possibly fail under. I'm not sure if a fallback is even needed, thoughts?

ShlomoCode commented 2 months ago

It seems pretty stable, I've searched and haven't seen any complaints about it. The apps on my computer work great with it, we can just remove it and see if there are issues from users? 😆

ejbills commented 2 months ago

Send in that PR :)

hasansultan92 commented 2 months ago

@SABRE1982 @ShlomoCode what PWA was used as a reference for this?