Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research for Launching Neuron from DApp #153

Open
Tracked by #176
IronLu233 opened this issue May 19, 2023 · 0 comments
Open
Tracked by #176

Research for Launching Neuron from DApp #153

IronLu233 opened this issue May 19, 2023 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation feature

Comments

@IronLu233
Copy link

IronLu233 commented May 19, 2023

TL;DR

Deep can launch user local Neuron wallet without it already started. If Neuron not run on the user's PC, it will launch it first and receive the wallet connect URL.

The implement of deep link

There are two necessary steps, register and listen.

Register deep link

On the Neuron, we should invoke these code when its main process start.

      if (process.argv.length >= 2) {
        app.setAsDefaultProtocolClient('neuron', process.execPath, [path.resolve(process.argv[1])])
      } else {
        app.setAsDefaultProtocolClient('neuron')
      }

The method setAsDefaultProtocolClient sets the current executable as the default handler for a protocol (aka URI scheme).

Extra works on MacOS and Linux

On MacOS, all registered URL scheme should be declared beforehand in MacOS Info.plist.
Meanwhile, on Linux, the linux desktop file for the app should include new protocol handler.

By using electron-builder, These build config options should be added.

protocols:
  name: 'Neuron'
  # Don't forget to set `MimeType: "x-scheme-handler/deeplink"` for `linux.desktop` entry!
  schemes: ['neuron']
# other config
linux:
  desktop:
    MimeType: "x-scheme-handler/deeplink"

response deep link

Previous step allows DApp to wake neuron and send the Wallet Connect URL, this step is for handling it.

function responseDeepLink(event: Electron.Event, url: string) {
    console.log(url)

}

app.on('open-url', responseDeepLink)

if (process.os === 'win32') {
  const gotTheLock = app.requestSingleInstanceLock()
  if (!gotTheLock) {
    app.quit()
  } else {
    app.on('second-instance', (event, commandLine, workingDirectory) => {
      // Someone tried to run a second instance, we should focus our window.
      if (mainWindow) {
        if (mainWindow.isMinimized()) mainWindow.restore()
        mainWindow.focus()
      }
      // the commandLine is array of strings in which last element is deep link url
      // the url str ends with /
       responseDeeplink(event, commandLine.pop().slice(0, -1)!)
    })
  }
}

On DApp

On the Dapp, just use a html <a> label, or use window.open can pass the wallet connect url to Neuron.

<a href={`neuron://connect?url=${url}`}>Connect</a>
window.open(`neuron://connect?url=${url}`)

Known bug

On Windows platfrom, process.defaultApp will return undefined when application is packed. In electron official document, it has a if clause before call app.setDefaultProtocolClient.

if (process.defaultApp) {
  if (process.argv.length >= 2) {
    app.setAsDefaultProtocolClient('electron-fiddle', process.execPath, [path.resolve(process.argv[1])])
  }
} else {
  app.setAsDefaultProtocolClient('electron-fiddle')
}
@Keith-CY Keith-CY added this to Neuron May 23, 2023
@Keith-CY Keith-CY moved this to 🆕 New in Neuron May 23, 2023
@Danie0918 Danie0918 moved this from 🆕 New to 🏗 In Progress in Neuron May 29, 2023
@Danie0918 Danie0918 moved this from 🏗 In Progress to 🆕 New in Neuron May 29, 2023
@Danie0918 Danie0918 added the documentation Improvements or additions to documentation label May 29, 2023
@Keith-CY Keith-CY moved this from 🆕 New to 🏗 In Progress in Neuron Jun 14, 2023
@Danie0918 Danie0918 moved this from 🏗 In Progress to ✅ Done in Neuron Jun 26, 2023
@Danie0918 Danie0918 moved this from ✅ Done to 📋 Backlog in Neuron Jun 26, 2023
@Danie0918 Danie0918 moved this from 📋 Backlog to 📫Hold On in Neuron Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature
Projects
Status: 📫Hold On
Development

No branches or pull requests

5 participants