astilectron icon indicating copy to clipboard operation
astilectron copied to clipboard

app.setAsDefaultProtocolClient(protocol[, path, args])

Open djcas9 opened this issue 3 years ago • 3 comments

Doc: https://www.electronjs.org/docs/latest/api/app#appsetasdefaultprotocolclientprotocol-path-args

How could I go about adding support for something like this?

djcas9 avatar May 07 '22 17:05 djcas9

You'll need to modify both go and JS projects.

Regarding the JS project, here's what you need to do:

  • add appCmdSetAsDefaultProtocolClient and appEventSetAsDefaultProtocolClient` here
  • add a case statement here listening for appCmdSetAsDefaultProtocolClient, execute app.setAsDefaultProtocolClient with the args provided in the json object, and return the boolean result of the function in a appEventSetAsDefaultProtocolClient event using a success json key

In the go project:

  • add the following attributes here:
    • Protocol string
    • Args []string
    • Success *bool
  • add appCmdSetAsDefaultProtocolClient and appEventSetAsDefaultProtocolClient here
  • add a (a *Astilectron) SetAsDefaultProtocolClient(protocol, path string, args []string) error method that will do this:
var e Event
if e, err = synchronousEvent(a.worker.Context(), a, a.writer, Event{Name: appCmdSetAsDefaultProtocolClient, Protocol: protocol, Path: path, Args: args}, appEventSetAsDefaultProtocolClient); err != nil {
  // TODO Process error the same way this package handle errors
  return
}

if !e.Success {
  //return an error as well
}

asticode avatar May 08 '22 08:05 asticode

Let me know if there is anything strange you would like changed, modified, etc.

zerotao avatar May 18 '22 20:05 zerotao

One aspect I am not sure fits the model you have built (and maybe there is a more general approach). Specifically capturing open-url in the way I did.

It feels like there should be a way to achieve the same thing from go-astilectron w/o needing to modify astilectron but I didn't see anything (or didn't look hard enough).

zerotao avatar May 18 '22 20:05 zerotao