electron-overlay-window icon indicating copy to clipboard operation
electron-overlay-window copied to clipboard

Added MacOS support

Open hsource opened this issue 3 years ago • 9 comments

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

  • Documented the general structure of the code a bit in DEVELOPING.md
  • Changed the example to work with TextEdit on Mac too and changed the keyboard shortcuts to not conflict with system shortcuts (Cmd + H on Mac is hide, Cmd + Q is quit app)

Testing

Tested by:

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

Tested

  • Getting permission
  • Blurring/focusing
  • Closing the app
  • Only opening the window after startup
  • Keyboard shortcuts

Resizing, focusing

Testing

Fullscreen

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

hsource avatar May 24 '21 09:05 hsource

I pushed a new version so that it handles renames properly like the other OS's, and added a call to refocus the target after we call .show() so that it doesn't take an extra click to focus the original app.

hsource avatar May 26 '21 06:05 hsource

Will review it soon, a little busy these weeks.

Not familiar with Mac API, can you explain why addChildWindow won't work here?

SnosMe avatar May 26 '21 10:05 SnosMe

Mac has a bit of a stricter permission model for windows - different applications don't have access to the NSWindow* for other applications. Because of that, we just have to make do with what the Accessibility API lets us do.

This Stackoverflow question has more: addChild my window to other application's window

hsource avatar May 26 '21 21:05 hsource

Depends on #20 , so that the behavior (always on top) is the same for all OS.

SnosMe avatar Oct 22 '21 07:10 SnosMe

Depends on #20 , so that the behavior (always on top) is the same for all OS.

Right on time! I just rebased on top of that branch and it looks like really minimal changes are needed.

hsource avatar Oct 22 '21 08:10 hsource

Tried to run https://github.com/hsource/electron-overlay-window/releases/tag/v3.0.0-macos.2 but no window appeared. Did allow iTerm.app to control computer.

❯ yarn demo:electron
yarn run v1.22.10
$ node-gyp build && yarn build-ts && electron dist/demo/electron-demo.js
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Nothing to be done for `all'.
gyp info ok
$ tsc
(node:26592) electron: The default of nativeWindowOpen is deprecated and will be changing from false to true in Electron 15.  See https://github.com/electron/electron/issues/28511 for more information.
(Use `Electron --trace-warnings ...` to show where the warning was created)
(node:26592) electron: The default of nativeWindowOpen is deprecated and will be changing from false to true in Electron 15.  See https://github.com/electron/electron/issues/28511 for more information.

How can I get this working?

paragbaxi avatar Dec 10 '21 03:12 paragbaxi

How can I get this working?

You just need to open a TextEdit window with an untitled document. It should automatically bind to that. I updated the instructions!

hsource avatar Dec 27 '21 10:12 hsource

Works!

paragbaxi avatar Jan 06 '22 04:01 paragbaxi

Hey! Will this ever be merged into master? Thanks!

kraj011 avatar Jul 21 '22 12:07 kraj011

any update?

jamninetyfive avatar Sep 22 '22 03:09 jamninetyfive