1
- module . exports = function ( ctx ) {
2
- console . log ( 'INNN' ) ;
3
- const fs = ctx . requireCordovaModule ( 'fs' ) ;
4
- const path = ctx . requireCordovaModule ( 'path' ) ;
5
- const Q = ctx . requireCordovaModule ( 'q' ) ;
6
- const xml = ctx . requireCordovaModule ( 'cordova-common' ) . xmlHelpers ;
1
+ module . exports = ( ctx , isInstalling ) => {
2
+ const fs = ctx . requireCordovaModule ( 'fs' ) ;
3
+ const path = ctx . requireCordovaModule ( 'path' ) ;
4
+ const Q = ctx . requireCordovaModule ( 'q' ) ;
5
+ const xml = ctx . requireCordovaModule ( 'cordova-common' ) . xmlHelpers ;
7
6
8
- const deferred = Q . defer ( ) ;
9
- const platformPath = path . join ( ctx . opts . projectRoot , './platforms/android' ) ;
10
- const manifestPaths = [
11
- path . join ( platformPath , './AndroidManifest.xml' ) ,
12
- path . join ( platformPath , './app/src/main/AndroidManifest.xml' ) ,
13
- ] ;
7
+ const deferred = Q . defer ( ) ;
8
+ const platformPath = path . join ( ctx . opts . projectRoot , './platforms/android' ) ;
9
+ const manifestPaths = [
10
+ path . join ( platformPath , './AndroidManifest.xml' ) ,
11
+ path . join ( platformPath , './app/src/main/AndroidManifest.xml' )
12
+ ] ;
14
13
15
- const manifestPath = manifestPaths . find ( ( filepath ) => {
16
- try {
17
- fs . accessSync ( filepath , fs . constants . F_OK )
18
- return true
19
- } catch ( err ) {
20
- return false
21
- }
22
- } ) ;
14
+ const manifestPath = manifestPaths . find ( filepath => {
15
+ try {
16
+ fs . accessSync ( filepath , fs . constants . F_OK ) ;
17
+ return true ;
18
+ } catch ( err ) {
19
+ return false ;
20
+ }
21
+ } ) ;
23
22
24
- var doc ;
23
+ if ( manifestPath != null ) {
24
+ const appName = 'com.instabug.cordova.plugin.MyApplication' ;
25
+ let doc = xml . parseElementtreeSync ( manifestPath ) ;
26
+ let appAttr = doc . getroot ( ) . find ( './application' ) . attrib [ 'android:name' ] ;
25
27
26
- if ( manifestPath != null ) {
27
- doc = xml . parseElementtreeSync ( manifestPath )
28
- doc . getroot ( ) . find ( './application' ) . attrib [ 'android:name' ] =
29
- 'com.instabug.cordova.plugin.MyApplication'
30
- fs . writeFileSync ( manifestPath , doc . write ( { indent : 4 } ) )
31
- deferred . resolve ( )
28
+ if ( isInstalling ) {
29
+ if ( ! appAttr ) {
30
+ doc . getroot ( ) . find ( './application' ) . attrib [ 'android:name' ] = appName ;
31
+ }
32
32
} else {
33
- deferred . reject ( new Error ( "Can't find AndroidManifest.xml" ) )
33
+ if ( appAttr === appName ) {
34
+ delete doc . getroot ( ) . find ( './application' ) . attrib [ 'android:name' ] ;
35
+ }
34
36
}
37
+
38
+ fs . writeFileSync ( manifestPath , doc . write ( { indent : 4 } ) ) ;
39
+ deferred . resolve ( ) ;
40
+ } else {
41
+ deferred . reject ( new Error ( "Can't find AndroidManifest.xml" ) ) ;
42
+ }
35
43
36
- return deferred . promise
37
- }
44
+ return deferred . promise ;
45
+ } ;
0 commit comments