Skip to content

Commit

Permalink
Merge pull request #932 from shankari/upgrade_2023
Browse files Browse the repository at this point in the history
Revert the QR code plugin to the one that we used before
  • Loading branch information
shankari authored Mar 17, 2023
2 parents 84e61ca + d318f8f commit a8aba80
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
6 changes: 5 additions & 1 deletion config.cordovabuild.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="50" id="edu.berkeley.eecs.emission" ios-CFBundleVersion="48" version="3.2.7" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget android-versionCode="51" id="edu.berkeley.eecs.emission" ios-CFBundleVersion="49" version="3.2.8" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>emission</name>
<description>
A commute pattern tracker and carbon footprint estimator.
Expand Down Expand Up @@ -42,6 +42,9 @@
<preference name="WKWebViewOnly" value="true" />
<preference name="WKSuspendInBackground" value="false" />
<preference name="AutoHideSplashScreen" value="true" />
<config-file parent="NSCameraUsageDescription" target="*-Info.plist" mode="merge">
<string>To scan QR codes for the login token and the study</string>
</config-file>
</platform>
<platform name="android">
<hook src="hooks/before_build/android/android_copy_locales.js" type="before_build" />
Expand All @@ -53,6 +56,7 @@
<preference name="GradlePluginKotlinVersion" value="1.7.10" />
<resource-file src="google-services.json" target="app/google-services.json" />
<hook src="hooks/before_build/android/android_set_provider.js" type="before_build" />
<hook src="hooks/before_build/android/android_change_compile_implementation.js" type="before_build" />
<config-file parent="/manifest/application" target="AndroidManifest.xml">
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</config-file>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* A hook to change provider in order to match with the application name.
*/

var fs = require('fs');
var path = require('path');
var et = require('elementtree');

const LOG_NAME = "Changing compile to implementation ";

var changeCompileToImplementation = function (file) {
if (fs.existsSync(file)) {
fs.readFile(file, 'utf8', function (err, data) {
var result = data.replace("compile", "implementation");
fs.writeFile(file, result, 'utf8', function (err) {
if (err) throw new Error(LOG_NAME + 'Unable to write into ' + file + ': ' + err);
console.log(LOG_NAME + "" + file + " updated...")
});
});
} else {
console.error("Could not find file "+file+" skipping compile -> implementation change");
}
}

module.exports = function (context) {
// If Android platform is not installed, don't even execute
if (!context.opts.platforms.includes('android')) return;

var config_xml = path.join(context.opts.projectRoot, 'config.xml');
var data = fs.readFileSync(config_xml).toString();
// If no data then no config.xml
if (data) {
var etree = et.parse(data);
console.log(LOG_NAME + "Retrieving application name...")
var applicationName = etree._root.attrib.id;
console.info(LOG_NAME + "Your application is " + applicationName);
const splitParts = applicationName.split(".")
var lastApplicationPart = splitParts[splitParts.length - 1];

var platformRoot = path.join(context.opts.projectRoot, 'platforms/android/')

console.log(LOG_NAME + "Updating barcode scanner gradle...");
var gradleFile = path.join(platformRoot, 'phonegap-plugin-barcodescanner/'+lastApplicationPart+'-barcodescanner.gradle');
changeCompileToImplementation(gradleFile);
} else {
throw new Error(LOG_NAME + "Could not retrieve application name.");
}
}
8 changes: 5 additions & 3 deletions package.cordovabuild.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edu.berkeley.eecs.emission",
"version": "3.2.7",
"version": "3.2.8",
"displayName": "emission",
"license": "BSD-3-Clause",
"repository": {
Expand Down Expand Up @@ -60,7 +60,9 @@
"cordova-plugin-em-unifiedlogger": {},
"cordova-plugin-em-usercache": {},
"cordova-plugin-androidx-adapter": {},
"cordova-plugin-barcode-qrscanner": {}
"phonegap-plugin-barcodescanner": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
}
}
},
"dependencies": {
Expand All @@ -87,7 +89,7 @@
"cordova-plugin-x-socialsharing": "6.0.4",
"fs-extra": "^9.0.1",
"klaw-sync": "^6.0.0",
"cordova-plugin-barcode-qrscanner": "^3.0.12",
"phonegap-plugin-barcodescanner": "git+https://github.com/phonegap/phonegap-plugin-barcodescanner#v8.1.0",
"@havesource/cordova-plugin-push": "git+https://github.com/havesource/cordova-plugin-push.git#4.0.0-dev.0"
}
}

0 comments on commit a8aba80

Please sign in to comment.