|
| 1 | +<html> |
| 2 | +<head> |
| 3 | + <title> Notification </title> |
| 4 | +</head> |
| 5 | +<body style="background-color:rgba(0,0,0,0);"> |
| 6 | +<p id="output" /> |
| 7 | +<script> |
| 8 | +// Load native UI library |
| 9 | +var gui = require('nw.gui'); |
| 10 | +// register AppUserModelID from package.json app-id / name to the application short-cut menu (.lnk) |
| 11 | +gui.App.createShortcut( process.env.APPDATA + "\\Microsoft\\Windows\\Start Menu\\Programs\\node-webkit.lnk"); |
| 12 | + |
| 13 | +var notificationMenu = new gui.Menu(); |
| 14 | +notificationMenu.append(new gui.MenuItem({ |
| 15 | +label: 'display Notification', |
| 16 | +click: function() { |
| 17 | + var http = require('http'); |
| 18 | + var fs = require('fs'); |
| 19 | + var os = require('os'); |
| 20 | + |
| 21 | + var download = function(url, dest, cb) { |
| 22 | + var file = fs.createWriteStream(dest); |
| 23 | + var request = http.get(url, function(response) { |
| 24 | + response.pipe(file); |
| 25 | + file.on('finish', function() { |
| 26 | + file.close(cb); |
| 27 | + }); |
| 28 | + }); |
| 29 | + } |
| 30 | + |
| 31 | + // download the icon to os temp folder, win8 toast notification can only load notification image from file:/// |
| 32 | + download("http://icons.iconarchive.com/icons/icons-land/vista-style-emoticons/256/Study-icon.png", os.tmpdir()+"/notif.png", function(){ |
| 33 | + |
| 34 | + var path = require('path'); |
| 35 | + var options = { |
| 36 | + icon: path.resolve(os.tmpdir()+"/notif.png"), |
| 37 | + body: "Here is the notification text" |
| 38 | + }; |
| 39 | + |
| 40 | + var notification = new Notification("webkit notification!",options); |
| 41 | + notification.onclick = function () { |
| 42 | + document.getElementById("output").innerHTML += "Notification " + "clicked<br>"; |
| 43 | + } |
| 44 | + |
| 45 | + notification.onshow = function () { |
| 46 | + document.getElementById("output").innerHTML += "Notification " + "show<br>"; |
| 47 | + } |
| 48 | + |
| 49 | + notification.onclose = function () { |
| 50 | + document.getElementById("output").innerHTML += "Notification " + "close<br>"; |
| 51 | + } |
| 52 | + }); |
| 53 | +} |
| 54 | +})); |
| 55 | + |
| 56 | +var menubar = new gui.Menu({ type: 'menubar' }); |
| 57 | + |
| 58 | +// You can have submenu! |
| 59 | +menubar.append(new gui.MenuItem({ label: 'Notification', submenu: notificationMenu})); |
| 60 | + |
| 61 | +//assign the menubar to window menu |
| 62 | +var win = gui.Window.get(); |
| 63 | +win.menu = menubar; |
| 64 | + |
| 65 | + |
| 66 | +</script> |
| 67 | +</body> |
| 68 | +</html> |
0 commit comments