Skip to content

Commit 3d23537

Browse files
committed
[Notification] add manual test
1 parent a05939e commit 3d23537

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "nw-notification-test",
3+
"main": "index.html",
4+
"app-id": "com.node.webkit.notification.test"
5+
}

0 commit comments

Comments
 (0)