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

Documentation - plugins #2

Open
bishal1994 opened this issue Nov 6, 2018 · 26 comments
Open

Documentation - plugins #2

bishal1994 opened this issue Nov 6, 2018 · 26 comments
Labels

Comments

@bishal1994
Copy link

bishal1994 commented Nov 6, 2018

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 bishal1994 changed the title How to use ? Documentation Nov 6, 2018
@janpio janpio added the support label Nov 6, 2018
@janpio
Copy link
Member

janpio commented Nov 15, 2018

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
Copy link

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
Copy link
Member

janpio commented Nov 15, 2018

@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
Copy link
Author

bishal1994 commented Nov 15, 2018 via email

@janpio
Copy link
Member

janpio commented Nov 15, 2018

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
Copy link
Author

bishal1994 commented Nov 15, 2018 via email

@janpio
Copy link
Member

janpio commented Nov 15, 2018

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

@bishal1994
Copy link
Author

bishal1994 commented Nov 15, 2018 via email

@shazron
Copy link
Member

shazron commented Dec 3, 2018

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
Copy link
Member

janpio commented Dec 3, 2018

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

@bishal1994
Copy link
Author

bishal1994 commented Dec 3, 2018 via email

@purplecabbage
Copy link
Contributor

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.

erisu pushed a commit that referenced this issue Dec 5, 2018
* plugin's json name is unified to use browser settings in plugin.xml if there is no electron settings
@mghayour
Copy link

mghayour commented Aug 1, 2019

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
Copy link

tk505 commented Mar 27, 2020

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
Copy link
Member

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
Copy link

tk505 commented Mar 27, 2020

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 brodycj changed the title Documentation Documentation - plugins Mar 27, 2020
@brodycj
Copy link

brodycj commented Mar 27, 2020

I just updated the title. From f3de449 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 apache/cordova-docs#1057.

@mzielezny
Copy link

@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
Copy link

tk505 commented Apr 7, 2020

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

@tk505
Copy link

tk505 commented May 4, 2020

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
Copy link

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
Copy link

t-knapp commented Jul 16, 2020

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests