Commit 30e35884 by Sebastián Katzer

Merge branch 'master' of github.com:katzer/cordova-plugin-local-notifications

parents c3520580 f47e405b
...@@ -200,7 +200,9 @@ exports.core = { ...@@ -200,7 +200,9 @@ exports.core = {
clearLocalNotification: function (id) { clearLocalNotification: function (id) {
var notification = this.getAll([id])[0]; var notification = this.getAll([id])[0];
this.getToastHistory().remove('Toast' + id); try {
this.getToastHistory().remove('Toast' + id);
} catch (e) {/*Only Phones support the NotificationHistory*/ }
if (this.isRepeating(notification)) if (this.isRepeating(notification))
return; return;
...@@ -220,7 +222,9 @@ exports.core = { ...@@ -220,7 +222,9 @@ exports.core = {
this.clearLocalNotification(ids[i]); this.clearLocalNotification(ids[i]);
} }
this.getToastHistory().clear(); try {
this.getToastHistory().clear();
} catch (e) {/*Only Phones support the NotificationHistory*/ }
this.fireEvent('clearall'); this.fireEvent('clearall');
}, },
...@@ -251,7 +255,9 @@ exports.core = { ...@@ -251,7 +255,9 @@ exports.core = {
history = this.getToastHistory(), history = this.getToastHistory(),
toasts = this.getScheduledToasts(); toasts = this.getScheduledToasts();
history.remove('Toast' + id); try {
history.remove('Toast' + id);
} catch (e) {/*Only Phones support the NotificationHistory*/ }
for (var i = 0; i < toasts.length; i++) { for (var i = 0; i < toasts.length; i++) {
var toast = toasts[i]; var toast = toasts[i];
...@@ -272,7 +278,9 @@ exports.core = { ...@@ -272,7 +278,9 @@ exports.core = {
this.cancelLocalNotification(ids[i]); this.cancelLocalNotification(ids[i]);
} }
this.getToastHistory().clear(); try {
this.getToastHistory().clear();
} catch (e) {/*Only Phones support the NotificationHistory*/ }
this.fireEvent('cancelall'); this.fireEvent('cancelall');
}, },
......
...@@ -86,20 +86,52 @@ exports.isRepeating = function (notification) { ...@@ -86,20 +86,52 @@ exports.isRepeating = function (notification) {
* @param {String} path * @param {String} path
* Relative path to sound resource * Relative path to sound resource
* *
* @return {String} URI to Sound-File * @return {String} XML Tag for Sound-File
*/ */
exports.parseSound = function (path) { exports.parseSound = function (path) {
if (!path.match(/^file/))
return '';
var uri = this.parseUri(path),
audio = "<audio src=" + uri + " loop='false'/>";
return audio;
};
/**
* Parses image file path.
*
* @param {String} path
* Relative path to image resource
*
* @return {String} XML-Tag for Image-File
*/
exports.parseImage = function (path) {
if (!path.match(/^file/))
return '';
var uri = this.parseUri(path),
image = "<image id='1' src=" + uri + " />";
return image;
};
/**
* Parses file path to URI.
*
* @param {String} path
* Relative path to a resource
*
* @return {String} URI to File
*/
exports.parseUri = function (path) {
var pkg = Windows.ApplicationModel.Package.current, var pkg = Windows.ApplicationModel.Package.current,
pkgId = pkg.id, pkgId = pkg.id,
pkgName = pkgId.name; pkgName = pkgId.name;
if (!path.match(/^file/)) var uri = "'ms-appx://" + pkgName + "/www" + path.slice(6, path.length) + "'";
return;
var sound = "'ms-appx://" + pkgName + "/www/" + path.slice(6, path.length) + "'", return uri;
audio = "<audio src=" + sound + " loop='false'/>";
return audio;
}; };
/** /**
...@@ -141,37 +173,47 @@ exports.build = function (options) { ...@@ -141,37 +173,47 @@ exports.build = function (options) {
* @return String * @return String
*/ */
exports.buildToastTemplate = function (options) { exports.buildToastTemplate = function (options) {
var title = options.title, var title = options.title,
message = options.text || '', message = options.text || '',
json = JSON.stringify(options), json = JSON.stringify(options),
sound = ''; sound = '';
if (options.sound && options.sound !== '') { if (options.sound && options.sound !== '') {
sound = this.parseSound(options.sound); sound = this.parseSound(options.sound);
} }
if (title && title !== '') { var templateName = "ToastText",
return "<toast>" + imageNode;
"<visual>" + if (options.icon && options.icon !== '') {
"<binding template='ToastText02'>" + imageNode = this.parseImage(options.icon);
"<text id='1'>" + title + "</text>" + // template with Image
"<text id='2'>" + message + "</text>" + if (imageNode !== '') {
"</binding>" + templateName = "ToastImageAndText";
"</visual>" + };
sound + } else {
"<json>" + json + "</json>" + imageNode = "";
"</toast>"; }
} else {
return "<toast>" + var bindingNode;
"<visual>" + if (title && title !== '') {
"<binding template='ToastText01'>" + bindingNode = "<binding template='" + templateName + "02'>" +
"<text id='1'>" + message + "</text>" + imageNode +
"</binding>" + "<text id='1'>" + title + "</text>" +
"</visual>" + "<text id='2'>" + message + "</text>" +
sound + "</binding>";
"<json>" + json + "</json>" + } else {
"</toast>"; bindingNode = "<binding template='" + templateName + "01'>" +
} imageNode +
"<text id='1'>" + message + "</text>" +
"</binding>";
}
return "<toast>" +
"<visual>" +
bindingNode +
"</visual>" +
sound +
"<json>" + json + "</json>" +
"</toast>";
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment