asticode/go-astilectron

How can I set content protection on window with go-astilelectron ?

vocuzi opened this issue · 3 comments

How to set content protection flag with go-astilelectron ? This prevents the window contents from being captured by other apps.

Ref : https://www.electronjs.org/docs/api/browser-window#winsetcontentprotectionenable-macos-windows

This is not available for now. I won't have time to work on that anytime that, are you interested in submitting a PR ? I can guide you through it

Sure, I am interested

Great, here's what you'll need to do in GO:

  1. Add an Enable *bool field here (order it alphabetically)
  2. Add an EventNameWindowCmdSetContentProtection = "window.cmd.set.content.protection" and EventNameWindowEventContentProtectionSet = "window.event.content.protection.set" here (order it alphabetically)
  3. Add a func (w *Window) SetContentProtection(enable bool) in this file with the same logic as this function, but instead of EventNameWindowCmdMinimize put EventNameWindowCmdSetContentProtection, and instead of EventNameWindowEventMinimize put EventNameWindowEventContentProtectionSet. Also, in the Event struct, set the new field Enable to astikit.BoolPtr(enable)

And here's what you'll need to do in JS:

  1. Add the same event names you added in GO here
  2. here add a case for consts.eventNames.windowCmdSetContentProtection which will do elements[json.targetID].setContentProtection(json.enable ? json.enable : false) and client.write(json.targetID, consts.eventNames.windowEventContentProtectionSet)