SnosMe / electron-overlay-window

Creating overlays is easy like never before
MIT License
201 stars 38 forks source link

Added MacOS support for 3.0 #29

Closed hsource closed 1 year ago

hsource commented 1 year ago

Motivation

I wanted to get awakened_poe_trade working on Mac, and this was the biggest barrier, since no binaries existed for this on Mac.

PS: thanks a lot for the great demo app! I don't think developing this would've been possible without that

Fix

Created Mac interface for overlay_window.h - for the most part, this is structured similarly to the Windows/Linux code, with a few exceptions:

  1. Mac doesn't allow windows to be attached/reparented to those of other applications, so the overlay window has to stay within the separate app. To make this not look weird, we hide the window whenever the target window isn't on top
  2. Mac doesn't give a global way to listen to windows becoming the foreground window. We instead do 2 things:
    • Attach to the foreground window and detect when it gets deactivated or destroyed. When it does that, attach to the next foreground window
    • When attaching observers, we poll for 5 seconds since the observers seem to take a while to take effect

Side changes

Testing

Tested by:

  1. Run yarn demo:electron
  2. Open an empty, untitled TextEdit window. If you need to change the sample window, edit attachByTitle in the electron-demo file to attach to a window with a different title

Tested

Resizing, focusing

Testing

Fullscreen

https://user-images.githubusercontent.com/2937410/119969235-29ddc780-bf63-11eb-90d0-d80e57dbf5c5.mp4

hsource commented 1 year ago

@SnosMe - would it be possible to just merge this in? That would save me the tedious work of having to rebase once in a while. You don't have to address the Mac bugs and can just @ me for them and I can take a look.

hsource commented 1 year ago

Here's a new recording of the latest test - note that it actually works on fullscreen too, but my screen recorder (liceCAP) is broken with it.

Retesting MacOS