forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add manual test for position parameter in Tray click event
- 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
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |