const fs = require("fs"); const path = require("path"); const https = require("https"); module.exports = function (context) { if ( context.opts.plugin && context.opts.plugin.id === "cordova-plugin-android-notch" ) { const projectRoot = context.opts.projectRoot; const cordovaCommon = context.requireCordovaModule("cordova-common"); const { ConfigParser } = cordovaCommon; const appConfig = new ConfigParser( path.resolve(projectRoot, "config.xml") ); let projectName = appConfig.name(); const file = path.resolve( projectRoot, "platforms", "android", "app", "src", "main", "java", "com", "tobspr", "androidnotch", "AndroidNotch.java" ); if (fs.existsSync(file)) { fs.writeFileSync( file, fs .readFileSync(file) .toString() .replaceAll( "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetLeft() / density) : 0));", "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetLeft() / density) : (insets.getStableInsetLeft() / density)));" ) .replaceAll( "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetRight() / density) : 0));", "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetRight() / density) : (insets.getStableInsetRight() / density)));" ) .replaceAll( "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetTop() / density) : 0));", "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetTop() / density) : (insets.getStableInsetTop() / density)));" ) .replaceAll( "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetBottom() / density) : 0));", "callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, cutout != null ? (cutout.getSafeInsetBottom() / density) : (insets.getStableInsetBottom() / density)));" ) ); } } };