Skip to content

Commit a38508f

Browse files
authored
💎 Bump to version 8.6.4
1 parent 0824c6c commit a38508f

File tree

8 files changed

+253
-16
lines changed

8 files changed

+253
-16
lines changed

‎CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v8.6.4 (2019-09-06)
2+
3+
* Fixes missing imports in android.
4+
* Fixes floatingButtonEdge & floatingButtonOffset on android.
5+
* Adds script to automatically add our maven repo to the project level `build.gradle`
6+
17
## v8.6.3 (2019-09-05)
28

39
* Adds initializing android sdk from JS side using `cordova.plugins.instabug.activate`

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cordova.plugins.instabug.activate(
3636
```
3737
You can change the invocation event with any of the following: ```'button'```, ```'screenshot'```, ```'swipe'```, or ```'shake'```.
3838

39-
2. Make sure to add the following snippet to your project level `build.gradle`.
39+
2. Make sure the following snippet is added to your project level `build.gradle`, if not you can manually add it as follows:.
4040
```dart
4141
allprojects {
4242
repositories {

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "instabug-cordova",
3-
"version": "8.6.3",
3+
"version": "8.6.4",
44
"description": "The purpose of this plugin is to simplify the process of integrating the Instabug SDK in a hybrid application, as well as to provide an interface to interfacing with the SDK through JavaScript.",
55
"main": "index.js",
66
"repository": {

‎plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
<source-file src="src/android/IBGPlugin.java" target-dir="src/com/instabug/cordova/plugin"/>
9090
<!-- <source-file src="src/android/MyApplication.java" target-dir="src/com/instabug/cordova/plugin"/> -->
9191
<source-file src="src/android/util/Util.java" target-dir="src/com/instabug/cordova/plugin/util"/>
92-
<!-- <hook type="before_plugin_install" src="scripts/android/before_plugin_install.js"/>
93-
<hook type="before_plugin_uninstall" src="scripts/android/before_plugin_uninstall.js"/> -->
92+
<hook type="before_plugin_install" src="scripts/android/link_gradle.js"/>
93+
<hook type="before_plugin_uninstall" src="scripts/android/unlink_gradle.js"/>
9494
</platform>
9595

9696
<!-- ios -->

‎scripts/android/link_gradle.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
'use strict';
2+
var fs = require('fs');
3+
4+
const LOG_LEVEL_SUCCESS = 0;
5+
const LOG_LEVEL_WARN = 1;
6+
7+
const CHAR_OPEN_PARAN = '{';
8+
const CHAR_CLOSED_PARAN = '}';
9+
10+
const GRADLE_FILE_PATH = 'platforms/android/build.gradle';
11+
const MAVEN_REPO_URL =
12+
'https://sdks.instabug.com/nexus/repository/instabug-cp';
13+
14+
function getPosition(string, substring, occurrenceInString) {
15+
return string.split(substring, occurrenceInString).join(substring).length;
16+
}
17+
18+
function findRepositoriesBlockEnd(block) {
19+
let repositoriesStartBlockIndex = getPosition(block, CHAR_OPEN_PARAN, 2);
20+
let count = 1;
21+
let blockEndIndex = -1;
22+
for (let i = repositoriesStartBlockIndex + 1; i < block.length; i++) {
23+
if (block.charAt(i) === CHAR_OPEN_PARAN) {
24+
count++;
25+
}
26+
27+
if (block.charAt(i) === CHAR_CLOSED_PARAN) {
28+
count--;
29+
}
30+
31+
if (count === 0) {
32+
blockEndIndex = i;
33+
break;
34+
}
35+
}
36+
37+
return blockEndIndex;
38+
}
39+
40+
function readFile(filePath, success) {
41+
fs.readFile(filePath, 'utf-8', function(err, data) {
42+
if (err) {
43+
console.log(process.cwd());
44+
finish(
45+
LOG_LEVEL_WARN,
46+
`Linking process could not be completed because of\n${err.message}`
47+
);
48+
}
49+
success(data);
50+
});
51+
}
52+
53+
function writeFile(data) {
54+
fs.writeFile(GRADLE_FILE_PATH, data, err => {
55+
if (err) {
56+
finish(
57+
LOG_LEVEL_WARN,
58+
`Linking process could not be completed because of\n${err.message}`
59+
);
60+
}
61+
finish(LOG_LEVEL_SUCCESS, 'Linking process completed successfully');
62+
});
63+
}
64+
65+
function finish(logLevel, message) {
66+
if (logLevel === LOG_LEVEL_SUCCESS) {
67+
console.info(message);
68+
} else {
69+
console.warn(message);
70+
}
71+
// process.exit(0);
72+
}
73+
74+
function generateNewGradleFile(data) {
75+
76+
if (data.includes(MAVEN_REPO_URL)) {
77+
finish(LOG_LEVEL_SUCCESS, '');
78+
}
79+
80+
const regex = /allprojects\ *\n*\ *{/;
81+
if (!regex.test(data)) {
82+
finish(
83+
LOG_LEVEL_WARN,
84+
'Something went wrong while trying to complete the linking process. '
85+
);
86+
}
87+
88+
89+
const matchedRegex = data.match(regex);
90+
const block = data.substring(matchedRegex.index, data.length);
91+
const blockEndIndex = findRepositoriesBlockEnd(block);
92+
93+
if (blockEndIndex === -1) {
94+
finish(
95+
LOG_LEVEL_WARN,
96+
'Something went wrong while trying to complete the linking process. '
97+
);
98+
}
99+
100+
let updatedBlock = `${block.substring(0, blockEndIndex)}\tmaven {
101+
\t url "${MAVEN_REPO_URL}"
102+
\t}
103+
${block.substring(blockEndIndex, block.length)}`;
104+
const newGradleFile = `${data.substring(
105+
0,
106+
matchedRegex.index
107+
)}${updatedBlock}`;
108+
return newGradleFile;
109+
}
110+
111+
112+
readFile(GRADLE_FILE_PATH, function(data) {
113+
const newFile = generateNewGradleFile(data)
114+
writeFile(newFile);
115+
});

‎scripts/android/unlink_gradle.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'use strict';
2+
var fs = require('fs');
3+
4+
const LOG_LEVEL_SUCCESS = 0;
5+
const LOG_LEVEL_WARN = 1;
6+
7+
const CHAR_OPEN_PARAN = '{';
8+
const CHAR_CLOSED_PARAN = '}';
9+
10+
const GRADLE_FILE_PATH = 'platforms/android/build.gradle';
11+
const MAVEN_REPO_URL =
12+
'https://sdks.instabug.com/nexus/repository/instabug-cp';
13+
14+
function readFile(filePath, success) {
15+
fs.readFile(filePath, 'utf-8', function(err, data) {
16+
if (err) {
17+
finish(
18+
LOG_LEVEL_WARN,
19+
`Linking process could not be completed because of\n${err.message}`
20+
);
21+
}
22+
success(data);
23+
});
24+
}
25+
26+
function findClosureStart(data, index) {
27+
const alphRegex = /[a-z]/;
28+
let maven = '';
29+
let foundOpenParan = false;
30+
let closureStart = -1;
31+
for (let i = index; i >= 0; i--) {
32+
if (!foundOpenParan) {
33+
foundOpenParan = data.charAt(i) === CHAR_OPEN_PARAN;
34+
}
35+
36+
if (alphRegex.test(data.charAt(i)) && foundOpenParan) {
37+
maven = data.charAt(i) + maven;
38+
}
39+
if (maven === 'maven') {
40+
closureStart = i;
41+
break;
42+
}
43+
}
44+
return closureStart;
45+
}
46+
47+
function findClosureEnd(data, index) {
48+
const startIndex = index + MAVEN_REPO_URL.length + 2;
49+
let closureEnd = -1;
50+
//after
51+
for (let i = startIndex; i < data.length; i++) {
52+
if (data.charAt(i) === CHAR_CLOSED_PARAN) {
53+
closureEnd = i;
54+
break;
55+
}
56+
}
57+
return closureEnd;
58+
}
59+
60+
function removeMavenRepo(data) {
61+
const regex = /\"https:\/\/sdks.instabug.com\/nexus\/repository\/instabug-cp\"/;
62+
if (!regex.test(data) || !data.match(regex)) {
63+
finish(LOG_LEVEL_SUCCESS, 'Already Unlinked');
64+
return data;
65+
} else {
66+
const start = findClosureStart(data, data.match(regex).index);
67+
const end = findClosureEnd(data, data.match(regex).index);
68+
let newGradle =
69+
data.substring(0, start) + data.substring(end + 1, data.length);
70+
return newGradle;
71+
}
72+
}
73+
74+
function writeFile(data) {
75+
fs.writeFile(GRADLE_FILE_PATH, data, err => {
76+
if (err) {
77+
finish(
78+
LOG_LEVEL_WARN,
79+
`Unlinking process could not be completed because of\n${err.message}`
80+
);
81+
}
82+
finish(LOG_LEVEL_SUCCESS, 'Unlinking process completed successfully');
83+
});
84+
}
85+
86+
function finish(logLevel, message) {
87+
if (logLevel === LOG_LEVEL_SUCCESS) {
88+
console.info(message);
89+
} else {
90+
console.warn(message);
91+
}
92+
}
93+
94+
readFile(GRADLE_FILE_PATH, function(data) {
95+
const newGradle = removeMavenRepo(data);
96+
writeFile(newGradle);
97+
});

‎src/android/IBGPlugin.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.content.Intent;
44
import android.graphics.Color;
55
import android.net.Uri;
6+
import android.os.Handler;
7+
import android.os.Looper;
68
import android.util.Log;
79

810
import com.instabug.bug.BugReporting;
@@ -303,17 +305,17 @@ private final void hasChats(CallbackContext callbackContext) {
303305
private final void setReportTypes(CallbackContext callbackContext, JSONArray types) {
304306
String[] stringArrayOfReportTypes = toStringArray(types);
305307
if (stringArrayOfReportTypes.length != 0) {
306-
new Handler(Looper.getMainLooper()).post(new Runnable() {
307-
@Override
308-
public void run() {
309-
try {
310-
BugReporting.setReportTypes(Util.parseReportTypes(stringArrayOfReportTypes));
311-
callbackContext.success();
312-
} catch (Exception e) {
313-
callbackContext.error(e.getMessage());
314-
}
308+
new Handler(Looper.getMainLooper()).post(new Runnable() {
309+
@Override
310+
public void run() {
311+
try {
312+
BugReporting.setReportTypes(Util.parseReportTypes(stringArrayOfReportTypes));
313+
callbackContext.success();
314+
} catch (Exception e) {
315+
callbackContext.error(e.getMessage());
315316
}
316-
});
317+
}
318+
});
317319
}
318320
}
319321

@@ -577,6 +579,8 @@ public void run() {
577579
Instabug.setPrimaryColor(colorInt);
578580
}
579581
});
582+
583+
580584
} catch (IllegalStateException e) {
581585
callbackContext.error(errorMsg);
582586
}

‎src/android/IBGPluginActivity.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.os.Bundle;
44
import android.util.Log;
5+
import android.os.Handler;
6+
import android.os.Looper;
57

68
import com.instabug.bug.BugReporting;
79
import com.instabug.library.Feature;
@@ -67,7 +69,15 @@ public void onCreate(Bundle savedInstanceState) {
6769
* String representation of edge
6870
*/
6971
private void setFloatingButtonEdge(String edge) {
70-
72+
new Handler(Looper.getMainLooper()).post(new Runnable() {
73+
@Override
74+
public void run() {
75+
if (edge.equals("left"))
76+
BugReporting.setFloatingButtonEdge(InstabugFloatingButtonEdge.LEFT);
77+
else
78+
BugReporting.setFloatingButtonEdge(InstabugFloatingButtonEdge.RIGHT);
79+
}
80+
});
7181
}
7282

7383
/**
@@ -77,7 +87,12 @@ private void setFloatingButtonEdge(String edge) {
7787
* String representation of int offset
7888
*/
7989
private void setFloatingButtonOffset(String offset) {
80-
90+
new Handler(Looper.getMainLooper()).post(new Runnable() {
91+
@Override
92+
public void run() {
93+
BugReporting.setFloatingButtonOffset(Integer.parseInt(offset));
94+
}
95+
});
8196
}
8297

8398
/**

0 commit comments

Comments
 (0)