fixQRScanner.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const fs = require("fs");
  2. const path = require("path");
  3. const https = require("https");
  4. module.exports = function (context) {
  5. if (
  6. context.opts.plugin &&
  7. context.opts.plugin.id === "cordova-plugin-qrscanner"
  8. ) {
  9. const projectRoot = context.opts.projectRoot;
  10. const cordovaCommon = context.requireCordovaModule("cordova-common");
  11. const { ConfigParser } = cordovaCommon;
  12. const appConfig = new ConfigParser(
  13. path.resolve(projectRoot, "config.xml")
  14. );
  15. let projectName = appConfig.name();
  16. const file = path.resolve(
  17. projectRoot,
  18. "platforms",
  19. "android",
  20. "app",
  21. "src",
  22. "main",
  23. "java",
  24. "com",
  25. "bitpay",
  26. "cordova",
  27. "qrscanner",
  28. "QRScanner.java"
  29. );
  30. if (fs.existsSync(file)) {
  31. fs.writeFileSync(
  32. file,
  33. fs
  34. .readFileSync(file)
  35. .toString()
  36. .replaceAll(
  37. "android.support.v4.app.ActivityCompat",
  38. "androidx.core.app.ActivityCompat"
  39. )
  40. );
  41. }
  42. }
  43. };