1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Touchgui/plugins/org.apache.cordova.dialogs/src/windows8/NotificationProxy.js Thu Jun 04 14:50:33 2015 +0200 1.3 @@ -0,0 +1,126 @@ 1.4 +/* 1.5 + * 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * 1.23 +*/ 1.24 + 1.25 +/*global Windows:true */ 1.26 + 1.27 +var cordova = require('cordova'); 1.28 + 1.29 +var isAlertShowing = false; 1.30 +var alertStack = []; 1.31 + 1.32 +module.exports = { 1.33 + alert:function(win, loseX, args) { 1.34 + 1.35 + if (isAlertShowing) { 1.36 + var later = function () { 1.37 + module.exports.alert(win, loseX, args); 1.38 + }; 1.39 + alertStack.push(later); 1.40 + return; 1.41 + } 1.42 + isAlertShowing = true; 1.43 + 1.44 + var message = args[0]; 1.45 + var _title = args[1]; 1.46 + var _buttonLabel = args[2]; 1.47 + 1.48 + var md = new Windows.UI.Popups.MessageDialog(message, _title); 1.49 + md.commands.append(new Windows.UI.Popups.UICommand(_buttonLabel)); 1.50 + md.showAsync().then(function() { 1.51 + isAlertShowing = false; 1.52 + win && win(); 1.53 + 1.54 + if (alertStack.length) { 1.55 + setTimeout(alertStack.shift(), 0); 1.56 + } 1.57 + 1.58 + }); 1.59 + }, 1.60 + 1.61 + confirm:function(win, loseX, args) { 1.62 + 1.63 + if (isAlertShowing) { 1.64 + var later = function () { 1.65 + module.exports.confirm(win, loseX, args); 1.66 + }; 1.67 + alertStack.push(later); 1.68 + return; 1.69 + } 1.70 + 1.71 + isAlertShowing = true; 1.72 + 1.73 + try { 1.74 + var message = args[0]; 1.75 + var _title = args[1]; 1.76 + var buttons = args[2]; 1.77 + 1.78 + var md = new Windows.UI.Popups.MessageDialog(message, _title); 1.79 + 1.80 + buttons.forEach(function(buttonLabel) { 1.81 + md.commands.append(new Windows.UI.Popups.UICommand(buttonLabel)); 1.82 + }); 1.83 + 1.84 + md.showAsync().then(function(res) { 1.85 + isAlertShowing = false; 1.86 + var result = res ? buttons.indexOf(res.label) + 1 : 0; 1.87 + win && win(result); 1.88 + if (alertStack.length) { 1.89 + setTimeout(alertStack.shift(), 0); 1.90 + } 1.91 + 1.92 + }); 1.93 + } catch (e) { 1.94 + // set isAlertShowing flag back to false in case of exception 1.95 + isAlertShowing = false; 1.96 + if (alertStack.length) { 1.97 + setTimeout(alertStack.shift(), 0); 1.98 + } 1.99 + // rethrow exception 1.100 + throw e; 1.101 + } 1.102 + }, 1.103 + 1.104 + beep:function(winX, loseX, args) { 1.105 + 1.106 + // set a default args if it is not set 1.107 + args = args && args.length ? args : ["1"]; 1.108 + 1.109 + var snd = new Audio('ms-winsoundevent:Notification.Default'); 1.110 + var count = parseInt(args[0]) || 1; 1.111 + snd.msAudioCategory = "Alerts"; 1.112 + 1.113 + var onEvent = function () { 1.114 + if (count > 0) { 1.115 + snd.play(); 1.116 + } else { 1.117 + snd.removeEventListener("ended", onEvent); 1.118 + snd = null; 1.119 + winX && winX(); // notification.js just sends null, but this is future friendly 1.120 + } 1.121 + count--; 1.122 + }; 1.123 + snd.addEventListener("ended", onEvent); 1.124 + onEvent(); 1.125 + 1.126 + } 1.127 +}; 1.128 + 1.129 +require("cordova/exec/proxy").add("Notification",module.exports);