cordova-electron icon indicating copy to clipboard operation
cordova-electron copied to clipboard

Documentation - plugins

Open bishal1994 opened this issue 6 years ago • 26 comments

I have created a cordova plugin that works on cordova android and for electron I have a nodejs file that performs the same task as the plugin of cordova but for Desktop app . Is there a way to wrap the cordova plugin api and the node js file in electron and we can load the plugin based on the type ( ie if its cordova the cordova plugin api will be loaded and if it is electron the nodejs will be loaded)? The search got me here but I cant find any documentation about the usage. Any help will be appreciated. Thank you in advance.

bishal1994 avatar Nov 06 '18 06:11 bishal1994

This repository contains a Cordova platform that has an Electron app as the output of the build process vs. a fully native app (that contains the web app). I don't think this helps with your problem at all, or did I misunderstand?

janpio avatar Nov 15 '18 10:11 janpio

Well this can be used in a way to solve my problem. Will it be able to use Cordova plugin( which I use for Cordova electron now Cordova-print-plugin)?

mavericksthinker avatar Nov 15 '18 11:11 mavericksthinker

@mavericksthinker = @bishal1994?

Will it be able to use Cordova plugin( which I use for Cordova electron now Cordova-print-plugin)?

What do you refer to by it? If you mean a project created with Cordova that uses the cordova-electron platform, then it depends if the plugin implements bindings for the cordova-electron platform. I am also not sure if the plugin system is implemented here - see the commit history for some context how barebones this thing is currently.

@purplecabbage? Time to provide some context here and/or in the README maybe?

janpio avatar Nov 15 '18 11:11 janpio

Yes sorry , you got it right that's what I meant . I will go through the commit history too . But a readme with some description will be very helpful not just for me but for others to use it too as I saw Cordova-Electron was recommended for same aim that I want to achieve. Thank you for your attention . Hope this repo can be managed and we'll documented to benefit everyone.

On Thu, Nov 15, 2018, 6:44 PM Jan Piotrowski <[email protected] wrote:

@mavericksthinker https://github.com/mavericksthinker = @bishal1994 https://github.com/bishal1994?

Will it be able to use Cordova plugin( which I use for Cordova electron now Cordova-print-plugin)?

What do you refer to by it? If you mean a project created with Cordova that uses the cordova-electron platform, then it depends if the plugin implements bindings for the cordova-electron platform. I am also not sure if the plugin system is implemented here - see the commit history for some context how barebones this thing is currently.

@purplecabbage https://github.com/purplecabbage? Time to provide some context here and/or in the README maybe?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-electron/issues/2#issuecomment-439012901, or mute the thread https://github.com/notifications/unsubscribe-auth/AqM6Juv5vWPbrfNGv57_lEhJiisZnYtnks5uvVOVgaJpZM4YP0_5 .

bishal1994 avatar Nov 15 '18 14:11 bishal1994

No documentation needed here to figure out if your plugin works with cordova-electron: Does it say so in the documentation? Does it have an www/electron folder? If both is false, then it will definitely not work.

janpio avatar Nov 15 '18 14:11 janpio

As you mentioned this will provide an electron app as output right? Does the Cordova platform that gives electron app as output utilizes nodeJs if yes? There must be possibilities to make plugin for the same platform(electron app) as we do for Android and iOS .... in Cordova. That's what I want to utilize.

On Thu, Nov 15, 2018, 9:53 PM Jan Piotrowski <[email protected] wrote:

No documentation needed here to figure out if your plugin works with cordova-electron: Does it say so in the documentation? Does it have an www/electron folder? If both is false, then it will definitely not work.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-electron/issues/2#issuecomment-439067166, or mute the thread https://github.com/notifications/unsubscribe-auth/AqM6Jvjy5efKWJdjurDvZ98c03N4yR_hks5uvX__gaJpZM4YP0_5 .

bishal1994 avatar Nov 15 '18 15:11 bishal1994

That I can't tell you, sorry - no idea.

janpio avatar Nov 15 '18 15:11 janpio

Well that's the reason for asking documentation. Atleast the developers can let us know what they have done .

On Thu, Nov 15, 2018, 10:08 PM Jan Piotrowski <[email protected] wrote:

That I can't tell you, sorry - no idea.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-electron/issues/2#issuecomment-439072513, or mute the thread https://github.com/notifications/unsubscribe-auth/AqM6JkVzfH8t_UQ4LhlITdDGqny8E65wks5uvYNugaJpZM4YP0_5 .

bishal1994 avatar Nov 15 '18 15:11 bishal1994

The developer that did this as an experiment is no longer on the project. From what I know, this will not support native plugins, and may or may not work with current Cordova tooling. YMMV

shazron avatar Dec 03 '18 06:12 shazron

(A improved implementation is in the works, I heard. No ETA though, but watch this space)

janpio avatar Dec 03 '18 09:12 janpio

Thank you hope to get it soon.

On Mon, Dec 3, 2018, 4:55 PM Jan Piotrowski <[email protected] wrote:

(A improved implementation is in the works, I heard. No ETA though, but watch this space)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-electron/issues/2#issuecomment-443651573, or mute the thread https://github.com/notifications/unsubscribe-auth/AqM6JqZmT9V8kvx8N011rJZ5CNEWUck8ks5u1PT3gaJpZM4YP0_5 .

bishal1994 avatar Dec 03 '18 11:12 bishal1994

This will be able to support cordova plugins, and yes it can access nodejs methods/libraries just like any other electron app. The full definition of how plugins are defined for cordova-electron is pending, I'll try to get to it this week.

purplecabbage avatar Dec 03 '18 18:12 purplecabbage

i have same problem too, we want to make a new cordova, electron plugin, but i dont know how can we start and what should we do for that ! in readme file we have only this paragraph

When adding a plugin, if the plugin supports both the electron and browser platform, the electron portion will be used. If the plugin misses electron but contains the browser implementation, it will fall back on the browser implementation.

but, how we can write a plugin with electron support ?

mghayour avatar Aug 01 '19 14:08 mghayour

Now that Electron platform has been officially released, is there any more documentation on plugins that support electron (not browser)?

Or anyone know of an example cordova-plugin that is supporting electron platform out there?

tk505 avatar Mar 27 '20 14:03 tk505

We have documentation here: https://cordova.apache.org/docs/en/latest/guide/platforms/electron/index.html - if it's outdated or missing something: we really appreciate PRs!

timbru31 avatar Mar 27 '20 14:03 timbru31

Hey @timbru31 , on the subject on plugins the platform documentation page essentially states "we support electron plugins" without any further information on how to create one.

Over on the plugin section of the documentation https://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html, there are handy guides for each platform including plugin.xml requirements for the platform and example class mappings and lifecycle information on writing plugins for that platform. Electron is sadly missing from here.

I'd love to submit a PR! However before I can do that I actually need to know how to create a plugin for electron, which is why I'm searching here, the issue request for plugin documentation (and many other placings), for any clues on how to do that.

If you know of any existing plugins that support electron (not browser) that you could link me to (even developer test ones), then I could hopefully figure it out backwards from there.

Any help is much appreciated.

tk505 avatar Mar 27 '20 14:03 tk505

I just updated the title. From f3de449afc2b93094100a4c4bccfaf0ef05766a6 I can see that if a plugin works on the browser platform, it will also work on Electron.

I think this should be documented better. I hope we can do this as part of the sponsored documentation project discussed in https://github.com/apache/cordova-docs/issues/1057.

brodycj avatar Mar 27 '20 15:03 brodycj

@tk505 I have made a try to extend cordova-plugin-chrome-apps-sockets-udp (https://github.com/mzielezny/cordova-plugin-chrome-apps-sockets-udp) and for my usecase with electron it is working (WIP because I made only that part which let me to create broadcast over udp and receive response). In my code I use node dgram native module. The most important part of using electron is to remember to activate node support and than in plugin use global.require rather than require (which is overriden). Maybe by analogies you would be able to create your own plugin.

mzielezny avatar Apr 02 '20 18:04 mzielezny

thanks @mzielezny ! I'll have a look at it.

tk505 avatar Apr 07 '20 11:04 tk505

Many thanks to @mzielezny, your project gave me the hints I needed to get going, most notably the syntax to use in the plugin.xml for electron. great stuff

tk505 avatar May 04 '20 08:05 tk505

If anyone need I have also tried to prepare [WiP] SQLLite version of plugin - far from production but I'm using third party node module (not build as dgram) and it is working with simple cases (insert, update) https://github.com/mzielezny/cordova-sqlite-storage

mzielezny avatar May 04 '20 12:05 mzielezny

Regarding Windows Platform

Is it possible to control electrons internals like we can do on android with accessing the webView? There is a plug-in for updating the apps www content at runtime. - I know, it has a deprecation warning, but it works well - https://github.com/nordnet/cordova-hot-code-push

The idea is to adopt the behaviour to the electron platform. So one has to change the location in plug-in code like they do here: https://github.com/nordnet/cordova-hot-code-push/blob/master/src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java#L129

Related question to this is, is it possible to write to the apps www folder? Updates provided by CHCP would be downloaded there.

Thanks

t-knapp avatar Jul 16 '20 09:07 t-knapp

I've found on the web a way to run native C++ into a pure electron app from here : https://gauriatiq.medium.com/electron-app-with-c-back-end-as-native-addon-napi-c67867f4058

Do you guys think it could be possible to leverage this to run from a plugin inside of cordova-electron somehow? It compiles C++ into a .node file that is run from a nodejs server from within electron. If this would be possible from a plugin's perspective, we will be able to ditch the dying cordova-windows and port most if not all native plugins.

Jahrenski avatar Feb 10 '21 13:02 Jahrenski

Native node modules have to be recompiled for electron. In my sql-lite fork I'm recompiling sqllite3 module and than use it in Cordova Electron project - so I think it would be possible to work. The best way would be to try prepare a hello world with C++ native module. For now I haven't noticed any sandboxing or special limitations ( currently I'm using from node that SQL, net library ans fs).

mzielezny avatar Feb 10 '21 15:02 mzielezny

Thanks for the reply, this gives me hope. I'm working on this at the moment and will let you know how it goes.

Jahrenski avatar Feb 10 '21 15:02 Jahrenski

Alright, so I managed to use compiled native C++ to run from nodejs in the context of a cordova-electron plugin! Thanks to @mzielezny I found that my missing piece was to use globa.require instead of straight up require.

I made a starter repo demonstrating how it works. https://github.com/Jahrenski/test-cordova-electron.git

I'll now attempt to automate the process using source C++ files directly and also try to make this run on android/iOS.

Jahrenski avatar Feb 11 '21 15:02 Jahrenski