Skip to content

Commit

Permalink
Add manual test for position parameter in Tray click event
Browse files Browse the repository at this point in the history
- Add a manual test and an example usage (tray only application with a custom
tray menu) of the position parameter in `Tray` `click` event as discussed in
nwjs#1874
  • Loading branch information
mrfabbri committed Dec 14, 2014
1 parent 4effdaf commit a8a6251
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/manual_tests/custom_tray_menu/custom-tray-menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<script>
var gui = require('nw.gui');

var win = gui.Window.get();

// mimicks tray menu behaviour, disappears when losing focus
win.on('blur', function() {
win.hide();
});
</script>
<body>
<p>A custom tray menu</p>
<p><button onclick="win.hide();">Close Menu</button></p>
<p><button onclick="gui.App.quit();">Close App</button></p>
</body>
</html>
Binary file added tests/manual_tests/custom_tray_menu/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions tests/manual_tests/custom_tray_menu/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<html>
<body>
<script>
// NOTE: __since__ node-webkit v0.11.3

var gui = require('nw.gui');

var win = gui.Window.get();

var tray;
tray = new gui.Tray({ icon: './icon.png', });

// reusing the custom tray menu (just hiding and showing)
var customTrayMenu = gui.Window.open('custom-tray-menu.html', {
width: 100, height: 120,
frame: false, toolbar: false,
show: false
});
var iconWidth = 13;
var translate = require('os').platform() == 'darwin' ?
function (pos) {
pos.x -= Math.floor(customTrayMenu.width/2-iconWidth);
} :
function (pos) {
pos.x -= Math.floor(customTrayMenu.width/2);
pos.y -= trayAreaIsTop(pos) ? 0 : customTrayMenu.height;
};
function trayAreaIsTop(pos) {
var screen;
if (gui.Screen.Init) gui.Screen.Init();
function posInBounds(s) {
return pos.y > s.bounds.y && pos.y < (s.bounds.y + s.bounds.height) &&
pos.x > s.bounds.x && pos.x < (s.bounds.x + s.bounds.width);
}
screen = gui.Screen.screens.filter(posInBounds)[0];
return pos.y < (screen.bounds.y + screen.bounds.height) / 2;
}
function showCustomTrayMenuAt(position) {
translate(position);
customTrayMenu.moveTo(position.x, position.y);
customTrayMenu.show();
customTrayMenu.focus();
}
tray.on('click', showCustomTrayMenuAt);

</script>
</body>
</html>
24 changes: 24 additions & 0 deletions tests/manual_tests/custom_tray_menu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"main": "index.html",
"name": "nw-test",
"description": "test app",
"window": {
"title": "My Node-Webkit App",
"icon": "icon.png",
"toolbar": false,
"frame": true,
"width": 800,
"height": 500,
"always-on-top": false,
"kiosk": false,
"fullscreen": false,
"show": false,
"show_in_taskbar": false,
"resizable": true
},
"webkit": {
"plugin": false,
"java": false,
"page-cache": false
}
}

0 comments on commit a8a6251

Please sign in to comment.