michael@0: /* michael@0: * michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * michael@0: */ michael@0: michael@0: /*global Windows:true */ michael@0: michael@0: var cordova = require('cordova'); michael@0: michael@0: var isAlertShowing = false; michael@0: var alertStack = []; michael@0: michael@0: module.exports = { michael@0: alert:function(win, loseX, args) { michael@0: michael@0: if (isAlertShowing) { michael@0: var later = function () { michael@0: module.exports.alert(win, loseX, args); michael@0: }; michael@0: alertStack.push(later); michael@0: return; michael@0: } michael@0: isAlertShowing = true; michael@0: michael@0: var message = args[0]; michael@0: var _title = args[1]; michael@0: var _buttonLabel = args[2]; michael@0: michael@0: var md = new Windows.UI.Popups.MessageDialog(message, _title); michael@0: md.commands.append(new Windows.UI.Popups.UICommand(_buttonLabel)); michael@0: md.showAsync().then(function() { michael@0: isAlertShowing = false; michael@0: win && win(); michael@0: michael@0: if (alertStack.length) { michael@0: setTimeout(alertStack.shift(), 0); michael@0: } michael@0: michael@0: }); michael@0: }, michael@0: michael@0: confirm:function(win, loseX, args) { michael@0: michael@0: if (isAlertShowing) { michael@0: var later = function () { michael@0: module.exports.confirm(win, loseX, args); michael@0: }; michael@0: alertStack.push(later); michael@0: return; michael@0: } michael@0: michael@0: isAlertShowing = true; michael@0: michael@0: try { michael@0: var message = args[0]; michael@0: var _title = args[1]; michael@0: var buttons = args[2]; michael@0: michael@0: var md = new Windows.UI.Popups.MessageDialog(message, _title); michael@0: michael@0: buttons.forEach(function(buttonLabel) { michael@0: md.commands.append(new Windows.UI.Popups.UICommand(buttonLabel)); michael@0: }); michael@0: michael@0: md.showAsync().then(function(res) { michael@0: isAlertShowing = false; michael@0: var result = res ? buttons.indexOf(res.label) + 1 : 0; michael@0: win && win(result); michael@0: if (alertStack.length) { michael@0: setTimeout(alertStack.shift(), 0); michael@0: } michael@0: michael@0: }); michael@0: } catch (e) { michael@0: // set isAlertShowing flag back to false in case of exception michael@0: isAlertShowing = false; michael@0: if (alertStack.length) { michael@0: setTimeout(alertStack.shift(), 0); michael@0: } michael@0: // rethrow exception michael@0: throw e; michael@0: } michael@0: }, michael@0: michael@0: beep:function(winX, loseX, args) { michael@0: michael@0: // set a default args if it is not set michael@0: args = args && args.length ? args : ["1"]; michael@0: michael@0: var snd = new Audio('ms-winsoundevent:Notification.Default'); michael@0: var count = parseInt(args[0]) || 1; michael@0: snd.msAudioCategory = "Alerts"; michael@0: michael@0: var onEvent = function () { michael@0: if (count > 0) { michael@0: snd.play(); michael@0: } else { michael@0: snd.removeEventListener("ended", onEvent); michael@0: snd = null; michael@0: winX && winX(); // notification.js just sends null, but this is future friendly michael@0: } michael@0: count--; michael@0: }; michael@0: snd.addEventListener("ended", onEvent); michael@0: onEvent(); michael@0: michael@0: } michael@0: }; michael@0: michael@0: require("cordova/exec/proxy").add("Notification",module.exports);