forked from AlexDisler/cordova-splash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid_update_theme.js
49 lines (44 loc) · 1.36 KB
/
android_update_theme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var fs = require("fs-extra");
var Q = require("q");
var xml2js = require("xml2js");
var display = require("./display");
var fileName = "platforms/android/app/src/main/res/values/themes.xml";
function updateTheme() {
var deferred = Q.defer();
fs.readFile(fileName, function (err, data) {
if (err) {
display.error("could not read theme for splash screen");
deferred.reject(err);
return;
}
var parser = new xml2js.Parser();
parser.parseString(data, function (err, result) {
if (err) {
display.error("could not parse theme for splash screen");
deferred.reject(err);
return;
}
result.resources.style[0].item = result.resources.style[0].item.map(
function (element) {
if (element.$.name === "windowSplashScreenAnimatedIcon") {
element._ = "@drawable/screen";
}
return element;
}
);
var builder = new xml2js.Builder();
var xml = builder.buildObject(result);
fs.writeFile(fileName, xml, "utf-8", function (err) {
if (err) {
display.error("could not write theme for splash screen");
deferred.reject(err);
return;
}
display.success("updated theme for splash screen");
deferred.resolve();
});
});
});
return deferred.promise;
}
module.exports = updateTheme;