capacitor-community / electron

Deploy your Capacitor apps to Linux, Mac, and Windows desktops, with the Electron platform! 🖥️
https://capacitor-community.github.io/electron/
MIT License
318 stars 58 forks source link

Capacitor App Plugin - Events not firing - appUrlOpen / getLaunchUrl() #194

Open polisettyManoj opened 2 years ago

polisettyManoj commented 2 years ago

I'm using the capacitor App plugin and trying to get URL from which the app is opened (I need to handle deep link)

npm install @capacitor/app npx cap sync

App.addListener('appUrlOpen', data => { console.log('App opened with URL:', data); // not triggerring });

const checkAppLaunchUrl = async () => { const { url } = await App.getLaunchUrl();

console.log('App opened with URL: ' + url); // url always empty };

appUrlOpen event needs to fire and getLaunchUrl need to give deeplink Url

**Desktop - Windows

@IT-MikeS I appreciate your quick response

IT-MikeS commented 2 years ago

Have you followed the guide in the docs.

https://capacitor-community.github.io/electron/docs/deeplinking

polisettyManoj commented 2 years ago

@IT-MikeS yes followed.

polisettyManoj commented 2 years ago

@IT-MikeS I created a sample application by following these steps

  1. ionic start appElectron blank --type=angular --capacitor
  2. npm i @capacitor-community/electron
  3. ionic build
  4. npx cap add @capacitor-community/electron

after that added capacitor/app plugin and followed the steps given in this document - https://capacitor-community.github.io/electron/docs/deeplinking

npm install @capacitor/app npx cap sync

App.addListener('appUrlOpen', data => { console.log('App opened with URL:', data); // not triggerring });

const checkAppLaunchUrl = async () => { const { url } = await App.getLaunchUrl();

console.log('App opened with URL: ' + url); // url always empty };

IT-MikeS commented 2 years ago

@IT-MikeS I created a sample application by following these steps

  1. ionic start appElectron blank --type=angular --capacitor
  2. npm i @capacitor-community/electron
  3. ionic build
  4. npx cap add @capacitor-community/electron

after that added capacitor/app plugin and followed the steps given in this document - https://capacitor-community.github.io/electron/docs/deeplinking

npm install @capacitor/app npx cap sync

Did you cap sync with the electron command? (npx cap sync @capacitor-community/electron)

polisettyManoj commented 2 years ago

@IT-MikeS yes (npx cap sync @capacitor-community/electron) this is also done

polisettyManoj commented 2 years ago

@IT-MikeS Can you please help me? as I was struck at this point for the past several days

IT-MikeS commented 2 years ago

Have you built this into an installable application? (gone though electron builder etc) and installed and tested as a built app? Deeplinking is only available to built applications. (Electron limitation)

polisettyManoj commented 2 years ago

@IT-MikeS I'm using "electron:build-windows": "npm run build && electron-builder build --windows --publish=never" command to build the application and tested. getLaunchURL is still empty

polisettyManoj commented 2 years ago

I'm using the capacitor App plugin and trying to get URL from which the app is opened (I need to handle deep link)

npm install @capacitor/app npx cap sync

App.addListener('appUrlOpen', data => { console.log('App opened with URL:', data); // not triggerring });

const checkAppLaunchUrl = async () => { const { url } = await App.getLaunchUrl();

console.log('App opened with URL: ' + url); // url always empty };

appUrlOpen event needs to fire and getLaunchUrl need to give deeplink Url

**Desktop - Windows

@IT-MikeS I appreciate your quick response

@IT-MikeS if possible you can create a sample project by following these steps, it won't take much time. can you test it in your Machine ?

polisettyManoj commented 2 years ago

@IT-MikeS I went through capacitor/app V3 plugin code (https://github.com/ionic-team/capacitor-plugins/blob/main/app/src/web.ts) they didn't implement several methods for the web. getLaunchUrl is simply returning an empty string.

image

polisettyManoj commented 2 years ago

@IT-MikeS any update on this? are you looking into this issue ?

IT-MikeS commented 2 years ago

It's on my radar but it will be a while before I dig in due to other commitments and life balance. However PRs are always welcome should you feel inclined to investigate and fix the issue in your own time.

polisettyManoj commented 2 years ago

@IT-MikeS I tried but was unable to fix it. can you fix it in your own time? or guide me to fix the issue.

--> I need to change capacitor/app plugin code ?

IT-MikeS commented 2 years ago

All the work I do on this repo is in my own time, that's open source for you 😝

Unfortunately as I do not have the time to dig into the issue at the moment I can not provide good guidance nor fix the issue without impact on my life balance.

Please be patient and understanding. The issue will get looked into in time but no guarantees are given. You may also try the Ionic discord in the capacitor community channel if anyone else may be able to assist you quicker.

polisettyManoj commented 2 years ago

Okay @IT-MikeS :)

polisettyManoj commented 1 year ago

@mlynch @danielsogl @vevedh @leMaik @stewones @coreyjv @jgoux @MathisTLD @challenger71498 @jdgjsag67251 can anyone help on this ?

jdgjsag67251 commented 1 year ago

AFAIK there are no official Capacitor plugins that support Electron. Unfortunately, running npm install @capacitor/app will do nothing in Electron. I have made two pull-requests to the plugins to add some functionality (https://github.com/ionic-team/capacitor-plugins/pull/792 & https://github.com/ionic-team/capacitor-plugins/pull/793), but neither of them have seen any action.

polisettyManoj commented 1 year ago

@jdgjsag67251 how to achieve this? any guidance?

JuliusSkrisa commented 1 year ago

@polisettyManoj if the app "App.addListener('appUrlOpen'...." doesnt work for you. you can expose function from main process that will return the url.

In preload.ts expose the function ipcRenderer.on (not secure) or create channel between main and renderer process to pass the URL information. (thats basically what electron capacitor platform is doing, but for some reason it didnt work for me either with App.addListener) In main process you can get it by calling ipcRenderer.on('appUrlOpen', (url) => { })

you can read this to understand how to create a channel https://www.debugandrelease.com/the-ultimate-electron-guide/

polisettyManoj commented 1 year ago

I will try @JuliusSkrisa. Thank you very much