Capacitor plugin, missing something?

I hope they don’t remove it soon since we depend on it with our App Connect plugins.

The capacitor.js file is being generated by Capacitor when you build the app and you have the bundledWebRuntime options set.


The way we implemented the plugins is as follows (it depends on the config bundledWebRuntime being set to true).

Install the plugin using

npm install @capacitor/network

Copy the file node_modules/@capacitor/network/dist/plugin.js into your www folder. I copied mine to www/plugins/network/plugin.js.

In your html make sure both js files are included:

<script src="capacitor.js"></script>
<script src="plugins/network/plugin.js"></script>

You can access the plugin api from Capacitor.Plugins.Network.

I’ve added following script to my page to set the status to a global App Connect variable:

<script type="module">
  dmx.global.set('networkStatus', await Capacitor.Plugins.Network.getStatus());
</script>

I use type module to allow use of await, with a normal script block you can use:

<script>
  Capacitor.Plugins.Network.getStatus().then(status => {
    dmx.global.set('networkStatus', status);
  });
</script>

In the page I can use {{networkStatus.connectionType}} and {{networkStatus.connected}}.

We currently highly rely on the bundledWebRuntime to not need a bundler to build the app.

2 Likes