apache / cordova-electron

Apache Cordova Electron
Apache License 2.0
126 stars 58 forks source link

Documentation - plugins #2

Open bishal1994 opened 6 years ago

bishal1994 commented 6 years ago

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.

janpio commented 6 years ago

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?

mavericksthinker commented 6 years ago

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)?

janpio commented 6 years ago

@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?

bishal1994 commented 6 years ago

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 <notifications@github.com 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 .

janpio commented 6 years ago

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.

bishal1994 commented 6 years ago

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 <notifications@github.com 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 .

janpio commented 6 years ago

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

bishal1994 commented 6 years ago

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 <notifications@github.com 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 .

shazron commented 6 years ago

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

janpio commented 6 years ago

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

bishal1994 commented 6 years ago

Thank you hope to get it soon.

On Mon, Dec 3, 2018, 4:55 PM Jan Piotrowski <notifications@github.com 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 .

purplecabbage commented 6 years ago

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.

mghayour commented 5 years ago

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 ?

tk505 commented 4 years ago

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?

timbru31 commented 4 years ago

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!

tk505 commented 4 years ago

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.

brodycj commented 4 years ago

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.

mzielezny commented 4 years ago

@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.

tk505 commented 4 years ago

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

tk505 commented 4 years ago

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

mzielezny commented 4 years ago

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

t-knapp commented 4 years ago

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

Jahrenski commented 3 years ago

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.

mzielezny commented 3 years ago

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).

Jahrenski commented 3 years ago

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 commented 3 years ago

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.