fixNotch.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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-android-notch"
  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. "tobspr",
  26. "androidnotch",
  27. "AndroidNotch.java"
  28. );
  29. if (fs.existsSync(file)) {
  30. fs.writeFileSync(
  31. file,
  32. fs
  33. .readFileSync(file)
  34. .toString()
  35. .replaceAll(
  36. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetLeft() / density) : 0));",
  37. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetLeft() / density) : (insets.getStableInsetLeft() / density)));"
  38. )
  39. .replaceAll(
  40. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetRight() / density) : 0));",
  41. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetRight() / density) : (insets.getStableInsetRight() / density)));"
  42. )
  43. .replaceAll(
  44. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetTop() / density) : 0));",
  45. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetTop() / density) : (insets.getStableInsetTop() / density)));"
  46. )
  47. .replaceAll(
  48. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetBottom() / density) : 0));",
  49. "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetBottom() / density) : (insets.getStableInsetBottom() / density)));"
  50. )
  51. );
  52. }
  53. }
  54. };