Capacitor / Cordova EmmAppConfig plugin with Javascript

Viewed 54

I'm trying to get the following working based on this post "Building a CapacitorJS application using pure JavaScript and Webpack" on Medium.com (https://medium.com/@SmileFX/a-complete-guide-building-a-capacitorjs-application-using-pure-javascript-and-webpack-37d00f11720d)

My intention is to build an Android app that will get deployed from an MDM server with an AppConfig configuration. When launched, the app will generate a file (derived from the AppConfig configuration) and save the file to the file system on the device.

Here is the content of my index.js

import '@capacitor/core';
import '@angular/core';
import '@ionic-native/core';
import 'rxjs';

import { Device } from '@capacitor/device';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
//import { EmmAppConfig } from '@ionic-native/emm-app-config/ngx';

async function getDeviceInfo() {
    message("getDeviceInfo started");
    let info = await Device.getInfo();
    return info.operatingSystem;
}

async function getEmmAppConfig() {
    message("getEmmAppConfig started");
    //let eac = await EmmAppConfig.getValue("z_number");
    let eac = "Z_1234_567";
    return eac;
};

async function putFile(name, data) {
    message("putFile started with name: " +name+ " and data: " +data);

    let file = await Filesystem.writeFile({
        path: "file:///storage/emulated/0/z_number/" +name+ ".txt",
        data: data,
        recursive: true,
        encoding: Encoding.UTF8
    });
    return file;
};

window.onload = start;

function start() {

    message("app started");

    getDeviceInfo().then(info => {
        putFile("info", info).then(file => {
            message("File saved here: " +JSON.stringify(file, null, 4));
        });
    });

    getEmmAppConfig().then(eac => {
        putFile("eac", eac).then(file => {
            message("File saved here: " +JSON.stringify(file, null, 4));
        });
    });
}

function message(message) {
    document.body.innerHTML = document.body.innerHTML+ "<p>" +message+ "</p>" ;
}

The above code does run on the Android emulator and saves bothe files as expected only when "import { EmmAppConfig } from '@ionic-native/emm-app-config/ngx';" is commented out, otherwise it does not run (not even to output "App Started")

this is the content of my package.json

{
  "name": "capacitor-app",
  "version": "1.0.0",
  "description": "An Amazing Capacitor App",
  "main": "index.js",
  "keywords": [
    "capacitor",
    "mobile"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@angular/core": "^13.0.3",
    "@capacitor/android": "^3.3.2",
    "@capacitor/camera": "latest",
    "@capacitor/core": "latest",
    "@capacitor/device": "^1.1.0",
    "@capacitor/filesystem": "^1.0.6",
    "@capacitor/splash-screen": "latest",
    "@ionic-native/core": "^5.36.0",
    "@ionic-native/emm-app-config": "^5.36.0",
    "cordova-plugin-emm-app-config": "^1.0.2",
    "rxjs": "^7.4.0"
  },
  "devDependencies": {
    "@capacitor/cli": "latest",
    "webpack-cli": "^4.9.1"
  },
  "author": "",
  "license": "ISC"
}

What am i missing?

0 Answers
Related